☕️ Classic, reliable, trusted test framework for Node.js and the browser
Report non-match to STDERR and exit if no files are matched (#2450)
Peter Müller1786fe2c2c47
diff --git a/bin/_mocha b/bin/_mochaindex fe3f6786..b355e283 100755--- a/bin/_mocha+++ b/bin/_mocha@@ -358,9 +358,26 @@ if (!args.length) {}args.forEach(function(arg) {- files = files.concat(utils.lookupFiles(arg, extensions, program.recursive));+ var newFiles;+ try {+ newFiles = utils.lookupFiles(arg, extensions, program.recursive);+ } catch (err) {+ if (err.message.indexOf('cannot resolve path') === 0) {+ console.error('Warning: Could not find any test files matching pattern: ' + arg);+ return;+ }++ throw err;+ }++ files = files.concat(newFiles);});+if (!files.length) {+ console.error('No test files found');+ process.exit(1);+}+// resolvefiles = files.map(function(path) {diff --git a/test/acceptance/glob/glob.sh b/test/acceptance/glob/glob.shindex a2b8c6fe..823ba07f 100755--- a/test/acceptance/glob/glob.sh+++ b/test/acceptance/glob/glob.sh@@ -22,11 +22,22 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pexit 1}-cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {+cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {echo Globbing './*-none.js' in `pwd` should match no files and run no tests.exit 1}+../../../bin/mocha -R json-stream ./*.js ./*-none.js >& /tmp/mocha-glob.txt || {+ echo Globbing ./*.js ./*-none.js in `pwd` failed.+ exit 1+}++cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' &&+cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {+ echo Globbing ./*.js ./*-none.js in `pwd` should match glob.js with one test inside and display one warning for the non-existing file.+ exit 1+}+# Globbing in windows command-shell differs completely from unix-style globbing.# In bash, the shell expands globs and passes the result to executables.# 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,"pexit 1}-cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {+cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {echo Globbing './*-none.js' in `pwd` should match no files and run no tests.exit 1}