Skip to content

test: fix dangling promise in test_runner no isolation test setup #57595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/fixtures/test-runner/no-isolation/global-hooks.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const test = require('node:test');

test.before(() => console.log('before(): global'));
test.beforeEach(() => console.log('beforeEach(): global'));
test.after(() => console.log('after(): global'));
test.afterEach(() => console.log('afterEach(): global'));
6 changes: 0 additions & 6 deletions test/fixtures/test-runner/no-isolation/global-hooks.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/fixtures/test-runner/no-isolation/global-hooks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'node:test';

test.before(() => console.log('before(): global'));
test.beforeEach(() => console.log('beforeEach(): global'));
test.after(() => console.log('after(): global'));
test.afterEach(() => console.log('afterEach(): global'));
34 changes: 25 additions & 9 deletions test/parallel/test-runner-no-isolation-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,40 @@
'after(): global',
'after one: <root>',
'after two: <root>',
];
].join('\n');

test('use --require to define global hooks', async (t) => {
const { stdout } = await common.spawnPromisified(process.execPath, [
...testArguments,
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.cjs'),
...testFiles,
]);

test('Using --require to define global hooks works', async (t) => {
const spawned = await common.spawnPromisified(process.execPath, [
const testHookOutput = stdout.split('\n▶')[0];

t.assert.equal(testHookOutput, order);

Check failure on line 57 in test/parallel/test-runner-no-isolation-hooks.mjs

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stdout --- Test failure: 'use --require to define global hooks' Location: test/parallel/test-runner-no-isolation-hooks.mjs:48:1 AssertionError [ERR_ASSERTION]: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'suite two - test\n' + 'afterEach one: suite two - test\n' + 'afterEach two: suite tw... == 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'su... at assert.<computed> [as equal] (node:internal/test_runner/test:320:18) at TestContext.<anonymous> (file:///home/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs:57:12) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Test.run (node:internal/test_runner/test:1063:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:308:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + '...', expected: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + '...', operator: '==' } Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs

Check failure on line 57 in test/parallel/test-runner-no-isolation-hooks.mjs

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- Test failure: 'use --require to define global hooks' Location: test/parallel/test-runner-no-isolation-hooks.mjs:48:1 AssertionError [ERR_ASSERTION]: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'suite two - test\n' + 'afterEach one: suite two - test\n' + 'afterEach two: suite tw... == 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'su... at assert.<computed> [as equal] (node:internal/test_runner/test:320:18) at TestContext.<anonymous> (file:///Users/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs:57:12) at async Test.run (node:internal/test_runner/test:1063:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:308:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + '...', expected: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + '...', operator: '==' } Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs

Check failure on line 57 in test/parallel/test-runner-no-isolation-hooks.mjs

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stdout --- Test failure: 'use --require to define global hooks' Location: test/parallel/test-runner-no-isolation-hooks.mjs:48:1 AssertionError [ERR_ASSERTION]: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'suite two - test\n' + 'afterEach one: suite two - test\n' + 'afterEach two: suite tw... == 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + 'before suite two: suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite two - test\n' + 'beforeEach two: suite two - test\n' + 'su... at assert.<computed> [as equal] (node:internal/test_runner/test:320:18) at TestContext.<anonymous> (file:///home/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs:57:12) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Test.run (node:internal/test_runner/test:1063:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:308:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach one: suite one - test\n' + 'afterEach two: suite one - test\n' + '...', expected: 'before(): global\n' + 'before one: <root>\n' + 'suite one\n' + 'before two: <root>\n' + 'suite two\n' + 'beforeEach(): global\n' + 'beforeEach one: suite one - test\n' + 'beforeEach two: suite one - test\n' + 'suite one - test\n' + 'afterEach(): global\n' + '...', operator: '==' } Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-runner-no-isolation-hooks.mjs
});

test('use --import (CJS) to define global hooks', async (t) => {
const { stdout } = await common.spawnPromisified(process.execPath, [
...testArguments,
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.js'),
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.cjs'),
...testFiles,
]);

t.assert.ok(spawned.stdout.includes(order.join('\n')));
const testHookOutput = stdout.split('\n▶')[0];

t.assert.equal(testHookOutput, order);
});

test('Using --import to define global hooks works', async (t) => {
const spawned = await common.spawnPromisified(process.execPath, [
test('use --import (ESM) to define global hooks', async (t) => {
const { stdout } = await common.spawnPromisified(process.execPath, [
...testArguments,
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.js'),
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.mjs'),
...testFiles,
]);

t.assert.ok(spawned.stdout.includes(order.join('\n')));
const testHookOutput = stdout.split('\n▶')[0];

t.assert.equal(testHookOutput, order);
});
Loading