Skip to content

Commit cd6d33f

Browse files
test: fix dangling promise in test_runner no isolation test setup
1 parent a4f556f commit cd6d33f

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const test = require('node:test');
2+
3+
test.before(() => console.log('before(): global'));
4+
test.beforeEach(() => console.log('beforeEach(): global'));
5+
test.after(() => console.log('after(): global'));
6+
test.afterEach(() => console.log('afterEach(): global'));

test/fixtures/test-runner/no-isolation/global-hooks.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import test from 'node:test';
2+
3+
test.before(() => console.log('before(): global'));
4+
test.beforeEach(() => console.log('beforeEach(): global'));
5+
test.after(() => console.log('after(): global'));
6+
test.afterEach(() => console.log('afterEach(): global'));

test/parallel/test-runner-no-isolation-hooks.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,28 @@ const order = [
4343
'after(): global',
4444
'after one: <root>',
4545
'after two: <root>',
46-
];
46+
].join('\n');
4747

4848
test('Using --require to define global hooks works', async (t) => {
49-
const spawned = await common.spawnPromisified(process.execPath, [
49+
const { stdout } = await common.spawnPromisified(process.execPath, [
5050
...testArguments,
51-
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.js'),
51+
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.cjs'),
5252
...testFiles,
5353
]);
5454

55-
t.assert.ok(spawned.stdout.includes(order.join('\n')));
55+
const testHookOutput = stdout.split('\n▶')[0];
56+
57+
t.assert.equal(testHookOutput, order);
5658
});
5759

5860
test('Using --import to define global hooks works', async (t) => {
59-
const spawned = await common.spawnPromisified(process.execPath, [
61+
const { stdout } = await common.spawnPromisified(process.execPath, [
6062
...testArguments,
61-
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.js'),
63+
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.mjs'),
6264
...testFiles,
6365
]);
6466

65-
t.assert.ok(spawned.stdout.includes(order.join('\n')));
67+
const testHookOutput = stdout.split('\n▶')[0];
68+
69+
t.assert.equal(testHookOutput, order);
6670
});

0 commit comments

Comments
 (0)