Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
} = primordials;

const { spawn } = require('child_process');
const { existsSync } = require('fs');
const { finished } = require('internal/streams/end-of-stream');
const { availableParallelism } = require('os');
const { resolve, sep, isAbsolute } = require('path');
Expand Down Expand Up @@ -161,9 +162,19 @@ function createTestFileList(patterns, cwd) {
});
const results = glob.globSync();

if (hasUserSuppliedPattern && results.length === 0 && ArrayPrototypeEvery(glob.matchers, (m) => !m.hasMagic())) {
console.error(`Could not find '${ArrayPrototypeJoin(patterns, ', ')}'`);
process.exit(kGenericUserError);
if (hasUserSuppliedPattern) {
if (results.length === 0 && ArrayPrototypeEvery(glob.matchers, (m) => !m.hasMagic())) {
console.error(`Could not find '${ArrayPrototypeJoin(patterns, ', ')}'`);
process.exit(kGenericUserError);
}

const missing = ArrayPrototypeFilter(patterns, (pattern, i) => {
return !glob.matchers[i].hasMagic() && !existsSync(resolve(cwd, pattern));
});

if (missing.length > 0) {
process.emitWarning(`Could not find '${ArrayPrototypeJoin(missing, ', ')}'`);
}
}

return ArrayPrototypeSort(results);
Expand Down
37 changes: 37 additions & 0 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,43 @@ for (const isolation of ['none', 'process']) {
assert.match(child.stderr.toString(), /^Could not find/);
}

{
// A file that is not found should warn even when other patterns match,
// and the matching tests should still run.
const args = [
'--test',
`--test-isolation=${isolation}`,
'a-random-file-that-does-not-exist.js',
join(testFixtures, 'default-behavior/test/random.cjs'),
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(),
/Warning: Could not find 'a-random-file-that-does-not-exist\.js'/);
assert.match(child.stdout.toString(), /this should pass/);
}

{
// Options after positional arguments are treated as patterns and should
// warn instead of being silently dropped.
const args = [
'--test',
`--test-isolation=${isolation}`,
join(testFixtures, 'default-behavior/test/random.cjs'),
'--test-reporter',
'tap',
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.match(child.stderr.toString(),
/Warning: Could not find '--test-reporter, tap'/);
assert.match(child.stdout.toString(), /this should pass/);
}

{
// Default behavior. node_modules is ignored. Files that don't match the
// pattern are ignored except in test/ directories.
Expand Down