Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a7bf859
fix(inline-snapshot): can be used by multiple tests. On clean state, …
jycouet Feb 11, 2025
ffc1fd2
linting
jycouet Feb 11, 2025
ebe1a06
Keep 1 failing test
jycouet Feb 11, 2025
33274ae
test the initial case
jycouet Feb 11, 2025
1c0f9fc
should be better :)
jycouet Feb 11, 2025
a78ba52
step by step understanding how it works
jycouet Feb 11, 2025
4ec405b
Adding tests and fixing code
jycouet Feb 12, 2025
04b66c6
lint:fix
jycouet Feb 12, 2025
c3423e8
lint++
jycouet Feb 12, 2025
a77cb34
lint#
jycouet Feb 12, 2025
7645936
rmv devbox
jycouet Feb 12, 2025
686c94d
add
jycouet Feb 12, 2025
42e42b6
del
jycouet Feb 12, 2025
9698b78
Merge branch 'main' of github.com:vitest-dev/vitest into fix-inlinesn…
jycouet Feb 12, 2025
468d386
Merge branch 'main' into fix-inlinesnapshot
hi-ogawa Feb 16, 2025
8e6ec5e
test: add test
hi-ogawa Feb 17, 2025
188e1ca
test: remove simple tests
hi-ogawa Feb 17, 2025
01030c0
test: add failing test
hi-ogawa Feb 17, 2025
1dc1c63
test: remove old test
hi-ogawa Feb 17, 2025
389f83f
test: tweak
hi-ogawa Feb 17, 2025
e3bb460
fix: reject only when snapshot mismatches
hi-ogawa Feb 17, 2025
20442c5
chore: cleanup
hi-ogawa Feb 17, 2025
0647a67
fix: show diff
hi-ogawa Feb 17, 2025
2bff432
test: pathe for windows
hi-ogawa Feb 17, 2025
16b1992
test: tweak for ci
hi-ogawa Feb 17, 2025
66a124f
test: test multiple tests
hi-ogawa Feb 17, 2025
118ebb0
Merge branch 'main' into fix-inlinesnapshot
hi-ogawa Feb 25, 2025
9e4dfd2
Merge branch 'main' into fix-inlinesnapshot
hi-ogawa Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ export default class SnapshotState {
): void {
this._dirty = true
if (options.stack) {
this._inlineSnapshots.push({
snapshot: receivedSerialized,
testId: options.testId,
...options.stack,
})
// In a clean state, we don't want to set the inlineSnapshots 2 times
if (this._inlineSnapshotStacks.some(s => s.file === options.stack!.file && s.line === options.stack!.line && s.column === options.stack!.column)) {
this._inlineSnapshots.push({
snapshot: receivedSerialized,
testId: options.testId,
...options.stack,
})
}
}
else if (options.rawSnapshot) {
this._rawSnapshots.push({
Expand Down Expand Up @@ -343,12 +346,6 @@ export default class SnapshotState {
// https://github.com/vitejs/vite/issues/8657
stack.column--

// reject multiple inline snapshots at the same location
if (this._inlineSnapshotStacks.some(s => s.file === stack!.file && s.line === stack!.line && s.column === stack!.column)) {
// remove already succeeded snapshot
this._inlineSnapshots = this._inlineSnapshots.filter(s => !(s.file === stack!.file && s.line === stack!.line && s.column === stack!.column))
throw new Error('toMatchInlineSnapshot cannot be called multiple times at the same location.')
}
this._inlineSnapshotStacks.push({ ...stack, testId })
}

Expand Down
26 changes: 1 addition & 25 deletions test/cli/fixtures/fails/inline-snapshop-inside-loop.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
import {test, expect} from "vitest";

test("fail 1", () => {
for (const str of ["foo", "bar"]) {
expect(str).toMatchInlineSnapshot();
}
});

test("fail 2.1", () => {
for (const str of ["foo", "bar"]) {
expect(str).toMatchInlineSnapshot(`"foo"`);
}
});

test("fail 2.2", () => {
for (const str of ["foo", "bar"]) {
expect(str).toMatchInlineSnapshot(`"bar"`);
}
});

test("fail 3", () => {
for (const str of ["ok", "ok"]) {
expect(str).toMatchInlineSnapshot();
}
});

test("fail 4", () => {
for (const str of ["ok", "ok"]) {
expect(str).toMatchInlineSnapshot(`"ok"`);
}
});
});
8 changes: 1 addition & 7 deletions test/cli/test/__snapshots__/fails.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ Error: InlineSnapshot cannot be used inside of test.each or describe.each
Error: InlineSnapshot cannot be used inside of test.each or describe.each"
`;

exports[`should fail inline-snapshop-inside-loop.test.ts 1`] = `
"Error: toMatchInlineSnapshot cannot be called multiple times at the same location.
Error: toMatchInlineSnapshot cannot be called multiple times at the same location.
Error: toMatchInlineSnapshot cannot be called multiple times at the same location.
Error: toMatchInlineSnapshot cannot be called multiple times at the same location.
Error: toMatchInlineSnapshot cannot be called multiple times at the same location."
`;
exports[`should fail inline-snapshop-inside-loop.test.ts 1`] = `"Error: Snapshot \`fail 1 2\` mismatched"`;

exports[`should fail mock-import-proxy-module.test.ts 1`] = `"Error: There are some problems in resolving the mocks API."`;

Expand Down
5 changes: 1 addition & 4 deletions test/cli/test/fails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const root = resolve(__dirname, '../fixtures/fails')
const files = await glob(['**/*.test.ts'], { cwd: root, dot: true, expandDirectories: false })

it.each(files)('should fail %s', async (file) => {
const { stderr } = await runVitest({
root,
update: file === 'inline-snapshop-inside-loop.test.ts' ? true : undefined,
}, [file])
const { stderr } = await runVitest({ root }, [file])

expect(stderr).toBeTruthy()
const msg = String(stderr)
Expand Down