-
-
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
Nested projects are ignored #5463
Comments
Hey @deftomat You can also configure jest to run different configurations in different directories, for example, to achieve the desired behavior in your example project, put this as the main module.exports = {
projects: [
{
displayName: "test",
testMatch: ["<rootDir>/packages/**/*.js"]
},
{
displayName: "lint",
runner: "jest-runner-eslint",
testMatch: ["<rootDir>/packages/first/**/*.js"]
}
]
}; If you want to run jest in each repo individually you can use a tool like lerna. Configure a test script in your |
Whoa, didn't expect such usage to be honest. Projects nested inside other projects, projectception! |
I think I'd be happy for this to be supported. We just need to change the project merging to be recursive. |
I was under the impression that when a jest root config has projects and you run it, it will actually use a different configuration file/json for each project if the project has one: E.g.:
Is my assumption wrong? |
Well, kind of. We, for example, using TypeScript in a few packages and to make it works, these packages have a necessary config. Global Jest's config doesn't know anything about TS. So, it looks like Jest is using a package's config, however, it ignores some parts. Like in this issue, it ignores Jest is awesome and probably the best test framework but projects feature is highly unpredictable. At least, for me 😉 |
When i do something similar to this: module.exports = {
projects: [
{
displayName: "test",
testMatch: ["<rootDir>/packages/**/*.js"]
},
{
displayName: "lint",
runner: "jest-runner-eslint",
testMatch: ["<rootDir>/packages/first/**/*.js"]
}
]
}; in my own package with the exception of using multiple runners (i'm interested in running tests in multiple projects from the root dir), jest runs matching every single file in the entire repo. It also applies the babel version of root instead of using each packages |
@brad-decker as a workaround for a related problem I have created fork of There is also a pending PR to get this merged into |
@cpojer @thymikee This is an old one but is there still interest in supporting nested projects? My specific use case is a monorepo with a structure like: apps
- app-one
- jest.config.json
- app-two
- jest.config.json
packages
- shared-package # used in both apps
- jest.config.json
- design-system # used in both apps
- jest.config.json
- utils # use in app-one and shared-package (transitive dep of app-two via shared-package)
- jest.config.json We are wanting to have our apps each define I'd be fine to take on the work but might need somebody to point me in the direction of Jest's config resolution code. |
I would very much like this feature as well. @nathanforce the code in question looks to be here: https://github.com/facebook/jest/blob/aa64672e728738926571746a85c57d1658bdaf55/packages/jest-config/src/index.ts#L280 |
Still happy to merge a PR with this. Link above is a good start - recursively going through all |
I wrote a small root config generator that creates a meta-project-list and sets the appropriate Perhaps this is something that could be adapted slightly and incorporated into Jest? There are limitations of course, but for my simple Jest config this works perfectly. // root jest.config.js
const path = require('path');
const glob = require('glob');
const WORKSPACE_GLOB = './packages/*/jest.config.js';
const projects = glob.sync(path.join(__dirname, WORKSPACE_GLOB)).flatMap((jestConfigPath) => {
const packageDir = path.dirname(jestConfigPath);
const packageName = path.basename(packageDir);
const config = require(jestConfigPath);
// If there are no subprojects, use the entire config as a project
const subprojects = config.projects ?? [config];
return subprojects.map(({ displayName, ...projectConfig }) => ({
displayName: `${packageName}${displayName ? `-${displayName}` : ''}`,
rootDir: packageDir,
...projectConfig,
}));
});
module.exports = {
projects,
}; Some open questions and limitations:
|
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Running
jest
in monorepo ignores projects in packages.Minimal repo: https://github.com/deftomat/jest-nested-projects-issue
What is the expected behavior?
Should run all projects in all packages. In another words: Should run nested projects.
Environment
Jest: v22.1.4
Node: v8.9.4
OS: macOS High Sierra
The text was updated successfully, but these errors were encountered: