From d8cea5d27e742f141e1335256ff343b73b1f4caf Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Wed, 26 Jul 2023 20:16:31 +0300 Subject: [PATCH] test: reorder test files fixtures for better understanding PR-URL: https://github.com/nodejs/node/pull/48787 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow --- .../{ => default-behavior}/index.test.js | 0 .../node_modules/test-nm.js | 0 .../{ => default-behavior}/random.test.mjs | 0 .../subdir/subdir_test.js | 0 .../{ => default-behavior}/test/random.cjs | 0 .../test/skip_by_name.cjs | 0 test/parallel/test-runner-cli.js | 24 ++++++------- test/parallel/test-runner-exit-code.js | 5 ++- test/parallel/test-runner-inspect.mjs | 6 +++- test/parallel/test-runner-run.mjs | 35 ++++++++++++++----- 10 files changed, 45 insertions(+), 25 deletions(-) rename test/fixtures/test-runner/{ => default-behavior}/index.test.js (100%) rename test/fixtures/test-runner/{ => default-behavior}/node_modules/test-nm.js (100%) rename test/fixtures/test-runner/{ => default-behavior}/random.test.mjs (100%) rename test/fixtures/test-runner/{ => default-behavior}/subdir/subdir_test.js (100%) rename test/fixtures/test-runner/{ => default-behavior}/test/random.cjs (100%) rename test/fixtures/test-runner/{ => default-behavior}/test/skip_by_name.cjs (100%) diff --git a/test/fixtures/test-runner/index.test.js b/test/fixtures/test-runner/default-behavior/index.test.js similarity index 100% rename from test/fixtures/test-runner/index.test.js rename to test/fixtures/test-runner/default-behavior/index.test.js diff --git a/test/fixtures/test-runner/node_modules/test-nm.js b/test/fixtures/test-runner/default-behavior/node_modules/test-nm.js similarity index 100% rename from test/fixtures/test-runner/node_modules/test-nm.js rename to test/fixtures/test-runner/default-behavior/node_modules/test-nm.js diff --git a/test/fixtures/test-runner/random.test.mjs b/test/fixtures/test-runner/default-behavior/random.test.mjs similarity index 100% rename from test/fixtures/test-runner/random.test.mjs rename to test/fixtures/test-runner/default-behavior/random.test.mjs diff --git a/test/fixtures/test-runner/subdir/subdir_test.js b/test/fixtures/test-runner/default-behavior/subdir/subdir_test.js similarity index 100% rename from test/fixtures/test-runner/subdir/subdir_test.js rename to test/fixtures/test-runner/default-behavior/subdir/subdir_test.js diff --git a/test/fixtures/test-runner/test/random.cjs b/test/fixtures/test-runner/default-behavior/test/random.cjs similarity index 100% rename from test/fixtures/test-runner/test/random.cjs rename to test/fixtures/test-runner/default-behavior/test/random.cjs diff --git a/test/fixtures/test-runner/test/skip_by_name.cjs b/test/fixtures/test-runner/default-behavior/test/skip_by_name.cjs similarity index 100% rename from test/fixtures/test-runner/test/skip_by_name.cjs rename to test/fixtures/test-runner/default-behavior/test/skip_by_name.cjs diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 496f53e23ea3a6..81e20045e33bdd 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -22,8 +22,8 @@ const testFixtures = fixtures.path('test-runner'); { // Default behavior. node_modules is ignored. Files that don't match the // pattern are ignored except in test/ directories. - const args = ['--test', testFixtures]; - const child = spawnSync(process.execPath, args); + const args = ['--test']; + const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') }); assert.strictEqual(child.status, 1); assert.strictEqual(child.signal, null); @@ -39,8 +39,8 @@ const testFixtures = fixtures.path('test-runner'); { // Same but with a prototype mutation in require scripts. - const args = ['--require', join(testFixtures, 'protoMutation.js'), '--test', testFixtures]; - const child = spawnSync(process.execPath, args); + const args = ['--require', join(testFixtures, 'protoMutation.js'), '--test']; + const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') }); const stdout = child.stdout.toString(); assert.match(stdout, /ok 1 - this should pass/); @@ -56,23 +56,19 @@ const testFixtures = fixtures.path('test-runner'); { // User specified files that don't match the pattern are still run. - const args = ['--test', testFixtures, join(testFixtures, 'index.js')]; - const child = spawnSync(process.execPath, args); + const args = ['--test', join(testFixtures, 'index.js')]; + const child = spawnSync(process.execPath, args, { cwd: testFixtures }); assert.strictEqual(child.status, 1); assert.strictEqual(child.signal, null); assert.strictEqual(child.stderr.toString(), ''); const stdout = child.stdout.toString(); assert.match(stdout, /not ok 1 - .+index\.js/); - assert.match(stdout, /ok 2 - this should pass/); - assert.match(stdout, /not ok 3 - this should fail/); - assert.match(stdout, /ok 4 - .+subdir.+subdir_test\.js/); - assert.match(stdout, /ok 5 - this should pass/); } { // Searches node_modules if specified. - const args = ['--test', join(testFixtures, 'node_modules')]; + const args = ['--test', join(testFixtures, 'default-behavior/node_modules')]; const child = spawnSync(process.execPath, args); assert.strictEqual(child.status, 1); @@ -85,7 +81,7 @@ const testFixtures = fixtures.path('test-runner'); { // The current directory is used by default. const args = ['--test']; - const options = { cwd: testFixtures }; + const options = { cwd: join(testFixtures, 'default-behavior') }; const child = spawnSync(process.execPath, args, options); assert.strictEqual(child.status, 1); @@ -124,7 +120,7 @@ const testFixtures = fixtures.path('test-runner'); // Test combined stream outputs const args = [ '--test', - 'test/fixtures/test-runner/index.test.js', + 'test/fixtures/test-runner/default-behavior/index.test.js', 'test/fixtures/test-runner/nested.js', 'test/fixtures/test-runner/invalid-tap.js', ]; @@ -202,7 +198,7 @@ const testFixtures = fixtures.path('test-runner'); const args = ['--no-warnings', '--experimental-loader', 'data:text/javascript,', '--require', fixtures.path('empty.js'), - '--test', join(testFixtures, 'index.test.js')]; + '--test', join(testFixtures, 'default-behavior', 'index.test.js')]; const child = spawnSync(process.execPath, args); assert.strictEqual(child.stderr.toString(), ''); diff --git a/test/parallel/test-runner-exit-code.js b/test/parallel/test-runner-exit-code.js index c0892055aea7fb..700480386d5b4a 100644 --- a/test/parallel/test-runner-exit-code.js +++ b/test/parallel/test-runner-exit-code.js @@ -43,7 +43,10 @@ if (process.argv[2] === 'child') { assert.strictEqual(child.status, 0); assert.strictEqual(child.signal, null); - child = spawnSync(process.execPath, ['--test', fixtures.path('test-runner', 'subdir', 'subdir_test.js')]); + child = spawnSync(process.execPath, [ + '--test', + fixtures.path('test-runner', 'default-behavior', 'subdir', 'subdir_test.js'), + ]); assert.strictEqual(child.status, 0); assert.strictEqual(child.signal, null); diff --git a/test/parallel/test-runner-inspect.mjs b/test/parallel/test-runner-inspect.mjs index a8fd9770948c7a..4cfc6bea54b964 100644 --- a/test/parallel/test-runner-inspect.mjs +++ b/test/parallel/test-runner-inspect.mjs @@ -11,7 +11,11 @@ common.skipIfInspectorDisabled(); tmpdir.refresh(); { - const child = new NodeInstance(['--test', '--inspect-brk=0'], undefined, fixtures.path('test-runner/index.test.js')); + const child = new NodeInstance( + ['--test', '--inspect-brk=0'], + undefined, + fixtures.path('test-runner/default-behavior/index.test.js') + ); let stdout = ''; let stderr = ''; diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 7e4a8fbe76753a..62fab0af146f4d 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -26,7 +26,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should succeed with a file', async () => { - const stream = run({ files: [join(testFixtures, 'test/random.cjs')] }); + const stream = run({ files: [join(testFixtures, 'default-behavior/test/random.cjs')] }); stream.on('test:fail', common.mustNotCall()); stream.on('test:pass', common.mustCall(1)); // eslint-disable-next-line no-unused-vars @@ -34,7 +34,12 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should run same file twice', async () => { - const stream = run({ files: [join(testFixtures, 'test/random.cjs'), join(testFixtures, 'test/random.cjs')] }); + const stream = run({ + files: [ + join(testFixtures, 'default-behavior/test/random.cjs'), + join(testFixtures, 'default-behavior/test/random.cjs'), + ] + }); stream.on('test:fail', common.mustNotCall()); stream.on('test:pass', common.mustCall(2)); // eslint-disable-next-line no-unused-vars @@ -68,7 +73,9 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should be piped with dot', async () => { - const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(dot).toArray(); + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/random.cjs')] + }).compose(dot).toArray(); assert.deepStrictEqual(result, [ '.', '\n', @@ -77,7 +84,9 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { it('should be piped with spec', async () => { const specReporter = new spec(); - const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(specReporter).toArray(); + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/random.cjs')] + }).compose(specReporter).toArray(); const stringResults = result.map((bfr) => bfr.toString()); assert.match(stringResults[0], /this should pass/); assert.match(stringResults[1], /tests 1/); @@ -85,7 +94,9 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should be piped with tap', async () => { - const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(tap).toArray(); + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/random.cjs')] + }).compose(tap).toArray(); assert.strictEqual(result.length, 13); assert.strictEqual(result[0], 'TAP version 13\n'); assert.strictEqual(result[1], '# Subtest: this should pass\n'); @@ -103,7 +114,10 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should skip tests not matching testNamePatterns - RegExp', async () => { - const result = await run({ files: [join(testFixtures, 'test/skip_by_name.cjs')], testNamePatterns: [/executed/] }) + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')], + testNamePatterns: [/executed/] + }) .compose(tap) .toArray(); assert.strictEqual(result[2], 'ok 1 - this should be skipped # SKIP test name does not match pattern\n'); @@ -111,7 +125,10 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { }); it('should skip tests not matching testNamePatterns - string', async () => { - const result = await run({ files: [join(testFixtures, 'test/skip_by_name.cjs')], testNamePatterns: ['executed'] }) + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')], + testNamePatterns: ['executed'] + }) .compose(tap) .toArray(); 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 }, () => { it('should emit "test:watch:drained" event on watch mode', async () => { const controller = new AbortController(); await run({ - files: [join(testFixtures, 'test/random.cjs')], + files: [join(testFixtures, 'default-behavior/test/random.cjs')], watch: true, signal: controller.signal, }).on('data', function({ type }) { @@ -135,7 +152,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { it('should stop watch mode when abortSignal aborts', async () => { const controller = new AbortController(); const result = await run({ - files: [join(testFixtures, 'test/random.cjs')], + files: [join(testFixtures, 'default-behavior/test/random.cjs')], watch: true, signal: controller.signal, })