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 glob pattern support: no comma splitting for 'spec' and 'ignore' options #4315

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

juergba
Copy link
Contributor

@juergba juergba commented Jun 6, 2020

Description

Currently we can pass test files via CLI:

  • node mocha test1 test2
  • node mocha -- test1 test2
  • node mocha --spec test1 --spec test2
  • node mocha --spec test1,test2

via configuration files:

  • spec: ['test1', 'test2']
  • spec: ['test1,test2']

The last option (comma-delimited list) is neither documented nor provided in our Yargs configuration. But it does break Mocha's glob pattern support in certain cases, e.g.
{controllers,test}/**/*.test.js ==> ['{controllers', 'test}/**/*.test.js']

Description of the Change

For options spec and ignore:

  • yars-parser: we remove splitting by comma
  • yargs: no changes necessary

Applicable issues

closes #4307

@juergba juergba self-assigned this Jun 6, 2020
@juergba juergba added type: bug a defect, confirmed by a maintainer area: node.js command-line-or-Node.js-specific labels Jun 6, 2020
@juergba juergba added this to the next milestone Jun 6, 2020
@juergba juergba added the semver-patch implementation requires increase of "patch" version number; "bug fixes" label Jun 6, 2020
@juergba juergba requested a review from a team June 6, 2020 07:34
* This is passed as the `coerce` option to `yargs-parser`
* @private
* @ignore
*/
const globOptions = ['spec', 'ignore'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, is exclude option alias'd into ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but vice versa. ignore is the canonical and exclude the alias option name. Yargs-parser applies the coerce function automatically to both names.

@craigtaub
Copy link
Contributor

craigtaub commented Jun 8, 2020

So as I understand comma-delimited spec: ["test/one/index.spec.js,test/two/index.spec.js"] would work in master but not on the fix (tried locally to confirm).
In which case should this be a breaking change? Regardless of not documenting the feature if we make a fix which breaks a certain existing setup, that sounds like a major.

@juergba
Copy link
Contributor Author

juergba commented Jun 8, 2020

So as I understand comma-delimited spec: ["test/one/index.spec.js,test/two/index.spec.js"] would work in master but not on the fix [...]

Yes, that's correct. I'm fine with major.

@juergba juergba added semver-major implementation requires increase of "major" version number; "breaking changes" and removed semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Jun 8, 2020
@craigtaub
Copy link
Contributor

craigtaub commented Jun 8, 2020

Fix looks good, but we only have 1 line of docs on this option and its usage (from what I can see in the Positional Arguments bit). Should we expand on it to add clarity now? Should it have a --spec section?
With introducing a breaking change imagine it could be useful to be able to point people to an explanation. Thoughts?

@juergba
Copy link
Contributor Author

juergba commented Jun 8, 2020

There is another docs section.
It's somehow confusing to have a positional argument spec and an option --spec. There is no need to use --spec in the CLI, actually it's only needed for the configuration files.
I'm not sure how to document that, I will think about.

Copy link
Contributor

@craigtaub craigtaub left a comment

Choose a reason for hiding this comment

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

Nice one

it's only needed for the configuration files

Yes I could not think where else to put it either. Happy to leave.

@boneskull
Copy link
Contributor

To be clear: this removes the ability to specify files such as foo.js,bar.js, but fixes {foo,bar}.js?

@juergba
Copy link
Contributor Author

juergba commented Jun 9, 2020

Yes, this is correct for spec and ignore:

  • CLI: node mocha --spec foo.js,bar.js
  • configuration file: spec: ['foo.js,bar.js']

see also comment.

The following has never worked and remains unchanged:

  • CLI: node mocha foo.js,bar.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific semver-major implementation requires increase of "major" version number; "breaking changes" type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrating from mocha.opts to mocharc broke glob pattern support
3 participants