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
Next Next commit
test_runner: remove cwd path validation
  • Loading branch information
pmarchini committed Oct 1, 2024
commit e6e83292d673688ac13c095b8c9c9d87c6648674
7 changes: 0 additions & 7 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const {
} = require('internal/test_runner/utils');
const { Glob } = require('internal/fs/glob');
const { once } = require('events');
const { existsSync, lstatSync } = require('fs');
const {
triggerUncaughtException,
exitCodes: { kGenericUserError },
Expand Down Expand Up @@ -591,12 +590,6 @@ function run(options = kEmptyObject) {

validateString(cwd, 'options.cwd');

if (existsSync(cwd) === false) {
throw new ERR_INVALID_ARG_VALUE('options.cwd', cwd, 'expects an existing directory');
} else if (!lstatSync(cwd).isDirectory()) {
throw new ERR_INVALID_ARG_VALUE('options.cwd', cwd, 'expects a directory, a file was provided');
}

if (globPatterns?.length > 0 && files?.length > 0) {
throw new ERR_INVALID_ARG_VALUE(
'options.globPatterns', globPatterns, 'is not supported when specifying \'options.files\'',
Expand Down
58 changes: 48 additions & 10 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -547,22 +547,60 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
for await (const _ of stream);
});

it('should throw if an invalid cwd is provided', async () => {
assert.throws(() => run({
it('should handle a non-existent directory being provided as cwd', async () => {
const diagnostics = [];
const stream = run({
cwd: fixtures.path('test-runner', 'cwd', 'non-existing')
}), {
code: 'ERR_INVALID_ARG_VALUE',
message: /expects an existing directory/
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustNotCall());
stream.on('test:stderr', common.mustNotCall());
stream.on('test:diagnostic', ({ message }) => {
diagnostics.push(message);
});

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
for (const entry of [
'tests 0',
'suites 0',
'pass 0',
'fail 0',
'cancelled 0',
'skipped 0',
'todo 0',
]
) {
assert.strictEqual(diagnostics.includes(entry), true);
}
});

it('should throw if a file is provided as cwd', async () => {
assert.throws(() => run({
it('should handle a non-existent file being provided as cwd', async () => {
const diagnostics = [];
const stream = run({
cwd: fixtures.path('test-runner', 'default-behavior', 'test', 'random.cjs')
}), {
code: 'ERR_INVALID_ARG_VALUE',
message: /expects a directory, a file was provided/
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustNotCall());
stream.on('test:stderr', common.mustNotCall());
stream.on('test:diagnostic', ({ message }) => {
diagnostics.push(message);
});

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
for (const entry of [
'tests 0',
'suites 0',
'pass 0',
'fail 0',
'cancelled 0',
'skipped 0',
'todo 0',
]
) {
assert.strictEqual(diagnostics.includes(entry), true);
}
});

it('should run with different cwd while in watch mode', async () => {
Expand Down