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

No way to get stable snapshot names with test.concurrent #5801

Closed
poolik opened this issue Mar 15, 2018 · 4 comments · Fixed by #14139
Closed

No way to get stable snapshot names with test.concurrent #5801

poolik opened this issue Mar 15, 2018 · 4 comments · Fixed by #14139

Comments

@poolik
Copy link

poolik commented Mar 15, 2018

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Trying to use named snapshots within it.concurrent(...) to get stable snapshot names, but looks like toMatchSnapshot still tries to reference current test name as well, which is not deterministic with concurrent tests.

This seems to have been changed in #4460, before that named snapshots would've worked with concurrent tests.

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

Example repo showing the issue is here:
https://github.com/poolik/jest-named-snapshots-bug

Just look at the src/tests/concurrent.ts. There are several async concurrent tests there using random time to compute and writing their results to named snapshots. The issue is that snapshots names are not deterministic, but depend on currently executing test name, which is random in concurrent tests.

What is the expected behavior?

I should be able to use named snapshots in concurrent tests in a deterministic way (provided that the snapshot names are unique across test suite).

Please provide your exact Jest configuration

View the repro application @ https://github.com/poolik/jest-named-snapshots-bug

Run npx envinfo --preset jest in your project directory and paste the
results here

npx: installed 1 in 2.343s

  System:
    OS: macOS High Sierra 10.13.3
    CPU: x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  Binaries:
    Node: 8.9.4
    Yarn: 1.5.1
    npm: 5.6.0
  npmPackages:
    jest:
      wanted: ^22.4.2
      installed: 22.4.2
@SimenB
Copy link
Member

SimenB commented Mar 18, 2018

Duplicate of #2180

@SimenB SimenB marked this as a duplicate of #2180 Mar 18, 2018
@SimenB SimenB closed this as completed Mar 18, 2018
@poolik
Copy link
Author

poolik commented Mar 19, 2018

@SimenB sorry, but I don't see how this is a duplicate of #2180. That issue ends with someone saying:

I think it's fair to require named snapshots when using test.concurrent()"

But this issue is about the fact that it's not possible to use even named snapshots with concurrent tests. This used to work right up to 22.0.0 release when #4460 was merged. Before that change named snapshots didn't depend on currently executing test, thus they worked with test.concurrent, but after this change it doesn't work anymore.

If I update my repro app linked above to use jest 21.2.1 then it works, as snapshot names use only the name provided in the method call, with 22.0.0 they are prepended by the currently running tests, which is not deterministic with concurrent tests.

@SimenB
Copy link
Member

SimenB commented Mar 19, 2018

#2180 is open, so it hasn't "ended". If you wanna see it happen, please send 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 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

Successfully merging a pull request may close this issue.

2 participants