-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): fix file snapshots in skipped suites considered obsolete (…
- Loading branch information
Showing
6 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/snapshots/test/fixtures/skip-test/__snapshots__/repro.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`repro suite > inner case 1`] = `"hi-1"`; | ||
|
||
exports[`top-level case 1`] = `"hi-2"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
const ENABLE_SKIP = process.env.ENABLE_SKIP; | ||
|
||
describe.skipIf(ENABLE_SKIP)('repro suite', () => { | ||
it('inner case', () => { | ||
expect('hi-1').toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it.skipIf(ENABLE_SKIP)('top-level case', () => { | ||
expect('hi-2').toMatchSnapshot() | ||
}) | ||
|
||
// at least one non-skipped test is needed to reproduce a bug. | ||
// without this, there will be no SnapshotClient.startCurrentRun, | ||
// so the code to check skip/obsolete snapshot is not exercised. | ||
it('normal case', () => { | ||
expect(0).toBe(0) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'node:fs' | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('snapshots in skipped test/suite is not obsolete', async () => { | ||
// create snapshot on first run | ||
fs.rmSync('test/fixtures/skip-test/__snapshots__', { recursive: true, force: true }) | ||
let vitest = await runVitest({ | ||
root: 'test/fixtures/skip-test', | ||
update: true, | ||
}) | ||
expect(vitest.stdout).toContain('Snapshots 2 written') | ||
expect(fs.readFileSync('test/fixtures/skip-test/__snapshots__/repro.test.ts.snap', 'utf-8')).toMatchInlineSnapshot(` | ||
"// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
exports[\`repro suite > inner case 1\`] = \`"hi-1"\`; | ||
exports[\`top-level case 1\`] = \`"hi-2"\`; | ||
" | ||
`) | ||
|
||
// running with `skipIf` enabled should not show "obsolete" | ||
vitest = await runVitest({ | ||
root: 'test/fixtures/skip-test', | ||
env: { | ||
ENABLE_SKIP: '1', | ||
}, | ||
}) | ||
expect(vitest.stdout).toContain('2 skipped') | ||
expect(vitest.stdout).not.toContain('obsolete') | ||
|
||
// running with `skipIf` and `update` should keep snapshots | ||
vitest = await runVitest({ | ||
root: 'test/fixtures/skip-test', | ||
update: true, | ||
env: { | ||
ENABLE_SKIP: '1', | ||
}, | ||
}) | ||
expect(fs.readFileSync('test/fixtures/skip-test/__snapshots__/repro.test.ts.snap', 'utf-8')).toMatchInlineSnapshot(` | ||
"// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
exports[\`repro suite > inner case 1\`] = \`"hi-1"\`; | ||
exports[\`top-level case 1\`] = \`"hi-2"\`; | ||
" | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters