question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

globalSetup and globalTeardown are ignored in projects.

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
ranyitzcommented, Aug 16, 2018

@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 like globalSetup/globalTeardown for a specific project.

Here an example:

projectsetup

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 names globalSetup/globalTeardown which will work as displayed above?

@thymikee @SimenB what do you think?

5reactions
t-kellycommented, May 31, 2018

Also having this problem when trying to run some test files with jest-puppeteer, and other test files with jsdom. Any workarounds?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found