globalSetup and globalTeardown are ignored in projects.
See original GitHub issueDo you want to request a feature or report a bug? Bug.
What is the current behavior?
globalSetup
and globalTeardown
are ignored when they are defined inside a project.
If the current behavior is a bug, please provide the steps to reproduce
I’m using the following jest.config.js
:
module.exports = {
projects: [
{
displayName: 'unit',
testMatch: ['<rootDir>/src/**/*.spec.ts'],
transform: {
"^.+\\.ts$": "ts-jest"
},
moduleDirectories: ["node_modules", "./"],
moduleFileExtensions: ["ts", "js", "json", "node"]
},
{
displayName: 'e2e',
testMatch: ['<rootDir>/e2e/**/*.spec.ts'],
transform: {
"^.+\\.ts$": "ts-jest"
},
moduleDirectories: ["node_modules", "./"],
moduleFileExtensions: ["ts", "js", "json", "node"],
globalSetup: '<rootDir>/e2e/global-setup.js',
globalTeardown: '<rootDir>/e2e/global-teardown.js'
}
]
};
What is the expected behavior? I’m not sure if this is an expected behaviour or not. However, whey I try to use a non-existing file for a globalSetup / globalTeardown, then it throws the following error:
Validation Error:
Module .../e2e/global-setup.js in the globalSetup option was not found.
So, Jest is expecting an option like this in project.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system. Jest: v22.1.4 Node: v8.9.4 OS: macOS High Sierra
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:17 (4 by maintainers)
Top Results From Across the Web
Getting Jest global setup and global teardown to work in a ...
The typescript environment is not yet defined when globalSetup and globalTeardown are run, which is why jest is failing.
Read more >Configuring Jest
Any global variables that are defined through globalSetup can only be read in globalTeardown . You cannot retrieve globals defined here in your...
Read more >Documentation - Mocha
Configures one or more global teardown fixtures. If given no parameters, unsets any previously-set fixtures. Parameters: Name, Type, Attributes, Description ...
Read more >Configuring Vitest
Path to global setup files, relative to project root ... Glob pattern of file paths to be ignored from triggering watch rerun.
Read more >Top 5 jest-config Code Examples - Snyk
... on jest-config code examples created from the most popular ways it is used in public projects. ... tools/testing/jest-setup.ts', globalTeardown: '.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mariogintili I started implementing the hacky way to do that, realizing it would be fairly easy to implement properly in Jest. We can call it
projectSetup
/projectTeardown
, it would work likeglobalSetup
/globalTeardown
for a specific project.Here an example:
Some use the
projects
feature for running different environments/runners in the same module while other for multiple modules in a monorepo. Maybe we can stick with the namesglobalSetup
/globalTeardown
which will work as displayed above?@thymikee @SimenB what do you think?
Also having this problem when trying to run some test files with jest-puppeteer, and other test files with jsdom. Any workarounds?