Mocha: flag to fail if .only() present.

Created on 4 Feb 2014  路  4Comments  路  Source: mochajs/mocha

It would be nice to have a flag to fail the test run if a .only() has been left the suite.

Really need this for CI to people don't forget to remove their .only()s.

Because of the way it's implemented maybe a --no-grep flag would make sense.

Most helpful comment

Version 3.5.0 recently introduced the --forbid-only flag, actually. Output isn't good yet (it prints nothing to indicate the issue, until we do something like #2874), but it'll fail CI.

All 4 comments

in your ci, add a step that greps for onlys before your tests run. this doesn't need to be in mocha.

Yes, but a grep would have to be implemented by everyone. It'd be nice to have this out-of-the-box. It's something I regularly struggle against because sometimes the joy of getting a it.only test to pass is so great that I forget to remove the .only before pushing to a pull request and merging. We need this in our lives.... please. :)

FYI for future visitors, here's the grep command that I've used that works for me:

grep -rq --include '*.spec.js' it.only . && echo 'You have it.only() in your tests!' && exit 1

Version 3.5.0 recently introduced the --forbid-only flag, actually. Output isn't good yet (it prints nothing to indicate the issue, until we do something like #2874), but it'll fail CI.

Was this page helpful?
0 / 5 - 0 ratings