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

Fix messages for file lookup issues - error scenario #3654

Merged
merged 6 commits into from Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/cli/run-helpers.js
Expand Up @@ -137,14 +137,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
const errors = [];
const unmatched = [];
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);
unmatched.push({message: err.message, pattern: err.pattern});
return;
}

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

if (!files.length) {
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`Error: ${message}`));
});
// give full message details when only 1 file is missing
const noneFoundMsg =
unmatched.length === 1
? `Error: No test files found: ${unmatched[0].pattern}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Double-quote pattern? Or clear enough as is? Your call.

Copy link
Contributor

Choose a reason for hiding this comment

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

How is a pattern containing escaped characters displayed? Raw?

Copy link
Contributor Author

@craigtaub craigtaub Jan 8, 2019

Choose a reason for hiding this comment

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

Hmm no they arent. I will JSON.stringify so it prints raw. Let me know if you think of a better way to handle it (or any other thoughts).

: 'Error: No test files found';
console.error(ansi.red(noneFoundMsg));
process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
console.warn(ansi.yellow(`Warning: ${message}`));
unmatched.forEach(warning => {
console.warn(ansi.yellow(`Warning: ${warning.message}`));
});
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
26 changes: 23 additions & 3 deletions test/integration/glob.spec.js
Expand Up @@ -28,13 +28,23 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'Error: Cannot find any files matching pattern "./*-none.js"'
'Error: No test files found: ./*-none.js'
);
},
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');
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
},
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: No test files found: ./*-none.js'
);
},
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: No test files found: ./**/*-none.js'
);
},
done
Expand Down