Skip to content

Commit

Permalink
fix(vitest): delegate snapshot options to workspace from root config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 16, 2024
1 parent 2b0abb3 commit 86297d4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vitest/src/node/workspace.ts
Expand Up @@ -358,7 +358,8 @@ export class WorkspaceProject {
},
},
snapshotOptions: {
...this.config.snapshotOptions,
...this.ctx.config.snapshotOptions,
expand: this.config.snapshotOptions.expand ?? this.ctx.config.snapshotOptions.expand,
resolveSnapshotPath: undefined,
},
onConsoleLog: undefined!,
Expand Down
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`basic 1`] = `1`;
@@ -0,0 +1,5 @@
import { test, expect } from "vitest"

test("basic", () => {
expect(1).toMatchSnapshot()
})
@@ -0,0 +1,5 @@
import { defineProject } from 'vitest/config'

export default defineProject({
test: {},
})
5 changes: 5 additions & 0 deletions test/snapshots/test/fixtures/workspace/vitest.workspace.ts
@@ -0,0 +1,5 @@
import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
'packages/*',
])
19 changes: 19 additions & 0 deletions test/snapshots/test/workspace.test.ts
@@ -0,0 +1,19 @@
import { expect, test } from 'vitest'
import { editFile, runVitest } from '../../test-utils'

test('--update works for workspace project', async () => {
// setup wrong snapshot value
editFile(
'test/fixtures/workspace/packages/space/test/__snapshots__/basic.test.ts.snap',
data => data.replace('`1`', '`2`'),
)

// run with --update
const { stdout, exitCode } = await runVitest({
update: true,
root: 'test/fixtures/workspace',
workspace: 'vitest.workspace.ts',
})
expect.soft(stdout).include('Snapshots 1 updated')
expect.soft(exitCode).toBe(0)
})

0 comments on commit 86297d4

Please sign in to comment.