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

setupFiles or setupFilesAfterEnv are no longer awaited #10962

Closed
mbreton opened this issue Dec 21, 2020 · 5 comments
Closed

setupFiles or setupFilesAfterEnv are no longer awaited #10962

mbreton opened this issue Dec 21, 2020 · 5 comments

Comments

@mbreton
Copy link

mbreton commented Dec 21, 2020

💥 Regression Report

I'm not sure it's a regression and I guess using Jest well, but it seems the setupFiles and setupFilesAfterEnv modules are no longer blocking in the Jest execution sequence flow.
I mean, if there is an async function in one of the setupFiles or setupFilesAfterEnv Jest doesn't wait the end of the promise.

Last working version

Worked up to version: ?

Stopped working in version: 24.9.0

To Reproduce

Create a simple project like this :
https://repl.it/join/tlxcxyac-mathieubreton

By running a yarn test you should see that:

yarn test
yarn run v1.22.5
$ jest
  console.log
    ============== Setup file ==============

      at setup.js:2:11

  console.log
    ---------- Sum test ----------

      at Object.<anonymous> (sum.test.js:5:13)

 PASS  ./sum.test.js
  sum
    ✓ adds 1 + 2 to equal 3 (3 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.808 s, estimated 2 s
Ran all test suites.
  console.log
    END ------ Sum test ------ END

      at sum.test.js:8:17

  console.log
    test

      at Object.<anonymous> (sum.test.js:14:13)

✨  Done in 2.56s.

Expected behavior

Jest should wait the end of the promise resolution in the setupFiles or setupFilesAfterEnv before continue and wait to execute test suites.

Link to repl or repo (highly encouraged)

https://repl.it/join/tlxcxyac-mathieubreton

Run npx envinfo --preset jest

npx envinfo --preset jest
npx: installed 1 in 2.177s

  System:
    OS: macOS 11.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 14.9.0 - ~/.nvm/versions/node/v14.9.0/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.14.9 - ~/.nvm/versions/node/v14.9.0/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3
@mbreton mbreton changed the title setupFiles or setupFilesAfterEnv are not longer awaited setupFiles or setupFilesAfterEnv are no longer awaited Dec 21, 2020
@SimenB
Copy link
Member

SimenB commented Dec 21, 2020

There is nothing to wait for (Jest cannot detect that you've fired off promises in your setup file). This has never worked before either, meaning there's no regression, so I'll close this.

That said, we could start to await exported promises, but that's a feature request. And top level await, which is available in ESM, sorta negates it. But again, feel free to open a feature request for awaiting default exported promises (or send a PR, logic is here: https://github.com/facebook/jest/blob/e5a84d92fc906a5bb140f9753b644319cea095da/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L74-L82 & https://github.com/facebook/jest/blob/e5a84d92fc906a5bb140f9753b644319cea095da/packages/jest-jasmine2/src/index.ts#L151-L159)

@SimenB SimenB closed this as completed Dec 21, 2020
@mbreton
Copy link
Author

mbreton commented Dec 21, 2020

Thanks @SimenB , indeed , I was not sure it was a regression.
I will try to figure out how I could implement it in a PR.

@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 11, 2021
@SimenB
Copy link
Member

SimenB commented Jan 1, 2024

#14749

@SimenB
Copy link
Member

SimenB commented Feb 20, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants