Open pragmatta opened 1 week ago
Also when the data does not result in an invalide escapepe sequence, it fails to properly parse out snapshots, resulting in test fails.
For example test:
test("dummy", () => {
expect({foo:"h\\i"}).toMatchSnapshot()
})
results in snapshot:
exports[`dummy 1`] = `
{
"foo": "h\i",
}
`;
that fails the test because of parsing mismatch:
37 | test("dummy", () => {
38 | expect({foo:"h\\i"}).toMatchSnapshot()
^
error: expect(received).toMatchSnapshot(expected)
Expected:
{
"foo": "hi",
}
Received:
{
"foo": "h\i",
}
The state of our snapshots implementation isn't great.
The state of our snapshots implementation isn't great.
Is there a way to read/parse the snapshots (easily), how does Bun do it? I want to cross-reference outputs of different implementations of same abstraction. I tried requiring the snapshot-file and reads an [object Module]
but has no properties..
const snapshots = require("./__snapshots__/OINOApi.test.ts.snap")
const keys = Object.keys(snapshots)
for (const key of keys) {
console.log(key, snapshots[key])
}
I tried requiring the snapshot-file and reads an
[object Module]
but has no properties..
Figured this one out, the extension of the file needs to be .js for it to work. Node seems to not care about this.
Discussed in https://github.com/oven-sh/bun/discussions/10402
Having
\x
in the snapshot data creates a corrupted snapshot that can't be read. For example this testgenerates snapshot
Which is invalid Javascript (I assume the file gets evaluated) as the
\x
is treated as a hex string and parsing the snapshot fails. Instead running the test will write it in the snapshot over and over again (and creates a problem that is hard to diagnose).