Skip to content

Commit ec3ff3e

Browse files
committed
test_runner: remove cwd path validation
1 parent 768c088 commit ec3ff3e

2 files changed

Lines changed: 48 additions & 17 deletions

File tree

lib/internal/test_runner/runner.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const {
8686
} = require('internal/test_runner/utils');
8787
const { Glob } = require('internal/fs/glob');
8888
const { once } = require('events');
89-
const { existsSync, lstatSync } = require('fs');
9089
const {
9190
triggerUncaughtException,
9291
exitCodes: { kGenericUserError },
@@ -565,12 +564,6 @@ function run(options = kEmptyObject) {
565564

566565
validateString(cwd, 'options.cwd');
567566

568-
if (existsSync(cwd) === false) {
569-
throw new ERR_INVALID_ARG_VALUE('options.cwd', cwd, 'expects an existing directory');
570-
} else if (!lstatSync(cwd).isDirectory()) {
571-
throw new ERR_INVALID_ARG_VALUE('options.cwd', cwd, 'expects a directory, a file was provided');
572-
}
573-
574567
if (globPatterns?.length > 0 && files?.length > 0) {
575568
throw new ERR_INVALID_ARG_VALUE(
576569
'options.globPatterns', globPatterns, 'is not supported when specifying \'options.files\'',

test/parallel/test-runner-run.mjs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -533,22 +533,60 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
533533
for await (const _ of stream);
534534
});
535535

536-
it('should throw if an invalid cwd is provided', async () => {
537-
assert.throws(() => run({
536+
it('should handle a non-existent directory being provided as cwd', async () => {
537+
const diagnostics = [];
538+
const stream = run({
538539
cwd: fixtures.path('test-runner', 'cwd', 'non-existing')
539-
}), {
540-
code: 'ERR_INVALID_ARG_VALUE',
541-
message: /expects an existing directory/
542540
});
541+
stream.on('test:fail', common.mustNotCall());
542+
stream.on('test:pass', common.mustNotCall());
543+
stream.on('test:stderr', common.mustNotCall());
544+
stream.on('test:diagnostic', ({ message }) => {
545+
diagnostics.push(message);
546+
});
547+
548+
// eslint-disable-next-line no-unused-vars
549+
for await (const _ of stream);
550+
for (const entry of [
551+
'tests 0',
552+
'suites 0',
553+
'pass 0',
554+
'fail 0',
555+
'cancelled 0',
556+
'skipped 0',
557+
'todo 0',
558+
]
559+
) {
560+
assert.strictEqual(diagnostics.includes(entry), true);
561+
}
543562
});
544563

545-
it('should throw if a file is provided as cwd', async () => {
546-
assert.throws(() => run({
564+
it('should handle a non-existent file being provided as cwd', async () => {
565+
const diagnostics = [];
566+
const stream = run({
547567
cwd: fixtures.path('test-runner', 'default-behavior', 'test', 'random.cjs')
548-
}), {
549-
code: 'ERR_INVALID_ARG_VALUE',
550-
message: /expects a directory, a file was provided/
551568
});
569+
stream.on('test:fail', common.mustNotCall());
570+
stream.on('test:pass', common.mustNotCall());
571+
stream.on('test:stderr', common.mustNotCall());
572+
stream.on('test:diagnostic', ({ message }) => {
573+
diagnostics.push(message);
574+
});
575+
576+
// eslint-disable-next-line no-unused-vars
577+
for await (const _ of stream);
578+
for (const entry of [
579+
'tests 0',
580+
'suites 0',
581+
'pass 0',
582+
'fail 0',
583+
'cancelled 0',
584+
'skipped 0',
585+
'todo 0',
586+
]
587+
) {
588+
assert.strictEqual(diagnostics.includes(entry), true);
589+
}
552590
});
553591

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

0 commit comments

Comments
 (0)