Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit e5f8f73

Browse files
Munterboneskull
authored andcommitted
Report non-match to STDERR and exit if no files are matched (mochajs#2450)
* Report non-matching patterns to STDERR and exit with non-zero status if no files are matched at all. Fixes mochajs#2194 * Code review changes
1 parent 79f61a4 commit e5f8f73

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

bin/_mocha

+18-1
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,26 @@ if (!args.length) {
358358
}
359359

360360
args.forEach(function(arg) {
361-
files = files.concat(utils.lookupFiles(arg, extensions, program.recursive));
361+
var newFiles;
362+
try {
363+
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
364+
} catch (err) {
365+
if (err.message.indexOf('cannot resolve path') === 0) {
366+
console.error('Warning: Could not find any test files matching pattern: ' + arg);
367+
return;
368+
}
369+
370+
throw err;
371+
}
372+
373+
files = files.concat(newFiles);
362374
});
363375

376+
if (!files.length) {
377+
console.error('No test files found');
378+
process.exit(1);
379+
}
380+
364381
// resolve
365382

366383
files = files.map(function(path) {

test/acceptance/glob/glob.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,22 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
2222
exit 1
2323
}
2424

25-
cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {
25+
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
2626
echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
2727
exit 1
2828
}
2929

30+
../../../bin/mocha -R json-stream ./*.js ./*-none.js >& /tmp/mocha-glob.txt || {
31+
echo Globbing ./*.js ./*-none.js in `pwd` failed.
32+
exit 1
33+
}
34+
35+
cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' &&
36+
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
37+
echo Globbing ./*.js ./*-none.js in `pwd` should match glob.js with one test inside and display one warning for the non-existing file.
38+
exit 1
39+
}
40+
3041
# Globbing in windows command-shell differs completely from unix-style globbing.
3142
# In bash, the shell expands globs and passes the result to executables.
3243
# In windows, the shell passes globs unexpanded, executables do expansion if they support it.
@@ -47,7 +58,7 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
4758
exit 1
4859
}
4960

50-
cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {
61+
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
5162
echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
5263
exit 1
5364
}

0 commit comments

Comments
 (0)