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

Assign process.env.JEST_RUN_IN_BAND value to check if testing is running serially. #9280

Closed
wants to merge 3 commits into from

Conversation

WeiAnAn
Copy link
Contributor

@WeiAnAn WeiAnAn commented Dec 7, 2019

Summary

Issue #9231.

I think use process.env.JEST_RUN_IN_BAND can solve this issue, and easier.

Test plan

Update TestScheduler tests, checking process.env.JEST_RUN_IN_BAND value.

@jeysal
Copy link
Contributor

jeysal commented Dec 8, 2019

I'm wondering if we should just define JEST_WORKER_ID as 0 when running in band (it is 1-indexed in actual workers) to signal this (and documenting it)?
I feel like there was a discussion on this earlier this year but I can't find it. @thymikee @SimenB can you think of downsides to doing that instead?

@WeiAnAn
Copy link
Contributor Author

WeiAnAn commented Dec 8, 2019

@jeysal, it seems discuss in pr #5860.

@jeysal
Copy link
Contributor

jeysal commented Dec 8, 2019

Thanks, awesome that you found it! I think casting the env variable string=>number=>boolean for a conditional as mentioned there is unlikely to happen and even if, it actually makes sense to me that the worker id is falsy if not running in a worker. So I'm in favor of changing JEST_WORKER_ID to 0 in the main process to signalize this.

@WeiAnAn
Copy link
Contributor Author

WeiAnAn commented Dec 9, 2019

I think if use JEST_WORKER_ID=0 to stand for running serially, it will cause a little confuse in code.

if (process.env.JEST_WORKER_ID == 0)
  // do something

It is hard to know what it mean in first time.

@SimenB
Copy link
Member

SimenB commented Dec 9, 2019

All env variables are strings, so "0" wouldn't be falsy.


I still don't think this is the correct solution to the problem, and making tests behave differently depending on them running in band or not feels like an anti pattern

@WeiAnAn
Copy link
Contributor Author

WeiAnAn commented Dec 9, 2019

Or only set JEST_RUN_IN_BAND when running in band.
It would be undefined in multiple worker, and it is falsy.

@johncmunson
Copy link

johncmunson commented Dec 9, 2019

making tests behave differently depending on them running in band or not feels like an anti pattern

@SimenB completely agree... this is most certainly an anti-pattern. However, this is javascript and sometimes other people's anti-patterns force you into writing an anti-pattern yourself just to compensate. It would be nice to have this escape hatch

@WeiAnAn WeiAnAn closed this Mar 24, 2021
@github-actions
Copy link

This pull request 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 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants