Mocha: Certain mocha command line options not working

Created on 6 Jul 2015  路  15Comments  路  Source: mochajs/mocha

I'm baffled by this. I have mocha 2.2.5 installed globally

Running:

mocha --bail

give the error:

  error: unknown option `--bail'

Other options work fine like

mocha -V
mocha --help
mocha --trace

Then some other options give the same error as --bail

mocha --watch
 error: unknown option `--watch'

mocha --no-timeouts
error: known option `--no-timeouts`

Any clue what could be causing this? I'm using Node v0.12.6

needs-feedback question

Most helpful comment

Actually, I think I found the issue. I was using the commander package to add CLI functionality. Removing the package (and the commander specific code) seems to have fixed the problem. I'll whip up a test case and file another issue.

Edit: In my case, it seems like the issue is arising because I'm using the rewire module to include unexported functions from the script that invokes commander. Moving those functions to a utility functions file and then testing that should fix the issue I was seeing.

All 15 comments

@sarus what's the output of which mocha and mocha --version?

@jbnicolai Please let me know if there is any other information that might help figure this out. I'm using a globally installed version of mocha.

which mocha
/opt/node/bin/mocha

mocha --version
2.2.5

Not sure if this stackoverflow question is related:

http://stackoverflow.com/questions/19384003/exporting-the-same-object-that-is-required-confuses-mocha

Different option and it seems like the option they were trying to use had a syntax difference (required the = sign) whereas --bail shouldn't require anything.

@sarus what are the contents of /opt/node/lib/node_modules/mocha/node_modules? My best guess at that path... I'm looking for the contents of Mocha's node_modules folder.

@sarus (does npm remove -g mocha then npm install -g mocha --force help?)

Contents of /opt/node/lib/node_modules/mocha/node_modules

commander  debug  diff  escape-string-regexp  glob  growl  jade  mkdirp  supports-color

Dong npm remove -g mocha and then npm install -g mocha --force did not help. I just noticed that mocha does work in other projects on the same machine.

so I have

/home/sarus/project1 <-- inside this project mocha --bail is broken
/home/sarus/project2 <-- inside this project mocha works fine
/home/sarus/project3 <-- inside this project mocha works fine

In all three projects which mocha points to the same /opt/node/bin/mocha

@sarus do you have mocha installed as a dev dependency of each of those projects?

Yes, mocha is installed as a dev dependency on all of them with the same version.

    "devDependencies": {
        "mocha": "~2.2"
    }

I'm running into this issue as well. It looks like --bail, --watch, --no-timeouts, and --reporter are all giving error: unknown option. Running mocha in my project works just fine, however. I'm using mocha 2.2.5 on node 0.12.7. The --reporter option worked for me last night, and the only things I've changed since then have been adding a few more tests.

Actually, I think I found the issue. I was using the commander package to add CLI functionality. Removing the package (and the commander specific code) seems to have fixed the problem. I'll whip up a test case and file another issue.

Edit: In my case, it seems like the issue is arising because I'm using the rewire module to include unexported functions from the script that invokes commander. Moving those functions to a utility functions file and then testing that should fix the issue I was seeing.

I confirm that I have the same problem and that when I remove the commander module no more error: unknown option problems. I'm not using the rewire module though.

Thanks @dstaley for the investigation!

This appears solved.

I just got this issue, but this time with the simple mocking module.

Same problem today when run mocha locally installed in devDependencies

node 8.1.4
npm 5.3.0
mocha 3.4.2

$ node_modules/mocha/bin/mocha --bail tests/
error error: unknown option '--bail'

or in package.json scripts
"test": "mocha --bail tests/
$ npm run test
error error: unknown option '--bail'

global installed it is ok
$ mocha --bail tests/

Hi, @rottmann, sorry for the late reply -- can you try removing the global Mocha and double-check that the version of the local Mocha is 3.4.2 or 3.5.0?

Solved for me: the error was not from mocha, it was a wrong check of args in my test (something changed in commander) that produced the error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevemao picture stevemao  路  46Comments

sagiegurari picture sagiegurari  路  61Comments

quangv picture quangv  路  38Comments

enobufs picture enobufs  路  38Comments

jbnicolai picture jbnicolai  路  37Comments