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

Inline snapshots fail with most-recent babel, jest, and babel-plugin-source-map-support #11151

Closed
mikestopcontinues opened this issue Mar 4, 2021 · 3 comments

Comments

@mikestopcontinues
Copy link

🐛 Bug Report

Inline snapshots don't work with this combo of packages. This may be related to #6744, but it happens even without matching the criteria in that ticket.

 Jest: Couldn't locate all inline snapshots.

      at Object.parse (node_modules/jest-snapshot/build/InlineSnapshots.js:267:11)
      at Object.parse (node_modules/prettier/index.js:13625:19)
      at coreFormat (node_modules/prettier/index.js:14899:14)
      at format (node_modules/prettier/index.js:15131:14)
      at node_modules/prettier/index.js:57542:12
      at Object.format (node_modules/prettier/index.js:57562:12)

To Reproduce

Steps to reproduce the behavior:

  1. Install most-recent babel, jest, and babel-plugin-source-map-support
  2. Try running this test:
test('simply fails', async () => {
  expect({key: [1, '2', null]}).toMatchInlineSnapshot();
});

Link to repl or repo (highly encouraged)

https://repl.it/@stopcontinues/inline-snapshots-busted

envinfo

  System:
    OS: macOS 11.2.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 15.5.1 - ~/.nvm/versions/node/v15.5.1/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.5.2 - ~/.nvm/versions/node/v15.5.1/bin/npm
@spalger
Copy link

spalger commented Mar 31, 2021

I'm experiencing this as well, I've verified that babel-jest is producing valid source maps (pulled the sourcemap out of babel-jest via the inspector and checked with http://sokra.github.io/source-map-visualization/) but then source-map-support isn't able to find those source maps when toMatchInlineSnapshot() is called so the new Error().stack isn't correct and the correct call can't be found. It also seems that source-map-support is installed several times and there are several instances of that module... which might be the root problem here...

Wow, yeah, one of the files imported by my tests had source-map-support/register in it which seems to have broken it, but removing that import fixed it!

@SimenB
Copy link
Member

SimenB commented Apr 3, 2021

Jest handles installation of sourcemaps itself, so you should remove any source-map-support usage in your own code when running tests.

(if you need it for your app, you should set it up in the entrypoint of it, not every single source file, but that's really something to discuss here 🙂)

@SimenB SimenB closed this as completed Apr 3, 2021
@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 10, 2021
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

3 participants