-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 config projects
array can't handle only one item
#7496
Comments
I wonder if this is as simple as setting this to Untested, but mind giving it a whirl? It's been that way since the original PR though: https://github.com/facebook/jest/pull/3400/files#diff-8006e39142c24851115752df17e9c1c0R109 @cpojer @rickhanlonii thoughts? |
@SimenB that fixes the issue in the repo I linked: diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js
index b1832b94a..79719e464 100644
--- a/packages/jest-config/src/index.js
+++ b/packages/jest-config/src/index.js
@@ -277,7 +277,7 @@ export function readConfigs(
}
}
- if (projects.length > 1) {
+ if (projects.length > 0) {
const parsedConfigs = projects
.filter(root => {
// Ignore globbed files that cannot be `require`d. … followed by $ ls -la node_modules/jest-config
lrwxr-xr-x 1 theneva staff 38 Dec 11 11:54 node_modules/jest-config -> ../../../.config/yarn/link/jest-config
$ ls -la ~/.config/yarn/link/jest-config
lrwxr-xr-x 1 theneva staff 39 Dec 11 11:54 /Users/theneva/.config/yarn/link/jest-config -> ../../../code/jest/packages/jest-config
$ yarn jest
yarn run v1.12.3
$ /Users/theneva/code/jest-project-stuff/node_modules/.bin/jest
PASS a packages/a/test.js
✓ 1+1 (3ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.712s, estimated 1s
Ran all test suites.
✨ Done in 1.15s. |
That's great, @theneva thanks for checking! |
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. |
🐛 Bug Report
Jest attempts to run all JS, JSON, and snapshot files as tests (ignoring the test config in the project folder) when only one project is specified in the
projects
array in the root project config.Interestingly, it works as expected if the
projects
array includes any other project, even if that project has no Jest config and no tests. See the linked repo's README for an example.This is a real use case for us, as we have several packages that are not required in all builds, but have lots of dependencies and/or take a long time to build. To avoid wasting time and money during the build, our build process for any
<package>
(starting with a copy of the project structure inside a Docker container) goes like this:<package>
rm -rf
all other packagesyarn install
yarn build
(which builds all packages in order of dependencies)yarn test
(which runs Jest for all packages, configured with"projects": [ "packages/*" ]
)If
package
is a library or app with no dependencies on other workspace packages, we end up with exactly one package left inpackages/
, sopackages/*
resolves to exactly one package, which in turn triggers this bug.To Reproduce
Create a repo with the following structure:
Add the following Jest config to
repo/package.json
:Add any Jest config to
repo/packages/a/package.json
:Add any dummy test to
repo/packages/a/test.js
, such as:Run Jest and verify that it ignores the project config, and instead attempts to run the
package.json
files in both root andpackages/a
as tests (which fail), in addition totest.js
(which passes):Expected behavior
The tests for the specified project should be executed with the project's Jest config, the way it would be executed if there were multiple projects.
Link to repl or repo (highly encouraged)
Please see README (and code that reflects the reproduction steps above) at https://github.com/theneva/jest-project-stuff
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: