-
-
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
globalSetup is executed in different context than tests #6007
Comments
This is by design - every single test file gets its own context. If you want to access something set up in a Importing your If you have more questions about this topic, we recommend using StackOverflow or our discord channel. If you think anything can be clarified in the docs, a PR is most welcome! |
Thanks a lot for the explanation. |
@SimenB I think this is more of an issue of the But I think the strange in-between behavior we have now will be unexpected by most users. If I've convinced any of the maintainers, would this change be welcome as a pull request? |
Tests do not share the same context, each individual test file has their own. If you want to run setup a single time (typically starting up some long-running service), use |
Thanks for the quick response. I had a misunderstanding while reading the documentation on resetModules. It says that tests share module state by default but not test files. I had thought it meant test files share state by default. |
PRs clarifying the docs are always welcome 🙂 |
The documentation at the moment describes the behavior of Jest when `resetModules` is set to `true`, but leaves the default/false case unclarified. I had a misconception that the module registry would not be reset at all in the false case, where it's still reset between different test files. This misconception was clarified by SimienB in issue jestjs#6007. The reporter of issue jestjs#4413 also had this question. This commit updates the documentation of `resetModules` to explain the default case more explicitly.
The documentation at the moment describes the behavior of Jest when `resetModules` is set to `true`, but leaves the default/false case unclarified. I had a misconception that the module registry would not be reset at all in the false case, where it's still reset between different test files. This misconception was clarified by SimienB in issue jestjs#6007. The reporter of issue jestjs#4413 also had this question. This commit updates the documentation of `resetModules` to explain the default case more explicitly.
The documentation at the moment describes the behavior of Jest when `resetModules` is set to `true`, but leaves the default/false case unclarified. I had a misconception that the module registry would not be reset at all in the false case, where it's still reset between different test files. This misconception was clarified by SimienB in issue jestjs#6007. The reporter of issue jestjs#4413 also had this question. This commit updates the documentation of `resetModules` to explain the default case more explicitly.
The documentation at the moment describes the behavior of Jest when `resetModules` is set to `true`, but leaves the default/false case unclarified. I had a misconception that the module registry would not be reset at all in the false case, where it's still reset between different test files. This misconception was clarified by SimienB in issue jestjs#6007. The reporter of issue jestjs#4413 also had this question. This commit updates the documentation of `resetModules` to explain the default case more explicitly.
The documentation at the moment describes the behavior of Jest when `resetModules` is set to `true`, but leaves the default/false case unclarified. I had a misconception that the module registry would not be reset at all in the false case, where it's still reset between different test files. This misconception was clarified by SimienB in issue #6007. The reporter of issue #4413 also had this question. This commit updates the documentation of `resetModules` to explain the default case more explicitly.
I'm writing a jest environment that enables coverage in the selenium environment. I'd like to communicate the coverage maps from the environment object back to the global teardown so that I can merge them and write out a single file. I was looking at using node-ipc to do that. I was wondering if there might be a more official way of doing this using jest APIs. |
If you just need to pass a simple reference, such as a connection string from your |
@kevinbarabash You can see how we did it, https://github.com/microsoft/BotFramework-WebChat/blob/master/__tests__/html/__jest__/setupRunHTMLTest.js#L66. We grab the |
For anyone else wondering what this referred to:
As far as I can tell (as of Assuming that's right, as far as I can tell there are two approaches to this:
edit: Some of my above assertions are false; see #7184, which is a really useful thread. |
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. |
Currently if
globalSetup
is used to asynchronously prepare something, and then the same file is imported in tests it results in two separate module instances.Repo to reproduce: https://github.com/kirill-konshin/jest-globalsetup-bug
After
npm test
console shows that test had itundefined
whilesetup
andteardown
both printed same value:In my use case inside
doSomethingAsync
an instance ofpuppeteer
browser would be created.AFAIK there is no other way to do something before all tests and after all tests.
NPX:
The text was updated successfully, but these errors were encountered: