-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-runner-no-isolation-hooks.mjs
More file actions
79 lines (64 loc) · 2.28 KB
/
test-runner-no-isolation-hooks.mjs
File metadata and controls
79 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { test } from 'node:test';
const testArguments = [
'--test',
'--test-isolation=none',
];
const testFiles = [
fixtures.path('test-runner', 'no-isolation', 'one.test.js'),
fixtures.path('test-runner', 'no-isolation', 'two.test.js'),
];
// Each file is wrapped in an implicit suite when using isolation: 'none',
// so file-level hooks are scoped to their file. Global hooks (registered
// via --import/--require) still run for all tests.
const file1 = fixtures.path('test-runner', 'no-isolation', 'one.test.js');
const file2 = fixtures.path('test-runner', 'no-isolation', 'two.test.js');
const order = [
'before(): global',
'suite one',
'suite two',
`before one: ${file1}`,
'beforeEach(): global',
'beforeEach one: suite one - test',
'suite one - test',
'afterEach one: suite one - test',
'afterEach(): global',
`after one: ${file1}`,
`before two: ${file2}`,
'before suite two: suite two',
'beforeEach(): global',
'beforeEach two: suite two - test',
'suite two - test',
'afterEach two: suite two - test',
'afterEach(): global',
`after two: ${file2}`,
'after(): global',
].join('\n');
test('use --import (CJS) to define global hooks', async (t) => {
const { stdout } = await common.spawnPromisified(process.execPath, [
...testArguments,
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.cjs'),
...testFiles,
]);
const testHookOutput = stdout.split('\n▶')[0];
t.assert.equal(testHookOutput, order);
});
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.mjs'),
...testFiles,
]);
const testHookOutput = stdout.split('\n▶')[0];
t.assert.equal(testHookOutput, order);
});
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,
]);
const testHookOutput = stdout.split('\n▶')[0];
t.assert.equal(testHookOutput, order);
});