JEST_WORKER_ID is returning "1" from the 2nd run onwards.
Worked up to version: I don't know
Stopped working in version: 23.2.0
Steps to reproduce the behavior:
git clone [email protected]:guyellis/jest-worker-id-one.git
cd jest-worker-id-one
npm i
jest
# Note that output is as expected
jest
# Note that output is not as expected
jest --clearCache
jest
# Output is as expected again
jest
# Out put is wrong again
--clearCache) PASS test/one.test.js
● Console
console.log test/one.test.js:3
process.env.JEST_WORKER_ID 2
PASS test/two.test.js
● Console
console.log test/two.test.js:3
process.env.JEST_WORKER_ID 1
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.034s
Ran all test suites.
JEST_WORKER_ID is always 1 PASS test/two.test.js
● Console
console.log test/two.test.js:3
process.env.JEST_WORKER_ID 1
PASS test/one.test.js
● Console
console.log test/one.test.js:3
process.env.JEST_WORKER_ID 1
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 0.745s, estimated 1s
Ran all test suites.
JEST_WORKER_ID should increment with each test suite.
https://github.com/guyellis/jest-worker-id-one
npx envinfo --preset jestPaste the results here:
$ npx envinfo --preset jest
npx: installed 1 in 0.977s
System:
OS: Linux 4.15 Ubuntu 16.04.4 LTS (Xenial Xerus)
CPU: x64 Intel(R) Core(TM) i7-6850K CPU @ 3.60GHz
Binaries:
Node: 8.9.3 - ~/.nvm/versions/node/v8.9.3/bin/node
npm: 5.5.1 - ~/.nvm/versions/node/v8.9.3/bin/npm
npmPackages:
jest: 23.2.0 => 23.2.0
@guyellis I'm not sure that this is a bug in Jest.
The following code is used to decide whether Jest should runInBand:
In your example, you have 2 tests, on the second run they are faster than the SLOWER_TEST_TIME so Jest uses only one worker.
Thanks for pointing me at this @ranyitz
I'm wondering if we need to either rename JEST_WORKER_ID or create a new incrementing identifier that increments per test suite?
The current behavior might be a bug inasmuch as you'd expect something like JEST_WORKER_ID to increment on a consistent basis from one execution to another. In this example it will increment on the first run before SLOW_TEST_TIME has a value and in all subsequent runs it will not. Technically it is accurate, as you say, because it's only incrementing per worker. The fact that the second execution only has one worker makes the external functionality of this change from the first run to the next.
Closing as it's working as expected, but please keep the discussion going!
Thank @thymikee - I've rechecked all my use cases and it turns out that they are covered by this functionality.
Most helpful comment
Thank @thymikee - I've rechecked all my use cases and it turns out that they are covered by this functionality.