Jest: JEST_WORKER_ID is returning "1" from the 2nd run onwards

Created on 4 Jul 2018  ·  4Comments  ·  Source: facebook/jest

💥 Regression Report

JEST_WORKER_ID is returning "1" from the 2nd run onwards.

Last working version

Worked up to version: I don't know

Stopped working in version: 23.2.0

To Reproduce

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

Output as Expected on 1st run (equivalent to running after a --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.

Output On 2nd run - 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.

Expected behavior

JEST_WORKER_ID should increment with each test suite.

Link to repl or repo (highly encouraged)

https://github.com/guyellis/jest-worker-id-one

Run npx envinfo --preset jest

Paste 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 
Needs Triage

Most helpful comment

Thank @thymikee - I've rechecked all my use cases and it turns out that they are covered by this functionality.

All 4 comments

@guyellis I'm not sure that this is a bug in Jest.

The following code is used to decide whether Jest should runInBand:

https://github.com/facebook/jest/blob/6a77ee37ec2d46ece7e9cfd0f891d11c113cc4c4/packages/jest-cli/src/test_scheduler.js#L88-L96

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.

Was this page helpful?
0 / 5 - 0 ratings