-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 message if no files found #3650
Changes from all commits
db722d0
96c3b15
c4651cb
54bfedd
964f363
afc429e
475d81c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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}`)); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have simply said: console.error(ansi.red('Error: No test files found')); Nothing is gained by outputting multiple error messages, and now we have both warnings and errors with the same message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't show at the same time though (warnings and errors). I mentioned in my comment earlier I felt giving multiple error messages was helpful in those scenarios (in that I found it useful myself). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused about when we are going to show errors vs warnings... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't the name of the issue "too much noise if no files found"? Retry one of your tests with lots of nonexistent globs... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just didn't want to see a warning about it (which duplicated the filenames) and then another error. If that's fixed, then great There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the description I tried to give full details on what shows when. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already understand what would be displayed when. Disagreed about what should show for the error case (nothing matched) -- an " |
||
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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test pattern should not be part of check for maintainability. WET due to filename. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this change request ignored? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't on purpose, I thought there was nothing outstanding so I merged it. |
||
); | ||
}, | ||
done | ||
|
@@ -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 | ||
|
@@ -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"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test pattern (filename) should not be part of check for maintainability. |
||
); | ||
}, | ||
done | ||
|
@@ -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 | ||
|
@@ -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"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test pattern (filename) should not be part of check for maintainability. |
||
); | ||
}, | ||
done | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specific about what you're storing since you're not storing the
Error
instance that was thrown.