|
1 | 1 | import fs from 'node:fs'
|
| 2 | +import path from 'node:path' |
2 | 3 | import { expect, test } from 'vitest'
|
3 | 4 | import { runVitest } from '../../test-utils'
|
4 | 5 |
|
@@ -46,3 +47,68 @@ test('snapshots in skipped test/suite is not obsolete', async () => {
|
46 | 47 | "
|
47 | 48 | `)
|
48 | 49 | })
|
| 50 | + |
| 51 | +test('handle obsoleteness of toMatchSnapshot("custom message")', async () => { |
| 52 | + const root = path.join(import.meta.dirname, './fixtures/skip-test-custom') |
| 53 | + |
| 54 | + // clear snapshots |
| 55 | + fs.rmSync(path.join(root, '__snapshots__'), { recursive: true, force: true }) |
| 56 | + |
| 57 | + // create snapshot on first run |
| 58 | + let vitest = await runVitest({ |
| 59 | + root, |
| 60 | + update: true, |
| 61 | + }) |
| 62 | + expect(vitest.stdout).toContain('Snapshots 4 written') |
| 63 | + expect(fs.readFileSync(path.join(root, '__snapshots__/basic.test.ts.snap'), 'utf-8')).toMatchInlineSnapshot(` |
| 64 | + "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 65 | +
|
| 66 | + exports[\`custom a > x 1\`] = \`0\`; |
| 67 | +
|
| 68 | + exports[\`custom a > y 1\`] = \`0\`; |
| 69 | +
|
| 70 | + exports[\`custom b > w 1\`] = \`0\`; |
| 71 | +
|
| 72 | + exports[\`custom b > z 1\`] = \`0\`; |
| 73 | + " |
| 74 | + `) |
| 75 | + |
| 76 | + // Skipped tests' `toMatchSnapshot("...")` is not considered obsolete |
| 77 | + vitest = await runVitest({ |
| 78 | + root, |
| 79 | + testNamePattern: 'custom a', |
| 80 | + }) |
| 81 | + expect(vitest.stdout).toContain('1 passed') |
| 82 | + expect(vitest.stdout).toContain('1 skipped') |
| 83 | + expect(vitest.stdout).not.toContain('obsolete') |
| 84 | + |
| 85 | + vitest = await runVitest({ |
| 86 | + root, |
| 87 | + testNamePattern: 'custom b', |
| 88 | + }) |
| 89 | + expect(vitest.stdout).toContain('1 passed') |
| 90 | + expect(vitest.stdout).toContain('1 skipped') |
| 91 | + expect(vitest.stdout).not.toContain('obsolete') |
| 92 | + |
| 93 | + // check snapshot doesn't change when skip + update |
| 94 | + vitest = await runVitest({ |
| 95 | + root, |
| 96 | + update: true, |
| 97 | + testNamePattern: 'custom a', |
| 98 | + }) |
| 99 | + expect(vitest.stdout).toContain('1 passed') |
| 100 | + expect(vitest.stdout).toContain('1 skipped') |
| 101 | + expect(vitest.stdout).not.toContain('obsolete') |
| 102 | + expect(fs.readFileSync(path.join(root, '__snapshots__/basic.test.ts.snap'), 'utf-8')).toMatchInlineSnapshot(` |
| 103 | + "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 104 | +
|
| 105 | + exports[\`custom a > x 1\`] = \`0\`; |
| 106 | +
|
| 107 | + exports[\`custom a > y 1\`] = \`0\`; |
| 108 | +
|
| 109 | + exports[\`custom b > w 1\`] = \`0\`; |
| 110 | +
|
| 111 | + exports[\`custom b > z 1\`] = \`0\`; |
| 112 | + " |
| 113 | + `) |
| 114 | +}) |
0 commit comments