Comments (6)
Yeah, probably it's not actionable for Vitest for now. Nonetheless, thanks for raising an issue with a concise reproduction.
Btw, one more limitation of toMatchFileSnapshot
. As explained in the following issue, it cannot automatically delete obsolete snapshot files.
If you have many files to manage, then you might need to write your own script or something to make sure "helm files" and "helm snapshot files" correspond to each other.
from vitest.
I think this is because the main use case is to just dump string directly to a file, so serialization is skipped for raw string input:
vitest/packages/snapshot/src/port/state.ts
Lines 242 to 244 in fee7d8b
Otherwise default string serializer would write quoted "hello"
instead of hello
to the file by default.
Actually if the input is not a raw string like expect({ hello: "world" }).toMatchFileSnapshot()
, then serializers (including custom ones) will be applied.
If you happen to have a specific use case to apply custom serializer for raw string, could you share the motivation? Maybe we can suggest some okay-ish workaround.
I don't think there's a good way to apply just user's custom serializers, so probably we cannot solve this issue/limitation in a general manner.
from vitest.
My use case is that I'm using vitest
to make sure that Kubernetes manifests generated by helm
haven't changed when new versions are released. However, those manifests do contain the version numbers which are expected to change, and I want to use a custom serializer to swap out those version numbers for static strings (so that the tests don't fail). These are all raw strings since they're generated by a non-Node tool (helm
in this case).
I will try using an object instead of just a raw string to see if it serves my case, thank you for suggesting it.
from vitest.
Thanks for providing the detail. Btw, did you try toMatchSnapshot
? https://vitest.dev/api/expect.html#tomatchsnapshot This uses a single file __snapshots__/some-file.test.ts.snap
to write all the snapshots for each test file, so I would assume it hinders readability for your use case, but just in case.
from vitest.
Yeah that's my workaround for now. The downside is that the snapshot file is ~40,000 lines and GitHub has trouble showing the diff when something changes π
In any case, if you think this issue won't be fixed please feel free to close it. I figure it's better to open this issue so that other folks can search for it if they run into the same thing.
from vitest.
By the way, for my specific use case, your suggestion of switching from raw string to an object did work - I use a YAML parser to turn the raw string into an object for comparison, and toMatchFileSnapshot
does invoke my custom serializer when I do that, so thank you for the suggestion!
from vitest.
Related Issues (20)
- ``` HOT 1
- The "cause" property of Error is ignored when matching HOT 9
- Unhandled uncaught error fails test run, no stack trace present HOT 2
- Missing input elements from Form event in Submit handler HOT 1
- Type safe assertions HOT 3
- Migrate UI Cypress tests to Vitest Browser Tests
- web-worker search path regression with ES6 wasm module
- Browser mode is flaky HOT 1
- OOM when running vitest in docker HOT 3
- Wrong diff for objectContaining
- inner suite `{ sequential: true }` doesn't override outer suite `{ concurrent: true }`
- ζ§θ‘ vitest ζΆζ₯ι ast.body is not iterable HOT 1
- Remove version labels for Vitest 2 documentation
- Text reporter still creates an empty coverage folder HOT 3
- using setupFiles from parent dir causes 'Failed to load url' HOT 2
- Check for listen port collision for browser tests HOT 6
- Add `aroundEach` Hook Similar to RSpec `around` HOT 10
- Segmentation fault - Test fails when using Vitest, but passes when using Jest HOT 2
- Mixing browser and non-browser projects in vitest workspace causes error HOT 2
- testNamePattern doesn't parse RegEx'es in the CLI, or documentation is unclear HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.