Skip to content

Commit 004e264

Browse files
committed
feat: support update: "none" and add docs about CI behavior
1 parent 3093620 commit 004e264

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

docs/config/update.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ outline: deep
55

66
# update <CRoot /> {#update}
77

8-
- **Type:** `boolean | 'new' | 'all'`
8+
- **Type:** `boolean | 'new' | 'all' | 'none'`
99
- **Default:** `false`
10-
- **CLI:** `-u`, `--update`, `--update=false`, `--update=new`
10+
- **CLI:** `-u`, `--update`, `--update=false`, `--update=new`, `--update=none`
1111

12-
Update snapshot files. The behaviour depends on the value:
12+
Define snapshot update behavior.
1313

14-
- `true` or `'all'`: updates all changed snapshots and delete obsolete ones
14+
- `true` or `'all'`: updates all changed snapshots and deletes obsolete ones
1515
- `new`: generates new snapshots without changing or deleting obsolete ones
16+
- `none`: does not write snapshots and fails on snapshot mismatches, missing snapshots, and obsolete snapshots
17+
18+
When `update` is `false` (the default), Vitest resolves snapshot update mode by environment:
19+
20+
- Local runs (non-CI): works same as `new`
21+
- CI runs (`process.env.CI` is truthy): works same as `none`

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Path to config file
1616
- **CLI:** `-u, --update [type]`
1717
- **Config:** [update](/config/update)
1818

19-
Update snapshot (accepts boolean, "new" or "all")
19+
Update snapshot (accepts boolean, "new", "all" or "none")
2020

2121
### watch
2222

docs/guide/snapshot.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ Or you can use the `--update` or `-u` flag in the CLI to make Vitest update snap
7979
vitest -u
8080
```
8181

82+
### CI behavior
83+
84+
By default, Vitest does not write snapshots in CI (`process.env.CI` is truthy) and any snapshot mismatches, missing snapshots, and obsolete snapshots fail the run. See [`update`](/config/update) for the details.
85+
86+
An **obsolete snapshot** is a snapshot entry (or snapshot file) that no longer matches any collected test. This usually happens after removing or renaming tests.
87+
8288
## File Snapshots
8389

8490
When calling `toMatchSnapshot()`, we store all snapshots in a formatted snap file. That means we need to escape some characters (namely the double-quote `"` and backtick `` ` ``) in the snapshot string. Meanwhile, you might lose the syntax highlighting for the snapshot content (if they are in some language).

examples/basic/test/suite.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('suite name', () => {
77

88
it('bar', () => {
99
expect(1 + 1).eq(2)
10+
expect(3).toMatchInlineSnapshot()
1011
})
1112

1213
it('snapshot', () => {

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
8484
},
8585
update: {
8686
shorthand: 'u',
87-
description: 'Update snapshot (accepts boolean, "new" or "all")',
87+
description: 'Update snapshot (accepts boolean, "new", "all" or "none")',
8888
argument: '[type]',
8989
},
9090
watch: {

packages/vitest/src/node/config/resolveConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ export function resolveConfig(
566566
expand: resolved.expandSnapshotDiff ?? false,
567567
snapshotFormat: resolved.snapshotFormat || {},
568568
updateSnapshot:
569-
UPDATE_SNAPSHOT === 'all' || UPDATE_SNAPSHOT === 'new'
569+
UPDATE_SNAPSHOT === 'all' || UPDATE_SNAPSHOT === 'new' || UPDATE_SNAPSHOT === 'none'
570570
? UPDATE_SNAPSHOT
571571
: isCI && !UPDATE_SNAPSHOT ? 'none' : UPDATE_SNAPSHOT ? 'all' : 'new',
572572
resolveSnapshotPath: options.resolveSnapshotPath,

packages/vitest/src/node/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export interface InlineConfig {
380380
*
381381
* @default false
382382
*/
383-
update?: boolean | 'all' | 'new'
383+
update?: boolean | 'all' | 'new' | 'none'
384384

385385
/**
386386
* Watch mode

0 commit comments

Comments
 (0)