stryker-js
stryker-js copied to clipboard
Jest: JEST_WORKER_ID is always 1 even in concurrent mode
Summary
Jest uses an environment variable named JEST_WORKER_ID
that is unique for each worker. This can be used to avoid collisions when using external resources, e.g. file system or external database. However, when using the Stryker Jest Runner, this environment variable is always 1, regardless of the concurrency setting, which potentially breaks any tests relying on it.
Stryker config
{
"packageManager": "yarn",
"reporters": ["html", "clear-text", "progress"],
"testRunner": "jest",
"coverageAnalysis": "perTest"
}
Stryker environment
+-- @stryker-mutator/[email protected]
+-- @stryker-mutator/[email protected]
+-- [email protected]
+-- [email protected]
jest.config.json:
{
"preset": "ts-jest",
"testEnvironment": "node"
}
Hmm interesting. I don't think we can influence the value of JEST_WORKER_ID
inside the testing environment. It is simply always 1
, because a runner isn't aware of other runners. Would using process.env.STRYKER_MUTATOR_WORKER ?? process.env.JEST_WORKER_ID
be an option for you?
See also https://stryker-mutator.io/docs/stryker-js/parallel-workers/
Thanks for the answer, I was not aware of STRYKER_MUTATOR_WORKER
but that does solve the issue (it only requires a small update to the test suite). If it's really the case that you have no control over JEST_WORKER_ID
, feel free to close this as "not planned".