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

Commit

Permalink
Fix message if no files found (mochajs#3650)
Browse files Browse the repository at this point in the history
* error and exit, dont warn

* return after error dont exit yet

* remove superflous message

* update glob tests

* update message

* use errors only if no tests found

* dont use error symbol.
  • Loading branch information
craigtaub authored Jan 4, 2019
1 parent 1df8ffe commit b3463e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
14 changes: 11 additions & 3 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const path = require('path');
const utils = require('../utils');
const minimatch = require('minimatch');
const ansi = require('ansi-colors');
const symbols = require('log-symbols');

const cwd = (exports.cwd = process.cwd());

Expand Down Expand Up @@ -138,13 +137,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
const 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.warn('Warning: %s: %O', err.message, err.pattern);
errors.push(err.message);
return;
}

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

if (!files.length) {
console.error(ansi.red(`${symbols.error} No test files found`));
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`Error: ${message}`));
});
process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
console.warn(ansi.yellow(`Warning: ${message}`));
});
}

const fileArgs = file.map(filepath => path.resolve(filepath));
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
files = glob.sync(filepath);
if (!files.length) {
throw createNoFilesMatchPatternError(
'cannot find any files matching pattern "' + filepath + '"',
'Cannot find any files matching pattern "' + filepath + '"',
filepath
);
}
Expand Down
12 changes: 6 additions & 6 deletions test/integration/glob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern "./*-none.js"'
'Error: Cannot find any files matching pattern "./*-none.js"'
);
},
done
Expand All @@ -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 @@ -77,7 +77,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./*-none.js"'
);
},
done
Expand All @@ -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 @@ -125,7 +125,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./**/*-none.js"'
);
},
done
Expand All @@ -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 b3463e9

Please sign in to comment.