JSDOM virtualConsole environment option defunct in parallel mode
See original GitHub issueš Bug Report
Overriding virtual console for jsdom isnāt possible for parallel execution.
To Reproduce
(Repl.it link further down.)
In any project using jest with at least two test files using jsdom, override the virtual console setting:
In jest.config.js:
...
testEnvironment: "jsdom",
testEnvironmentOptions: {
virtualConsole: new require('jsdom').VirtualConsole()
}
...
Then run:
- jest
Expected behavior
The tests run as they should.
Actual behavior
The tests die with an error from JSDOM:
TypeError: options.virtualConsole must be a VirtualConsole (from createVirtualConsole)
(createVirtualConsole is a bug in JSDOM - it should say VirtualConsole AFAIK.)
This looks like a bug in the way Jest fans out test to workers, because if you runs sequentially, it works. To demonstrate this, try:
- jest --runInBand
Link to repl or repo (highly encouraged)
https://repl.it/@mzedeler/Reproducing-virtualConsole-option-bug
Change first line in index.js to switch between passing and failing case.
Issues without a reproduction link are likely to stall.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
Binaries:
Node: 12.0.0 - ~/.nvm/versions/node/v12.0.0/bin/node
Yarn: 1.15.2 - ~/.nvm/versions/node/v12.0.0/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v12.0.0/bin/npm
npmPackages:
jest: 24 => 24.7.1
This is relate to https://github.com/facebook/jest/issues/5223.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)

Top Related StackOverflow Question
The bug here is that it works in
run-in-band, btw, so I donāt think youād like the fix š The way parallelized tests work is by running separate processes for them. The only way to communicate between processes is to pass serializable messages (in essence, we doJSON.stringify). This is done onconfig, so when you donew VirtualConsole, thatās not gonna be sent across, leading to the error youāre seeing in JSDOM. Additionally, as probably noted, when you donewsomething in the config, that instance is shared across all tests, which you probably donāt want.Iāll close this as the solution to your issue is to create a custom environment or just stub out
consoleas you noted. Weāll address config silently dropping fields as part of #7185See above - the solution in this case is a custom env - we currently do not support non-serializable things (like functions) in the config
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.