Skip to content

Commit

Permalink
test: reorder test files fixtures for better understanding
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Jul 25, 2023
1 parent a0f3ed8 commit 8c3dd7e
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 30 deletions.
File renamed without changes.
@@ -0,0 +1 @@
console.log('invalid tap output');
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/test-runner/default-behavior/random.test.mjs
@@ -0,0 +1,5 @@
import test from 'node:test';

test('this should fail', () => {
throw new Error('this is a failing test');
});
Empty file.
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/default-behavior/test/random.cjs
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
2 changes: 0 additions & 2 deletions test/fixtures/test-runner/index.js

This file was deleted.

@@ -0,0 +1,5 @@
import test from 'node:test';

test('this should fail', () => {
throw new Error('this is a failing test');
});
@@ -0,0 +1,5 @@
'use strict';
const test = require('node:test');

test('this should be skipped');
test('this should be executed');
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/specific-test-files/success.cjs
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
2 changes: 2 additions & 0 deletions test/fixtures/test-runner/specific-test-files/throwing.js
@@ -0,0 +1,2 @@
'use strict';
throw new Error('thrown from throwing.js');
28 changes: 14 additions & 14 deletions test/parallel/test-runner-cli.js
Expand Up @@ -22,7 +22,7 @@ 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'];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });

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

const stdout = child.stdout.toString();
assert.match(stdout, /ok 1 - this should pass/);
Expand All @@ -55,14 +55,14 @@ const testFixtures = fixtures.path('test-runner');

{
// User specified files that don't match the pattern are still run.
const args = ['--test', join(testFixtures, 'index.js')];
const args = ['--test', join(testFixtures, 'specific-test-files/throwing.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, /not ok 1 - .+throwing\.js/);
}

{
Expand All @@ -80,7 +80,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);
Expand Down Expand Up @@ -119,9 +119,9 @@ const testFixtures = fixtures.path('test-runner');
// Test combined stream outputs
const args = [
'--test',
'test/fixtures/test-runner/index.test.js',
'test/fixtures/test-runner/nested.js',
'test/fixtures/test-runner/invalid-tap.js',
'test/fixtures/test-runner/combined-stream-output/index.test.js',
'test/fixtures/test-runner/combined-stream-output/nested.js',
'test/fixtures/test-runner/combined-stream-output/invalid-tap.js',
];
const child = spawnSync(process.execPath, args);

Expand Down Expand Up @@ -197,7 +197,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, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.stderr.toString(), '');
Expand All @@ -209,7 +209,7 @@ const testFixtures = fixtures.path('test-runner');

{
// --test-shard option validation
const args = ['--test', '--test-shard=1', join(testFixtures, 'index.js')];
const args = ['--test', '--test-shard=1', join(testFixtures, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
Expand All @@ -221,7 +221,7 @@ const testFixtures = fixtures.path('test-runner');

{
// --test-shard option validation
const args = ['--test', '--test-shard=1/2/3', join(testFixtures, 'index.js')];
const args = ['--test', '--test-shard=1/2/3', join(testFixtures, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
Expand All @@ -233,7 +233,7 @@ const testFixtures = fixtures.path('test-runner');

{
// --test-shard option validation
const args = ['--test', '--test-shard=0/3', join(testFixtures, 'index.js')];
const args = ['--test', '--test-shard=0/3', join(testFixtures, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
Expand All @@ -245,7 +245,7 @@ const testFixtures = fixtures.path('test-runner');

{
// --test-shard option validation
const args = ['--test', '--test-shard=0xf/20abcd', join(testFixtures, 'index.js')];
const args = ['--test', '--test-shard=0xf/20abcd', join(testFixtures, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
Expand All @@ -257,7 +257,7 @@ const testFixtures = fixtures.path('test-runner');

{
// --test-shard option validation
const args = ['--test', '--test-shard=hello', join(testFixtures, 'index.js')];
const args = ['--test', '--test-shard=hello', join(testFixtures, 'specific-test-files/success.cjs')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-runner-inspect.mjs
Expand Up @@ -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/specific-test-files/success.test.cjs')
);

let stdout = '';
let stderr = '';
Expand All @@ -31,12 +35,12 @@ tmpdir.refresh();


{
const args = ['--test', '--inspect=0', fixtures.path('test-runner/index.js')];
const args = ['--test', '--inspect=0', fixtures.path('test-runner/specific-test-files/throwing.js')];
const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args);

assert.match(stderr,
/Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/);
assert.match(stdout, /not ok 1 - .+index\.js/);
assert.match(stdout, /not ok 1 - .+throwing\.js/);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
}
Expand Down
29 changes: 18 additions & 11 deletions test/parallel/test-runner-run.mjs
Expand Up @@ -26,15 +26,16 @@ 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, 'specific-test-files', 'success.cjs')] });
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should run same file twice', async () => {
const stream = run({ files: [join(testFixtures, 'test/random.cjs'), join(testFixtures, 'test/random.cjs')] });
const testFile = join(testFixtures, 'specific-test-files', 'success.cjs');
const stream = run({ files: [testFile, testFile] });
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(2));
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -68,7 +69,7 @@ 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, 'specific-test-files/success.cjs')] }).compose(dot).toArray();
assert.deepStrictEqual(result, [
'.',
'\n',
Expand All @@ -77,15 +78,17 @@ 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, 'specific-test-files/success.cjs')]
}).compose(specReporter).toArray();
const stringResults = result.map((bfr) => bfr.toString());
assert.match(stringResults[0], /this should pass/);
assert.match(stringResults[1], /tests 1/);
assert.match(stringResults[1], /pass 1/);
});

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, 'specific-test-files/success.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');
Expand All @@ -103,15 +106,18 @@ 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, 'specific-test-files/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');
assert.strictEqual(result[5], 'ok 2 - this should be executed\n');
});

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, 'specific-test-files/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');
Expand All @@ -134,10 +140,11 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
describe('AbortSignal', () => {
it('should stop watch mode when abortSignal aborts', async () => {
const controller = new AbortController();
const result = await run({
files: [join(testFixtures, 'test/random.cjs')],
watch: true,
signal: controller.signal,
const result = await run({

Check failure on line 143 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 6 spaces but found 4
files: [join(testFixtures, 'specific-test-files/success.cjs')],

Check failure on line 144 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
watch: true,

Check failure on line 145 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
signal: controller.signal

Check failure on line 146 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
,

Check failure on line 147 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 3
})
.compose(async function* (source) {
for await (const chunk of source) {
Expand Down

0 comments on commit 8c3dd7e

Please sign in to comment.