Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JEST_WORKER_ID is returning "1" from the 2nd run onwards #6608

Closed
guyellis opened this issue Jul 4, 2018 · 5 comments
Closed

JEST_WORKER_ID is returning "1" from the 2nd run onwards #6608

guyellis opened this issue Jul 4, 2018 · 5 comments

Comments

@guyellis
Copy link

guyellis commented Jul 4, 2018

💥 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 
@ranyitz
Copy link
Contributor

ranyitz commented Jul 4, 2018

@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.

@guyellis
Copy link
Author

guyellis commented Jul 4, 2018

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.

@thymikee
Copy link
Collaborator

thymikee commented Jul 5, 2018

Closing as it's working as expected, but please keep the discussion going!

@thymikee thymikee closed this as completed Jul 5, 2018
@guyellis
Copy link
Author

guyellis commented Jul 5, 2018

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

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants