Skip to content

Fix message if no files found - #3650

Merged
craigtaub merged 7 commits into
masterfrom
craigtaub/fixNoisyMessage
Jan 4, 2019
Merged

craigtaub merged 7 commits into
masterfrom
craigtaub/fixNoisyMessage

Conversation

@craigtaub

@craigtaub craigtaub commented Jan 3, 2019 •

Copy link
Copy Markdown
Contributor

Description of the Change

Previously would print a warning for each missing file/dir, then an error if no valid files were found.
Now prints slimmer warnings and errors only if no tests found.
Tests cover both scenarios.

Alternate approach

Print an error for each missing file/dir (and no final error). Still exit if no valid files were found.
Nasty as flags everything as an error even if there is a passing test

Scenarios:

Nothing given

Command: mocha
New output:

Error: Cannot find any files matching pattern "test/"

Previous output:

Warning: cannot find any files matching pattern "test/": 'test/'
✖ No test files found

Difference = No warning and slimmer message

Nothing found

Command: mocha -R json-stream --no-config "test/integration/fixtures/glob/**/*-none.js"
New output:

Error: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js"

Previous output:

Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js": 'test/integration/fixtures/glob/**/*-none.js'
✖ No test files found

Difference = No warning and slimmer message

1 found but 1 not found:

Command: mocha -R json-stream --no-config "test/integration/fixtures/glob/**/*.js" "test/integration/fixtures/glob/**/*-none.js"
New output:

Warning: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js"
["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T19:03:34.591Z","end":"2019-01-03T19:03:34.593Z","duration":2}]

Previous output:

Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js": 'test/integration/fixtures/glob/**/*-none.js'
["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T17:53:56.843Z","end":"2019-01-03T17:53:56.845Z","duration":2}]

Difference = slimmer warning

1 found but 2 not found:

Command: mocha -R json-stream --no-config "test/integration/fixtures/glob/**/*.js" "test/integration/fixtures/glob/**/*-none.js" "test/integration/fixtures/glob/**/*-none-again.js"
New output:

Warning: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js"
Warning: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none-again.js"
["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T19:03:55.208Z","end":"2019-01-03T19:03:55.210Z","duration":2}]

Previous output:

Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js": 'test/integration/fixtures/glob/**/*-none.js'
Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none-again.js": 'test/integration/fixtures/glob/**/*-none-again.js'
["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T17:54:34.393Z","end":"2019-01-03T17:54:34.395Z","duration":2}]

Difference = Simmer warnings

2 not found:

Command: mocha -R json-stream --no-config "test/integration/fixtures/glob/**/*-none.js" "test/integration/fixtures/glob/**/*-none-again.js"
New output:

Error: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js"
Error: Cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none-again.js"

Previous output:

Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none.js": 'test/integration/fixtures/glob/**/*-none.js'
Warning: cannot find any files matching pattern "test/integration/fixtures/glob/**/*-none-again.js": 'test/integration/fixtures/glob/**/*-none-again.js'
✖ No test files found

Difference = Warnings swapped for errors and no extra error.

1 found:

Command: mocha -R json-stream --no-config "test/integration/fixtures/glob/**/*.js"
New output:

["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T17:01:17.934Z","end":"2019-01-03T17:01:17.938Z","duration":4}]

Previous output:

["start",{"total":2}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["pass",{"title":"should find this test","fullTitle":"globbing test should find this test","duration":0,"currentRetry":0}]
["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,"start":"2019-01-03T17:55:06.996Z","end":"2019-01-03T17:55:06.999Z","duration":3}]

Difference = nothing

Applicable issues

Fixes #3646
(semver-patch)

@craigtaub craigtaub added area: reporters involving a specific reporter semver-minor implementation requires increase of "minor" version number; "features" pr-needs-work labels Jan 3, 2019
@coveralls

coveralls commented Jan 3, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 90.739% when pulling 475d81c on craigtaub/fixNoisyMessage into 1f325e7 on master.

@boneskull boneskull left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, no major issues. you can change some stuff I've commented on if you want 👍

Comment thread lib/cli/run-helpers.js Outdated
Comment thread lib/cli/run-helpers.js Outdated
Comment thread test/integration/glob.spec.js Outdated
results.stderr,
'to contain',
'cannot find any files matching pattern "./*-none.js"'
'✖ Cannot find any files matching pattern "./*-none.js"'

Copy link
Copy Markdown
Member

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
Copy Markdown
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'

@craigtaub craigtaub Jan 3, 2019 •

Copy link
Copy Markdown
Contributor Author

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.

@plroebuck plroebuck Jan 3, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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.

@plroebuck plroebuck Jan 4, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread lib/cli/run-helpers.js Outdated
Comment thread test/integration/glob.spec.js Outdated
results.stderr,
'to contain',
'cannot find any files matching pattern'
'✖ Cannot find any files matching pattern "./*-none.js"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

Comment thread test/integration/glob.spec.js Outdated
results.stderr,
'to contain',
'cannot find any files matching pattern'
'✖ Cannot find any files matching pattern "./**/*-none.js"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

@plroebuck plroebuck added area: usability concerning user experience or interface semver-patch implementation requires increase of "patch" version number; "bug fixes" and removed area: reporters involving a specific reporter semver-minor implementation requires increase of "minor" version number; "features" labels Jan 3, 2019
@craigtaub craigtaub added this to the v6.0.0 milestone Jan 4, 2019
@craigtaub
craigtaub merged commit fc0507e into master Jan 4, 2019
@craigtaub
craigtaub deleted the craigtaub/fixNoisyMessage branch January 4, 2019 08:11
Comment thread lib/cli/run-helpers.js
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`Error: ${message}`));
});

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor

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.

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor Author

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

ghost Jan 4, 2019

Copy link
Copy Markdown
Member

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

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor

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

ghost Jan 4, 2019

Copy link
Copy Markdown
Member

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

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor Author

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.

ghost Jan 5, 2019 •

Copy link
Copy Markdown
Contributor

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.

results.stderr,
'to contain',
'cannot find any files matching pattern "./*-none.js"'
'Error: Cannot find any files matching pattern "./*-none.js"'

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ghost Jan 5, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why was this change request ignored?

ghost Jan 5, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
Have made a new PR continuing (referenced) the work, I think it's more practical to converse there.

results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./*-none.js"'

ghost Jan 4, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test pattern (filename) should not be part of check for maintainability.

results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./**/*-none.js"'

ghost Jan 4, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test pattern (filename) should not be part of check for maintainability.

Comment thread lib/cli/run-helpers.js
spec = []
} = {}) => {
let files = [];
const errors = [];

ghost Jan 4, 2019 •

Copy link
Copy Markdown
Contributor

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.

  const messages = [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: usability concerning user experience or interface semver-patch implementation requires increase of "patch" version number; "bug fixes"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

too much noise if no files found

4 participants