Skip to content

Commit 43755ac

Browse files
rluvatonpluris
authored and
pluris
committed
test: reorder test files fixtures for better understanding
PR-URL: nodejs#48787 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 3d265e9 commit 43755ac

File tree

10 files changed

+41
-17
lines changed

10 files changed

+41
-17
lines changed

test/parallel/test-runner-cli.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const testFixtures = fixtures.path('test-runner');
2222
// Default behavior. node_modules is ignored. Files that don't match the
2323
// pattern are ignored except in test/ directories.
2424
const args = ['--test'];
25-
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
25+
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
2626

2727
assert.strictEqual(child.status, 1);
2828
assert.strictEqual(child.signal, null);
@@ -39,7 +39,7 @@ const testFixtures = fixtures.path('test-runner');
3939
{
4040
// Same but with a prototype mutation in require scripts.
4141
const args = ['--require', join(testFixtures, 'protoMutation.js'), '--test'];
42-
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
42+
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
4343

4444
const stdout = child.stdout.toString();
4545
assert.match(stdout, /ok 1 - this should pass/);
@@ -67,7 +67,7 @@ const testFixtures = fixtures.path('test-runner');
6767

6868
{
6969
// Searches node_modules if specified.
70-
const args = ['--test', join(testFixtures, 'node_modules/*.js')];
70+
const args = ['--test', join(testFixtures, 'default-behavior/node_modules/*.js')];
7171
const child = spawnSync(process.execPath, args);
7272

7373
assert.strictEqual(child.status, 1);
@@ -80,7 +80,7 @@ const testFixtures = fixtures.path('test-runner');
8080
{
8181
// The current directory is used by default.
8282
const args = ['--test'];
83-
const options = { cwd: testFixtures };
83+
const options = { cwd: join(testFixtures, 'default-behavior') };
8484
const child = spawnSync(process.execPath, args, options);
8585

8686
assert.strictEqual(child.status, 1);
@@ -119,7 +119,7 @@ const testFixtures = fixtures.path('test-runner');
119119
// Test combined stream outputs
120120
const args = [
121121
'--test',
122-
'test/fixtures/test-runner/index.test.js',
122+
'test/fixtures/test-runner/default-behavior/index.test.js',
123123
'test/fixtures/test-runner/nested.js',
124124
'test/fixtures/test-runner/invalid-tap.js',
125125
];
@@ -197,7 +197,7 @@ const testFixtures = fixtures.path('test-runner');
197197
const args = ['--no-warnings',
198198
'--experimental-loader', 'data:text/javascript,',
199199
'--require', fixtures.path('empty.js'),
200-
'--test', join(testFixtures, 'index.test.js')];
200+
'--test', join(testFixtures, 'default-behavior', 'index.test.js')];
201201
const child = spawnSync(process.execPath, args);
202202

203203
assert.strictEqual(child.stderr.toString(), '');

test/parallel/test-runner-exit-code.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ if (process.argv[2] === 'child') {
4343
assert.strictEqual(child.status, 0);
4444
assert.strictEqual(child.signal, null);
4545

46-
child = spawnSync(process.execPath, ['--test', fixtures.path('test-runner', 'subdir', 'subdir_test.js')]);
46+
child = spawnSync(process.execPath, [
47+
'--test',
48+
fixtures.path('test-runner', 'default-behavior', 'subdir', 'subdir_test.js'),
49+
]);
4750
assert.strictEqual(child.status, 0);
4851
assert.strictEqual(child.signal, null);
4952

test/parallel/test-runner-inspect.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ common.skipIfInspectorDisabled();
1111
tmpdir.refresh();
1212

1313
{
14-
const child = new NodeInstance(['--test', '--inspect-brk=0'], undefined, fixtures.path('test-runner/index.test.js'));
14+
const child = new NodeInstance(
15+
['--test', '--inspect-brk=0'],
16+
undefined,
17+
fixtures.path('test-runner/default-behavior/index.test.js')
18+
);
1519

1620
let stdout = '';
1721
let stderr = '';

test/parallel/test-runner-run.mjs

+26-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
2626
});
2727

2828
it('should succeed with a file', async () => {
29-
const stream = run({ files: [join(testFixtures, 'test/random.cjs')] });
29+
const stream = run({ files: [join(testFixtures, 'default-behavior/test/random.cjs')] });
3030
stream.on('test:fail', common.mustNotCall());
3131
stream.on('test:pass', common.mustCall(1));
3232
// eslint-disable-next-line no-unused-vars
3333
for await (const _ of stream);
3434
});
3535

3636
it('should run same file twice', async () => {
37-
const stream = run({ files: [join(testFixtures, 'test/random.cjs'), join(testFixtures, 'test/random.cjs')] });
37+
const stream = run({
38+
files: [
39+
join(testFixtures, 'default-behavior/test/random.cjs'),
40+
join(testFixtures, 'default-behavior/test/random.cjs'),
41+
]
42+
});
3843
stream.on('test:fail', common.mustNotCall());
3944
stream.on('test:pass', common.mustCall(2));
4045
// eslint-disable-next-line no-unused-vars
@@ -68,7 +73,9 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
6873
});
6974

7075
it('should be piped with dot', async () => {
71-
const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(dot).toArray();
76+
const result = await run({
77+
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
78+
}).compose(dot).toArray();
7279
assert.deepStrictEqual(result, [
7380
'.',
7481
'\n',
@@ -77,15 +84,19 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
7784

7885
it('should be piped with spec', async () => {
7986
const specReporter = new spec();
80-
const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(specReporter).toArray();
87+
const result = await run({
88+
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
89+
}).compose(specReporter).toArray();
8190
const stringResults = result.map((bfr) => bfr.toString());
8291
assert.match(stringResults[0], /this should pass/);
8392
assert.match(stringResults[1], /tests 1/);
8493
assert.match(stringResults[1], /pass 1/);
8594
});
8695

8796
it('should be piped with tap', async () => {
88-
const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(tap).toArray();
97+
const result = await run({
98+
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
99+
}).compose(tap).toArray();
89100
assert.strictEqual(result.length, 13);
90101
assert.strictEqual(result[0], 'TAP version 13\n');
91102
assert.strictEqual(result[1], '# Subtest: this should pass\n');
@@ -103,15 +114,21 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
103114
});
104115

105116
it('should skip tests not matching testNamePatterns - RegExp', async () => {
106-
const result = await run({ files: [join(testFixtures, 'test/skip_by_name.cjs')], testNamePatterns: [/executed/] })
117+
const result = await run({
118+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
119+
testNamePatterns: [/executed/]
120+
})
107121
.compose(tap)
108122
.toArray();
109123
assert.strictEqual(result[2], 'ok 1 - this should be skipped # SKIP test name does not match pattern\n');
110124
assert.strictEqual(result[5], 'ok 2 - this should be executed\n');
111125
});
112126

113127
it('should skip tests not matching testNamePatterns - string', async () => {
114-
const result = await run({ files: [join(testFixtures, 'test/skip_by_name.cjs')], testNamePatterns: ['executed'] })
128+
const result = await run({
129+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
130+
testNamePatterns: ['executed']
131+
})
115132
.compose(tap)
116133
.toArray();
117134
assert.strictEqual(result[2], 'ok 1 - this should be skipped # SKIP test name does not match pattern\n');
@@ -121,7 +138,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
121138
it('should emit "test:watch:drained" event on watch mode', async () => {
122139
const controller = new AbortController();
123140
await run({
124-
files: [join(testFixtures, 'test/random.cjs')],
141+
files: [join(testFixtures, 'default-behavior/test/random.cjs')],
125142
watch: true,
126143
signal: controller.signal,
127144
}).on('data', function({ type }) {
@@ -135,7 +152,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
135152
it('should stop watch mode when abortSignal aborts', async () => {
136153
const controller = new AbortController();
137154
const result = await run({
138-
files: [join(testFixtures, 'test/random.cjs')],
155+
files: [join(testFixtures, 'default-behavior/test/random.cjs')],
139156
watch: true,
140157
signal: controller.signal,
141158
})

0 commit comments

Comments
 (0)