Skip to content
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

Global Setup/Teardown #6600

Closed
simoncarbajal opened this issue Jul 2, 2018 · 2 comments
Closed

Global Setup/Teardown #6600

simoncarbajal opened this issue Jul 2, 2018 · 2 comments

Comments

@simoncarbajal
Copy link

🐛 Bug Report

The global variable when testEnvironment == 'node' is not shared between tests and global setup/teardown scripts as shown here:
http://jestjs.io/docs/en/mongodb#docsNav
http://jestjs.io/docs/en/configuration#globalsetup-string

To Reproduce

in package.json

"scripts": {
    "test": "jest --config=./jest.config.js;"
}
// in jest.config.js
module.exports = {
  testEnvironment: 'node',
  globalSetup: './tests/globalSetup.js'
};
// in globalSetup.js
global.myVar1 = '1';
module.exports = async () => {
  global.myVar2 = '2';
};
// in test.spec.js
console.log(global.myVar1);    // undefined
console.log(global.myVar2);    // undefined

Expected behavior

// in test.spec.js
console.log(global.myVar1);    // '1'
console.log(global.myVar2);    // '2'

Desired

Run only once a global unique afterAll or beforeAll for all the tests.

npx envinfo --preset jest

System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 10.5.0 - /usr/local/bin/node
    npm: 6.1.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.2.0 => 23.2.0
@SimenB
Copy link
Member

SimenB commented Jul 2, 2018

Duplicate of #6007.

This is not really possible to fix and still keep tests isolated. Ideas welcome on how to do it!

@SimenB SimenB closed this as completed Jul 2, 2018
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants