From c08666428d5c1a0e9fd507ab5832fa65b233790c Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 27 Nov 2024 21:58:24 +0300 Subject: [PATCH] test: migrate tests to use node:test module for better test structure --- test/sequential/test-debugger-custom-port.js | 29 ++++++++++--------- .../test-worker-heapsnapshot-options.js | 13 +++++---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/test/sequential/test-debugger-custom-port.js b/test/sequential/test-debugger-custom-port.js index 7c8abdc0c55174..5b472ded9f3f75 100644 --- a/test/sequential/test-debugger-custom-port.js +++ b/test/sequential/test-debugger-custom-port.js @@ -1,28 +1,31 @@ 'use strict'; const common = require('../common'); - -common.skipIfInspectorDisabled(); - const fixtures = require('../common/fixtures'); const startCLI = require('../common/debugger'); +const assert = require('node:assert'); +const { test } = require('node:test'); -const assert = require('assert'); +// Skip if the inspector is disabled +common.skipIfInspectorDisabled(); -// Custom port. -const script = fixtures.path('debugger', 'three-lines.js'); +test('should start CLI debugger with custom port and validate output', async (t) => { + const script = fixtures.path('debugger', 'three-lines.js'); + const cli = startCLI([`--port=${common.PORT}`, script]); -const cli = startCLI([`--port=${common.PORT}`, script]); -(async function() { - try { + await t.test('validate debugger prompt and output', async () => { await cli.waitForInitialBreak(); await cli.waitForPrompt(); + assert.match(cli.output, /debug>/, 'prints a prompt'); assert.match( cli.output, new RegExp(`< Debugger listening on [^\n]*${common.PORT}`), - 'forwards child output'); - } finally { + 'forwards child output' + ); + }); + + await t.test('ensure CLI exits with code 0', async () => { const code = await cli.quit(); assert.strictEqual(code, 0); - } -})().then(common.mustCall()); + }); +}); diff --git a/test/sequential/test-worker-heapsnapshot-options.js b/test/sequential/test-worker-heapsnapshot-options.js index ca0ab190514b6c..80c261a63be6f1 100644 --- a/test/sequential/test-worker-heapsnapshot-options.js +++ b/test/sequential/test-worker-heapsnapshot-options.js @@ -1,11 +1,14 @@ // Flags: --expose-internals 'use strict'; -const common = require('../common'); + +require('../common'); + const { recordState, getHeapSnapshotOptionTests } = require('../common/heap'); -const { Worker } = require('worker_threads'); -const { once } = require('events'); +const { Worker } = require('node:worker_threads'); +const { once } = require('node:events'); +const { test } = require('node:test'); -(async function() { +test('should handle heap snapshot options correctly in Worker threads', async () => { const tests = getHeapSnapshotOptionTests(); const w = new Worker(tests.fixtures); @@ -18,4 +21,4 @@ const { once } = require('events'); } await w.terminate(); -})().then(common.mustCall()); +});