Skip to content

vitest run --update doesn't work for workspaces #5194

@glacius-mitchell

Description

@glacius-mitchell

Describe the bug

Running vitest run --update within a monorepo that's configured to use a workspace (https://vitest.dev/guide/workspace.html) doesn't update any snapshots.

I've included a link to a minimal reproduction of this issue on StackBlitz below. It's a pnpm monorepo with a single package containing a single failing snapshot test.

Running pnpm run test:run:update yields the following output:

❯ pnpm run test:run:update

> @ test:run:update /home/projects/vitest-dev-vitest-21kers
> vitest run --update


 RUN  v1.2.2 /home/projects/vitest-dev-vitest-21kers

 ❯ |test-package| snapshot.test.ts (1)
   × snapshot

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  |test-package| snapshot.test.ts > snapshot
Error: Snapshot `snapshot 1` mismatched

- Expected
+ Received

- "original"
+ "updated"

 ❯ eval snapshot.test.ts:4:21
      2| 
      3| test('snapshot', () => {
      4|   expect('updated').toMatchSnapshot();
       |                     ^
      5| });
      6| 

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

  Snapshots  1 failed
 Test Files  1 failed (1)
      Tests  1 failed (1)
   Start at  10:34:49
   Duration  1.18s (transform 279ms, setup 0ms, collect 282ms, tests 7ms, environment 0ms, prepare 192ms)

 ELIFECYCLE  Command failed with exit code 1.

Observe that the test fails but the snapshot is not updated, despite using the --update flag.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-21kers?file=package.json

System Info

$ pnpm dlx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers
Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done

  System:
    OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (12) arm64 unknown
    Memory: 5.87 GB / 7.66 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 21.6.1 - /usr/local/share/nvm/versions/node/v21.6.1/bin/node
    npm: 10.2.4 - /usr/local/share/nvm/versions/node/v21.6.1/bin/npm
    pnpm: 8.15.1 - /usr/local/share/nvm/versions/node/v21.6.1/bin/pnpm
  npmPackages:
    vitest: 1.2.2 => 1.2.2

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions