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 message if no files found #3650

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
let errors = [];
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
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 +165,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(`${symbols.error} ${message}`));
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
});
Copy link
Contributor

@plroebuck plroebuck Jan 4, 2019

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@craigtaub craigtaub Jan 4, 2019

Choose a reason for hiding this comment

The 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).

Copy link
Contributor

Choose a reason for hiding this comment

The 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...

Copy link
Contributor

@plroebuck plroebuck Jan 4, 2019

Choose a reason for hiding this comment

The 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...

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

@craigtaub craigtaub Jan 4, 2019

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@plroebuck plroebuck Jan 5, 2019

Choose a reason for hiding this comment

The 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 "n not found" scenario with this code outputs n error messages instead of one. Worse, it uses the exact same message text as the warning case.

process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
console.warn(`Warning: ${message}`);
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
});
}

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"'
'✖ Cannot find any files matching pattern "./*-none.js"'
Copy link
Contributor

Choose a reason for hiding this comment

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

can you pull in the symbol from log-symbols? this may fail on windows

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just leave it and the pattern out...

             'Cannot find any files matching pattern'

Copy link
Contributor Author

@craigtaub craigtaub Jan 3, 2019

Choose a reason for hiding this comment

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

I like idea including symbol as could erroneously fall into warning block if just pattern matching the message.

Copy link
Contributor

@plroebuck plroebuck Jan 3, 2019

Choose a reason for hiding this comment

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

Continuing with that thought, confusing to use the same message as both error and warning.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I actually think listing the errors is better, from the users perspective it's more helpful and easier to see the mistake that way. I've used it myself during his pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

So if user gives 20 globs and none exist, one message per is somehow more informative than just saying "none found"? I disagree.
For warnings, fine -- but not when none exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

As @craigtaub stated, it was useful information, so if some subset of the paths are not found, it seems reasonable to list them (but not if all of them are not found).

FWIW, a user can avoid this problem altogether by using shell expansion, but that's not portable.

Copy link
Contributor

@plroebuck plroebuck Jan 4, 2019

Choose a reason for hiding this comment

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

If a subset don't exist, those would be warnings -- stated I had no problem with that.
Just the files.length === 0 error case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok i think its clear you both feel the single error message is better than multiple error messages. For debugging purposes I found the multiple one better, the initial idea of using an error was to indicate nothing did run, but perhaps its not clear enough.

);
},
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'
'✖ Cannot find any files matching pattern "./*-none.js"'
Copy link
Contributor

Choose a reason for hiding this comment

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

same

);
},
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'
'✖ Cannot find any files matching pattern "./**/*-none.js"'
Copy link
Contributor

Choose a reason for hiding this comment

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

same

);
},
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