-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 'setupFiles' with <rootDir> breaks libs/apps tests #2344
Comments
I've also been trying to figure out how to get around this. We want to use the same setup for all of our Angular libraries and apps, so I've tried doing something like the following: Global Jest config// jest.config.js
module.exports = {
// Configuration common to all Jest tests
} Global Jest config for Angular projects// jest.config.angular.js
module.exports = {
// Configuration common to all Angular tests
preset: './jest.config.js',
setupFilesAfterEnv: [ './jest.setup.angular.js' ]
} Global Jest setup file for Angular tests// jest.setup.angular.ts
import 'zone.js/dist/zone.js'
import 'zone.js/dist/proxy'
import 'zone.js/dist/sync-test'
import 'zone.js/dist/async-test.js'
import 'zone.js/dist/proxy.js'
import 'jest-zone-patch'
import 'jest-preset-angular' Project-level Jest config// jest.config.js
module.exports = {
preset: '../../../jest.config.angular.js',
// other configurations for this particular project
} When I run tests for the project I get the same error, where Jest is looking for the setup file from the context of the project, rather than at the root of the monorepo: An unhandled exception occurred: ● Validation Error:
Module ./jest.setup.angular.ts in the setupFilesAfterEnv option was not found.
<rootDir> is: /Users/wparson/Work/monorepo/libs/components-library/payment-calculator Is there a way I can tell Jest to use the root of the monorepo as the |
Just discovered Nx's Jest builder options: https://nx.dev/web/api/jest/builders/jest#jest Adding the "test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/components-library/payment-calculator/jest.config.js",
"tsConfig": "libs/components-library/payment-calculator/tsconfig.spec.json",
"setupFile": "jest.setup.angular.ts"
}
} We're still stuck with referencing the setup file in each individual project, but at least it's all in one file (angular.json) instead of spread across all of our project-level Jest configs. |
See #2314 (comment) as I believe they are related. I believe the ability to use This breaks IDEs that use https://github.com/jest-community/vscode-jest as they need the setup file to pull in required setup resources because that extension is not able to run the underlying jest configs for each app / lib when running tests |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
We are still experiencing this issue in our monorepo |
Sorry. The issue was marked by mistake. I removed the label. |
Is there any progress on this? I'm still seeing the issue but I'm assuming I must be missing a simple fix. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Prerequisites
Expected Behavior
Properly resolve
rootDir
whensetupFiles
are being used for jest configCurrent Behavior
Let's say my root
jest.config.js
is usingsetupFiles
for various reasons likenow if we wanna run test for particular package which uses root as a preset, setupFiles are not found as jest sets root dir to that particular directory from where are those test executed (so instead of having root
../..
- workspace root, it's./libs/my-lib
Failure Information (for bugs)
The text was updated successfully, but these errors were encountered: