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

Report non-match to STDERR and exit if no files are matched #2450

Merged
merged 2 commits into from Sep 18, 2016

Conversation

Munter
Copy link
Member

@Munter Munter commented Aug 21, 2016

This displays a warning on STDERR for each glob pattern that is passed in as a binary execution argument if the glob pattern results in no files matched.

If no files are matched across all the passed glob patterns it exits with error code 1

This allows for running tests for any glob pattern that correctly matches files, while still making the user aware of their other invalid glob patterns. Previously we would throw if any pattern did not match any files and the error message was not the best one to figure out the problem.

Fixes #2194

if (err.message.indexOf('cannot resolve path') === 0) {
console.error('Warning: Could not find any test files matching pattern: ' + arg);
return;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

This else is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't it good practice to re-throw any other error that might not be this specific one? Otherwise it will just be swallowed

Copy link
Member Author

Choose a reason for hiding this comment

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

.. And now I get it. Was a bit distracted. Fixed

});

if (files.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

prefer if (!files.length)

Copy link
Member

Choose a reason for hiding this comment

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

(not required)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

});

if (files.length === 0) {
process.exit(1);
Copy link
Member

Choose a reason for hiding this comment

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

Should probably add an error message here about no files being found, given you can simply execute mocha in a directory with empty subdir test, and this is the current output:

$ mocha


  0 passing (3ms)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@Munter
Copy link
Member Author

Munter commented Sep 17, 2016

@boneskull Changes implemented, branch rebased and all tests are passing

@boneskull boneskull merged commit 1786fe2 into master Sep 18, 2016
@boneskull boneskull deleted the fix-issue-2194 branch September 18, 2016 22:06
@boneskull
Copy link
Member

Thanks @Munter

1999 pushed a commit to 1999/mocha that referenced this pull request Sep 19, 2016
…roperty-currentretry

* upstream/master:
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
1999 pushed a commit to 1999/mocha that referenced this pull request Sep 22, 2016
…-files-cache

* upstream/master:
  attempt windows-friendly reproducible case for mochajs#2315
  fix: fix uncaught TypeError if error occurs on next tick, closes mochajs#2315 (mochajs#2439)
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
sgilroy pushed a commit to TwineHealth/mocha that referenced this pull request Feb 27, 2019
…2450)

* Report non-matching patterns to STDERR and exit with non-zero status if no files are matched at all. Fixes mochajs#2194

* Code review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature enhancement proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants