Skip to content

Commit 86297d4

Browse files
authoredFeb 16, 2024··
fix(vitest): delegate snapshot options to workspace from root config (#5199)
1 parent 2b0abb3 commit 86297d4

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed
 

‎packages/vitest/src/node/workspace.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ export class WorkspaceProject {
358358
},
359359
},
360360
snapshotOptions: {
361-
...this.config.snapshotOptions,
361+
...this.ctx.config.snapshotOptions,
362+
expand: this.config.snapshotOptions.expand ?? this.ctx.config.snapshotOptions.expand,
362363
resolveSnapshotPath: undefined,
363364
},
364365
onConsoleLog: undefined!,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`basic 1`] = `1`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test, expect } from "vitest"
2+
3+
test("basic", () => {
4+
expect(1).toMatchSnapshot()
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineProject } from 'vitest/config'
2+
3+
export default defineProject({
4+
test: {},
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineWorkspace } from 'vitest/config'
2+
3+
export default defineWorkspace([
4+
'packages/*',
5+
])

‎test/snapshots/test/workspace.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from 'vitest'
2+
import { editFile, runVitest } from '../../test-utils'
3+
4+
test('--update works for workspace project', async () => {
5+
// setup wrong snapshot value
6+
editFile(
7+
'test/fixtures/workspace/packages/space/test/__snapshots__/basic.test.ts.snap',
8+
data => data.replace('`1`', '`2`'),
9+
)
10+
11+
// run with --update
12+
const { stdout, exitCode } = await runVitest({
13+
update: true,
14+
root: 'test/fixtures/workspace',
15+
workspace: 'vitest.workspace.ts',
16+
})
17+
expect.soft(stdout).include('Snapshots 1 updated')
18+
expect.soft(exitCode).toBe(0)
19+
})

0 commit comments

Comments
 (0)
Please sign in to comment.