Skip to content

Commit

Permalink
use errors only if no tests found
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 3, 2019
1 parent 964f363 commit afc429e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
let errors = [];
spec.forEach(arg => {
let newFiles;
try {
newFiles = utils.lookupFiles(arg, extension, recursive);
} catch (err) {
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
console.error(ansi.red(`${symbols.error} ${err.message}`));
errors.push(err.message);
return;
}

Expand All @@ -164,8 +165,16 @@ exports.handleFiles = ({
});

if (!files.length) {
// prints message about each individual missing file already
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`${symbols.error} ${message}`));
});
process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
console.warn(`Warning: ${message}`);
});
}

const fileArgs = file.map(filepath => path.resolve(filepath));
Expand Down
6 changes: 3 additions & 3 deletions test/integration/glob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
' Cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
' Cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
' Cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down

0 comments on commit afc429e

Please sign in to comment.