faq labelnode node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you _not_ install Mocha globally.Running unit tests with "mocha": "6.1.4", on my repository along with Node v12.0.0 results in error process.removeListener is not a function
This error does not occur with Node v10.15.1
I suspect the error will occur any time you run unit tests with _mocha_ along with Node 12, but here's a way:
1) Clone my repository:
git clone https://github.com/whyboris/karma-helpful-reporter.git
2) Install Node v12.0.0 (I'm using nvm to switch back between versions easily)
3) Then npm run test and see the error.
Note that the error does not occur on Node v10.
Expected behavior: [What you expect to happen]
No error with Node 12
Actual behavior: [What actually happens]
process.removeListener('uncaughtException', uncaught);
^
TypeError: process.removeListener is not a function
Reproduces how often: [What percentage of the time does it reproduce?]
Every time
"mocha": "6.1.4",
Node v12.0.0
mocha --version and node node_modules/.bin/mocha --version: 6.1.4node --version: v12.0.0Full log:
1) "after each" hook
/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917
process.removeListener('uncaughtException', uncaught);
^
TypeError: process.removeListener is not a function
at Runner.<anonymous> (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917:13)
at Runner.emit (events.js:196:13)
at /Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:903:12
at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:728:16)
at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at Runner.hookErr (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:575:7)
at Runner.uncaught (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:857:19)
at process.uncaught (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:887:10)
at process.emit (events.js:196:13)
at process._fatalException (internal/process/execution.js:146:25)
Node documentation for removeListener:
https://nodejs.org/api/events.html#events_event_removelistener
[edit] - documentation should be here, thank you @plroebuck :
https://nodejs.org/api/events.html#events_emitter_removelistener_eventname_listener
Node documentation link should be to this.
Does this occur with the built-in reporters, or just your custom one?
Thank you @plroebuck for the documentation link and the follow up question.
I suspect the problem will happen with any project that uses _Mocha_ and attempts to run it with Node 12. My reporter does not have any dependencies, just _devDependencies_:
https://github.com/whyboris/karma-helpful-reporter/blob/karma-helpful-reporter/package.json#L13
The error occurs not when running my reporter in another project, but trying to run unit tests I've written using _Mocha_. The error occurs after all 105 of my unit test successfully run and pass.
馃し鈥嶁檪 sorry I'm not very knowledgeable about all this 馃槄
@whyboris is this still a pending issue?
Yes:

I even tried updating my repository to use "mocha": "6.2.0" 馃し鈥嶁檪
Have you updated your Node version? Which version do you use now?
I'm on _Node_ 12.6.0 and the above screenshot is what I see.
I'm also seeing exactly the same issue with mocha tests in node 12.12.0 and the screenshot above is what I also see.
I just tried to recreate this without success:
$ mocha --version
6.2.2
$ node -v
v12.13.0
Mocha's unit tests are also all run on node 12: https://travis-ci.org/mochajs/mocha/builds/606685504
It doesn't seem to be a problem with the base package, or any of the built-in reporters that are currently being tested.
I can recreate the error by cloning [email protected]:whyboris/karma-helpful-reporter, creating a clean install on node 12.13.0 and running the test suite:
$ npm t
> [email protected] test /Users/pbm/git/karma-helpful-reporter
> nyc mocha
[REMOVED SUCCESSFUL TESTS OUTPUT]
105 passing (1s)
1) "after each" hook
/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917
process.removeListener('uncaughtException', uncaught);
^
TypeError: process.removeListener is not a function
at Runner.<anonymous> (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917:13)
at Runner.emit (events.js:210:5)
at /Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:903:12
at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:728:16)
at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
at Runner.hookErr (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:575:7)
at Runner.uncaught (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:857:19)
at process.uncaught (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:887:10)
at process.emit (events.js:210:5)
at processEmit [as emit] (/Users/pbm/git/karma-helpful-reporter/node_modules/signal-exit/index.js:155:32)
at process._fatalException (internal/process/execution.js:150:25)
Since we test on node 12 it seems that this code path must be untested. First order of business would be to recreate the bug in a test in a Pull-request we can the iterate on to fix it
I haven't understood what happens exactly. I just have some remarks:
process is a global object created by Node and is an instance of EventEmitter. Every EventEmitter should know the removeListener function. So the error TypeError: process.removeListener is not a function is very strange.process object is overridden somewhere.process is manipulated.I'm not very experienced in mocking, but I'm shyly passing the ball back to you.
My diagnosis so far: process has been mocked and not reverted to its original state.
@rgroothuijsen thank you for your confirmation. 馃憤
@whyboris can I close this issue?
I had this issue with version 6.1.4 -- my tests would generate this error:
1) "after each" hook
/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917
process.removeListener('uncaughtException', uncaught);
^
I updated to 7.1.1 -- now the error is just
1) "after each" hook in "util/shell.js test suite"
It's not clear what the error is, but at least it points to a file in my repository, rather than to _mocha_
Please feel free to close the issue if you think you've resolved it 馃憣
I suspect it is fixed, but can't be sure 馃し鈥嶁檪
Cheers 馃檪
@whyboris I'm closing this issue.
I think it's your turn now to improve your testing code. Mocha needs the uncaught error handler to process uncaught exception. Overwriting the process object is a severe error in your code. It's your turn.
Most helpful comment
I can recreate the error by cloning
[email protected]:whyboris/karma-helpful-reporter, creating a clean install on node 12.13.0 and running the test suite: