Closed whyboris closed 4 years ago
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 git@github.com:whyboris/karma-helpful-reporter
, creating a clean install on node 12.13.0 and running the test suite:
$ npm t
> karma-helpful-reporter@0.3.4 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.
I recently encountered this error when upgrading Node through v12, and in case anyone else is having trouble with it...
It may relate to the change in v12 of making global.process non-enumerable, so some mocking/injection frameworks when asked to stub process
in a module accidentally overwrite the real thing. This will be missing any method not needed for the test, hence the error.
In my case the framework was rewire
, and the underlying bug can be found here, where I have suggested a workaround.
If that doesn't apply in your case, then the following may at least ease the symptoms if not address the root cause:
// global-process-hook.js
const oldProcess = process;
afterEach(() => {
if (process !== oldProcess) {
console.error('GLOBAL PROCESS CLOBBERED');
process = oldProcess;
}
});
Adding global-process-hook.js
to the mocha
command-line before the actual test folders allowed me to narrow down the tests that were causing the problem.
@john-perks thank you.
This issue and its reproduction repository are requiring rewire
as well.
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Running unit tests with
"mocha": "6.1.4",
on my repository along withNode v12.0.0
results in errorprocess.removeListener is not a function
This error does not occur with
Node v10.15.1
Steps to Reproduce
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]
Reproduces how often: [What percentage of the time does it reproduce?] Every time
Versions
"mocha": "6.1.4", Node v12.0.0
mocha --version
andnode node_modules/.bin/mocha --version
:6.1.4
node --version
:v12.0.0
Additional Information
Full log:
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