Skip to content

Commit aee5b62

Browse files
fixup!: move test-case to "known issues"
1 parent 6a38d32 commit aee5b62

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as common from '../common/index.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
3+
import { test } from 'node:test';
4+
5+
const testArguments = [
6+
'--test',
7+
'--test-isolation=none',
8+
];
9+
10+
const testFiles = [
11+
fixtures.path('test-runner', 'no-isolation', 'one.test.js'),
12+
fixtures.path('test-runner', 'no-isolation', 'two.test.js'),
13+
];
14+
15+
const order = [
16+
'before(): global',
17+
18+
'before one: <root>',
19+
'suite one',
20+
21+
'before two: <root>',
22+
'suite two',
23+
24+
'beforeEach(): global',
25+
'beforeEach one: suite one - test',
26+
'beforeEach two: suite one - test',
27+
28+
'suite one - test',
29+
'afterEach(): global',
30+
'afterEach one: suite one - test',
31+
'afterEach two: suite one - test',
32+
33+
'before suite two: suite two',
34+
'beforeEach(): global',
35+
'beforeEach one: suite two - test',
36+
'beforeEach two: suite two - test',
37+
38+
'suite two - test',
39+
'afterEach(): global',
40+
'afterEach one: suite two - test',
41+
'afterEach two: suite two - test',
42+
43+
'after(): global',
44+
'after one: <root>',
45+
'after two: <root>',
46+
].join('\n');
47+
48+
/**
49+
* TODO: The `--require` flag is processed in `loadPreloadModules` (process/pre_execution.js) BEFORE
50+
* the root test is created by the test runner. This causes a global `before` hook to register (and
51+
* run) but then the root test-case is created, causing the "subsequent" hooks to get lost. This
52+
* behaviour (CJS route only) is different from the ESM route, where test runner explicitly handles
53+
* `--import` in `root.runInAsyncScope` (test_runner/runner.js).
54+
* @see https://github.com/nodejs/node/pull/57595#issuecomment-2770724492
55+
* @see https://github.com/nodejs/node/issues/57728
56+
* Moved from test/parallel/test-runner-no-isolation-hooks.mjs
57+
*/
58+
test('use --require to define global hooks', async (t) => {
59+
const { stdout } = await common.spawnPromisified(process.execPath, [
60+
...testArguments,
61+
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.cjs'),
62+
...testFiles,
63+
]);
64+
65+
const testHookOutput = stdout.split('\n▶')[0];
66+
67+
t.assert.equal(testHookOutput, order);
68+
});

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ const order = [
4545
'after two: <root>',
4646
].join('\n');
4747

48-
test('use --require to define global hooks', async (t) => {
49-
const { stdout } = await common.spawnPromisified(process.execPath, [
50-
...testArguments,
51-
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.cjs'),
52-
...testFiles,
53-
]);
54-
55-
const testHookOutput = stdout.split('\n▶')[0];
56-
57-
t.assert.equal(testHookOutput, order);
58-
});
59-
6048
test('use --import (CJS) to define global hooks', async (t) => {
6149
const { stdout } = await common.spawnPromisified(process.execPath, [
6250
...testArguments,

0 commit comments

Comments
 (0)