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

Snapshot with more than a handful of lines #4661

Closed
cefn opened this issue Dec 5, 2023 · 1 comment
Closed

Snapshot with more than a handful of lines #4661

cefn opened this issue Dec 5, 2023 · 1 comment

Comments

@cefn
Copy link

cefn commented Dec 5, 2023

Describe the bug

As per #3201 ( @sheremet-va suggested I report a new bug ) ...

I am experiencing a failed snapshot, but the vite reporter doesn't report more than a couple of lines of the snapshot diff, so I'm unable to tell what the test failed on.

Reproduction

The issue was observed in the Gitlab actions run at https://github.com/cefn/watchable/actions/runs/7088197269/job/19290116297?pr=55 and originates from the test suite source at https://github.com/cefn/watchable/blob/32630d4bb29e6ad3c6f1fa29b613b47ad2913b24/packages/nevermore/test/strategies/concurrency.test.ts#L50-L63

The too-terse console output looks like this in github...

image

However, in retrospect I think this could be my non-conformant use of toMatchInlineSnapshot().

The expanded snapshot string version was overwhelmed with whitespace making it impossible to read, so I switched it to a javascript array, which seemed functional until it failed only in github (with no good feedback from the snapshot error). The tests were passing when run locally.

But maybe this was never meant to work. To align with expectations, perhaps I should have switched the signature of toMatchInlineSnapshot() to be toEqual() after refactoring the snapshot from a string to an array.

Until this point I found the pattern of switching the snapshot string to be an array to be fine in practice, but this may be why the error serialization is wrong - if it (maybe correctly) makes a strong assumption that snapshot is a string not an array. Feel free to close if Javascript objects/arrays are non-conformant snapshots.

System Info

npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers
Need to install the following packages:
envinfo@7.11.0
Ok to proceed? (y) y

  System:
    OS: macOS 13.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 83.50 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - /opt/homebrew/opt/nvm/versions/node/v20.9.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/shims/yarn
    npm: 10.1.0 - /opt/homebrew/opt/nvm/versions/node/v20.9.0/bin/npm
    pnpm: 8.6.11 - /opt/homebrew/opt/nvm/versions/node/v20.3.1/bin/pnpm
  Browsers:
    Chrome: 119.0.6045.199
    Edge: 119.0.2151.97
    Safari: 16.6


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 5, 2023
@sheremet-va
Copy link
Member

This is not the correct usage of toMatchInlineSnapshot - you need to generate the string locally and then publish it with a string.

@sheremet-va sheremet-va removed bug p3-minor-bug An edge case that only affects very specific usage (priority) labels Feb 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants