Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test_runner: add more run validation
  • Loading branch information
rluvaton committed Oct 6, 2023
commit 9ffad8667e7afc2c13ec52f019cebc895ef403fc
8 changes: 2 additions & 6 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,8 @@ function watchFiles(testFiles, opts) {
return filesWatcher;
}

function run(options) {
if (options != null) {
validateObject(options, 'options');
}

options = options ?? kEmptyObject;
function run(options = kEmptyObject) {
validateObject(options, 'options');

let { testNamePatterns, shard } = options;
const { concurrency, timeout, signal, files, inspectPort, watch, setup, only } = options;
Expand Down
29 changes: 16 additions & 13 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import assert from 'node:assert';
const testFixtures = fixtures.path('test-runner');

describe('require(\'node:test\').run', { concurrency: true }, () => {
it('should fail when passing array as options', () => {
assert.throws(() => run([]), {
code: 'ERR_INVALID_ARG_TYPE'
});
});

it('should run with no tests', async () => {
const stream = run({ files: [] });
stream.on('test:fail', common.mustNotCall());
Expand Down Expand Up @@ -70,13 +64,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
for await (const _ of stream);
});

it('should validate files', async () => {
[Symbol(), {}, () => {}, 0, 1, 0n, 1n, '', '1', Promise.resolve([]), true, false]
.forEach((files) => assert.throws(() => run({ files }), {
code: 'ERR_INVALID_ARG_TYPE'
}));
});

it('should be piped with dot', async () => {
const result = await run({
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
Expand Down Expand Up @@ -442,4 +429,20 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
assert.deepStrictEqual(executedTestFiles.sort(), [...shardsTestsFiles].sort());
});
});

describe('validation', () => {
it('should only allow array in options.files', async () => {
[Symbol(), {}, () => {}, 0, 1, 0n, 1n, '', '1', Promise.resolve([]), true, false]
.forEach((files) => assert.throws(() => run({ files }), {
code: 'ERR_INVALID_ARG_TYPE'
}));
});

it('should only allow object as options', () => {
[Symbol(), [], () => {}, 0, 1, 0n, 1n, '', '1', true, false]
.forEach((options) => assert.throws(() => run(options), {
code: 'ERR_INVALID_ARG_TYPE'
}));
});
});
});