Skip to content

vitest v3 throws with jest-image-snapshot. #7322

@nnaku

Description

@nnaku

Describe the bug

Hello, it seem that recent changes in snapshot state #6817 broke some custom and third party snapshot matchers. For example using jest-image-snapshot with v3 results to error be thrown from vitest internals.

Opening issue because I was asked to do so. #6817 (comment)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: this.matched.total is not a function
 ❯ SnapshotState.pack node_modules/@vitest/snapshot/dist/index.js:2099:37
 ❯ processTicksAndRejections node:internal/process/task_queues:105:5
 ❯ SnapshotClient.finish node_modules/@vitest/snapshot/dist/index.js:2141:20
 ❯ VitestTestRunner.onAfterRunSuite node_modules/vitest/dist/runners.js:179:22
 ❯ runSuite node_modules/@vitest/runner/dist/index.js:1330:5
 ❯ runFiles node_modules/@vitest/runner/dist/index.js:1356:5
 ❯ startTests node_modules/@vitest/runner/dist/index.js:1366:3
 ❯ node_modules/vitest/dist/chunks/runBaseTests.Ba8jtu6O.js:129:11
 ❯ withEnv node_modules/vitest/dist/chunks/runBaseTests.Ba8jtu6O.js:92:5
 ❯ run node_modules/vitest/dist/chunks/runBaseTests.Ba8jtu6O.js:117:3

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯


 Test Files   (1)
      Tests   (1)
     Errors  1 error
   Start at  12:05:47
   Duration  23ms

 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit

Reproduction

import { describe, expect, it } from "vitest";
import { toMatchImageSnapshot } from "jest-image-snapshot";
import fs from "fs";
expect.extend({ toMatchImageSnapshot });

describe("Test", () => {
  it("should match image snapshot", async () => {
    const image = fs.readFileSync("./image.png");
    expect(image).toMatchImageSnapshot();
  });
});

cant upload images to stackbliz 😢

System Info

System:
    OS: macOS 14.7.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 235.53 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v22.13.0/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
    bun: 1.0.0 - ~/.bun/bin/bun
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 119.1.60.118
    Chrome: 132.0.6834.83
    Safari: 17.6
  npmPackages:
    vitest: ^3.0.2 => 3.0.2

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    P2 - 3

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions