use rootDir instead of cwd for globalConfig location #389
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using
cwd
to determine the location to put the globalConfig.json causes a conflict between parallel test runs in a monorepo when Jest is invoked from the root of the repository and has a particularjest.config
file specified.This is how tools like Nx invoke tests. Commands are run from the root of the repo and if I do something like
nx run-many --target=test --projects=project1,project2
this results in two separatejest
commands being executed at the same time. Each command has the samecwd
value (the repository root) but is pointed at a differentjest.config
file which specified which test files to run. This causes the runs to conflict, because when one of them finishes it will delete the globalConfig.json file which the other one then attempts to read for any test files it has left to execute.Instead, switch to using the
rootDir
property of the jest environment config, which defaults to the location of thejest.config
file currently in use for this test run.https://jestjs.io/docs/configuration#rootdir-string