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 not being created #1376

Closed
6 tasks done
pechitook opened this issue May 26, 2022 · 2 comments · Fixed by #1510
Closed
6 tasks done

Inline snapshots not being created #1376

pechitook opened this issue May 26, 2022 · 2 comments · Fixed by #1510

Comments

@pechitook
Copy link

Describe the bug

Under some specific settings unkown to me yet (dependencies, maybe?), inline snapshots do not work. To be more specific:

  • They are not written when there is only one toMatchInlineSnapshot assertion
  • They are written to the wrong assertion when there are more than one

This happened to my first project with vite/vitest and for a while assumed that they just weren't working but trying out a new project from scratch didn't have this issue. I believe this is somewhat of an edge case, and even though I narrowed my dependencies to the bare minimum in a StackBlitz project, I cannot seem to find the root cause.

Thanks!

Reproduction

  1. Go to https://stackblitz.com/edit/vitejs-vite-vxrdhg?file=tests/unit/utils/dates.spec.js&view=editor
  2. Run npm run test
  3. See how the second snapshot gets created with the value of the first snapshot.

More variants:

  • Remove the second test block, see how vitest says the snapshot was written but it is not

System Info

I don't think this is relevant given there is a StackBlitz repro, but still

  System:
    OS: macOS 11.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 963.97 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Brave Browser: 97.1.34.81
    Chrome: 101.0.4951.64
    Firefox: 100.0.2
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-vue: ^2.3.3 => 2.3.3
    vite: ^2.9.9 => 2.9.9
    vitest: ^0.12.9 => 0.12.9

Used Package Manager

npm

Validations

@pechitook pechitook changed the title Inilne snapshots not being created Inline snapshots not being created May 29, 2022
@sheremet-va
Copy link
Member

I found that the problem is with the source map for .js files:

const pos = consumer.originalPositionFor({ line, column })

This line returns invalid original position. Need investigating.

@pechitook
Copy link
Author

Just updated to 0.15.2 and can now use inlineSnapshots in the project. Many thanks @sheremet-va 🙇

@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2023
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