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

Feature request: MOCHA_GREP environment variable (alternative to --grep) #4232

Closed
jedwards1211 opened this issue Apr 21, 2020 · 4 comments
Closed
Labels
type: feature enhancement proposal

Comments

@jedwards1211
Copy link

jedwards1211 commented Apr 21, 2020

Is your feature request related to a problem or a nice-to-have?? Please describe.
I've been working with sequelize lately and it's awkward to grep for tests in their repo. Here are some of their package scripts:

    "test-docker": "npm run test-docker-unit && npm run test-docker-integration",
    "test-docker-unit": "npm run test-unit",
    "test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration",
    "test-integration": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --exit --check-leaks --colors -t 30000 --reporter spec \"test/integration/**/*.test.js\"",
    "test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration",

Grepping for tests is a hassle because

  • I have to use a variable number of --, like npm run test-docker-integration -- -- --grep foo, depending on the script, to pass --grep to the actual mocha command. yarn doesn't have this problem if you use yarn instead of npm run in the package scripts, but I don't control that.
  • npm run test-docker -- -- --grep foo would only apply the --grep to the test-docker-integration script, not to the test-docker-unit script.

Describe the solution you'd like
If I could just do MOCHA_GREP=foo npm run test-docker it would be a lot easier.

Describe alternatives you've considered
I'm planning to PR some additional scripts to their repo for grepping tests, but I'm sure sequelize isn't the only repo that makes grepping difficult like this, so I'd rather have a quick and easy way to do it for future projects I may work on.

@jedwards1211 jedwards1211 added the type: feature enhancement proposal label Apr 21, 2020
@outsideris
Copy link
Contributor

Couldn't you use configuration files?

@jedwards1211
Copy link
Author

jedwards1211 commented May 1, 2020

I guess that's true...it would be a bit more of a hassle to change the grep and avoid committing the file to the repo than if I could just use an environment variable though

@outsideris
Copy link
Contributor

I don't agree to add MOCHA_GREP. Because if we support mocha flags with environment variable, we should support all flags with environment variable rather than only --grep.
It makes hard to maintain mocha's flags.

@boneskull
Copy link
Contributor

yargs has a feature that supports setting options via an environment variable; we should probably take advantage of that at some point. Might even be an issue for it already.

A workaround:

// .mocharc.js
module.exports = {
  grep: process.env.MOCHA_GREP
}

Will close this in lieu of an issue that supports more widely consuming env vars.

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

No branches or pull requests

3 participants