Skip to content

Commit

Permalink
Merge 5d49ff3 into cb1c6b0
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 4, 2019
2 parents cb1c6b0 + 5d49ff3 commit 95278b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
16 changes: 9 additions & 7 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
const errors = [];
const missingMessages = [];
spec.forEach(arg => {
let newFiles;
try {
newFiles = utils.lookupFiles(arg, extension, recursive);
} catch (err) {
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
errors.push(err.message);
missingMessages.push(err.message);
return;
}

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

if (!files.length) {
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`Error: ${message}`));
});
if (missingMessages.length === 1) {
// give full message details when only 1 file is missing
console.error(ansi.red(`Error: ${missingMessages[0]}`));
} else {
console.error(ansi.red('Error: No test files found'));
}
process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
missingMessages.forEach(message => {
console.warn(ansi.yellow(`Warning: ${message}`));
});
}
Expand Down
26 changes: 23 additions & 3 deletions test/integration/glob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'Error: Cannot find any files matching pattern "./*-none.js"'
'Error: Cannot find any files matching pattern'
);
},
done
);
});

it('should handle multiple non-matching patterns', function(done) {
testGlob.shouldFail(
'./*-none.js ./*-none-twice.js',
function(results) {
expect(results.stderr, 'to contain', 'Error: No test files found');
},
done
);
});

it('should handle both matching and non-matching patterns in the same command', function(done) {
testGlob.shouldSucceed(
'./*.js ./*-none.js',
Expand Down Expand Up @@ -77,13 +87,23 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'Error: Cannot find any files matching pattern "./*-none.js"'
'Error: Cannot find any files matching pattern'
);
},
done
);
});

it('should handle multiple non-matching patterns', function(done) {
testGlob.shouldFail(
'"./*-none.js" "./*-none-twice.js"',
function(results) {
expect(results.stderr, 'to contain', 'Error: No test files found');
},
done
);
});

it('should handle both matching and non-matching patterns in the same command', function(done) {
testGlob.shouldSucceed(
'"./*.js" "./*-none.js"',
Expand Down Expand Up @@ -125,7 +145,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'Error: Cannot find any files matching pattern "./**/*-none.js"'
'Error: Cannot find any files matching pattern'
);
},
done
Expand Down

0 comments on commit 95278b7

Please sign in to comment.