|
1 | 1 | import fs from 'node:fs' |
2 | 2 | import path from 'node:path' |
3 | 3 | import { expect, test } from 'vitest' |
4 | | -import { runVitest } from '../../test-utils' |
| 4 | +import { runInlineTests, runVitest } from '../../test-utils' |
5 | 5 |
|
6 | 6 | test('snapshots in skipped test/suite is not obsolete', async () => { |
7 | 7 | // create snapshot on first run |
@@ -114,3 +114,92 @@ test('handle obsoleteness of toMatchSnapshot("custom message")', async () => { |
114 | 114 | " |
115 | 115 | `) |
116 | 116 | }) |
| 117 | + |
| 118 | +test('obsolete snapshots are still reported when another test is skipped', async () => { |
| 119 | + const structure = { |
| 120 | + 'basic.test.ts': ` |
| 121 | + import { expect, it } from 'vitest' |
| 122 | +
|
| 123 | + it.skip('a', () => { |
| 124 | + expect(0).toMatchSnapshot() |
| 125 | + }) |
| 126 | +
|
| 127 | + it('b', () => { |
| 128 | + expect(1).toMatchSnapshot() |
| 129 | + }) |
| 130 | + `, |
| 131 | + '__snapshots__/basic.test.ts.snap': `// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 132 | +
|
| 133 | +exports[\`a 1\`] = \`0\`; |
| 134 | +
|
| 135 | +exports[\`b 1\`] = \`1\`; |
| 136 | +
|
| 137 | +exports[\`removed test 1\`] = \`2\`; |
| 138 | +`, |
| 139 | + } |
| 140 | + |
| 141 | + const failed = await runInlineTests(structure, { update: 'none' }) |
| 142 | + expect(failed.errorTree()).toMatchInlineSnapshot(` |
| 143 | + { |
| 144 | + "basic.test.ts": { |
| 145 | + "__module_errors__": [ |
| 146 | + "Obsolete snapshots found when no snapshot update is expected. |
| 147 | + · removed test 1 |
| 148 | + ", |
| 149 | + ], |
| 150 | + "a": "skipped", |
| 151 | + "b": "passed", |
| 152 | + }, |
| 153 | + } |
| 154 | + `) |
| 155 | + |
| 156 | + const updated = await runInlineTests(structure, { update: 'all' }) |
| 157 | + expect(fs.readFileSync(path.join(updated.root, '__snapshots__/basic.test.ts.snap'), 'utf-8')).toMatchInlineSnapshot(` |
| 158 | + "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 159 | +
|
| 160 | + exports[\`a 1\`] = \`0\`; |
| 161 | +
|
| 162 | + exports[\`b 1\`] = \`1\`; |
| 163 | + " |
| 164 | + `) |
| 165 | +}) |
| 166 | + |
| 167 | +test('skipped test does not hide obsolete snapshots of a test with a longer name', async () => { |
| 168 | + const result = await runInlineTests({ |
| 169 | + 'basic.test.ts': ` |
| 170 | + import { expect, it } from 'vitest' |
| 171 | +
|
| 172 | + it.skip('foo', () => { |
| 173 | + expect(0).toMatchSnapshot() |
| 174 | + expect(0).toMatchSnapshot('custom') |
| 175 | + }) |
| 176 | +
|
| 177 | + it('bar', () => { |
| 178 | + expect(1).toMatchSnapshot() |
| 179 | + }) |
| 180 | + `, |
| 181 | + '__snapshots__/basic.test.ts.snap': `// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 182 | +
|
| 183 | +exports[\`bar 1\`] = \`1\`; |
| 184 | +
|
| 185 | +exports[\`foo 1\`] = \`0\`; |
| 186 | +
|
| 187 | +exports[\`foo > custom 1\`] = \`0\`; |
| 188 | +
|
| 189 | +exports[\`foobar 1\`] = \`0\`; |
| 190 | +`, |
| 191 | + }, { update: 'none' }) |
| 192 | + expect(result.errorTree()).toMatchInlineSnapshot(` |
| 193 | + { |
| 194 | + "basic.test.ts": { |
| 195 | + "__module_errors__": [ |
| 196 | + "Obsolete snapshots found when no snapshot update is expected. |
| 197 | + · foobar 1 |
| 198 | + ", |
| 199 | + ], |
| 200 | + "bar": "passed", |
| 201 | + "foo": "skipped", |
| 202 | + }, |
| 203 | + } |
| 204 | + `) |
| 205 | +}) |
0 commit comments