Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report non-match to STDERR and exit if no files are matched #2450

Merged
merged 2 commits into from
Sep 18, 2016
Merged
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
19 changes: 18 additions & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add an error message here about no files being found, given you can simply execute mocha in a directory with empty subdir test, and this is the current output:

$ mocha


  0 passing (3ms)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

// resolve

files = files.map(function(path) {
Expand Down
15 changes: 13 additions & 2 deletions test/acceptance/glob/glob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
exit 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.
Expand All @@ -47,7 +58,7 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
exit 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
}
Expand Down