Skip to content

Extremely slow for huge snapshots mismatch #2764

Closed
@Maxim-Mazurok

Description

Describe the bug

I have a huge snapshot (38k lines JS Map), when I run vitest in either dev or run modes - it takes insane amount of time to get response, one might think that it just hangs.

Reproduction

My test:

import { it, describe, expect } from "vitest";

describe("something", () => {
  it("works", () => {
    expect(something()).toMatchSnapshot();
  });
});

My snapshot:

// Vitest Snapshot v1

exports[`something > works 1`] = `
Map {
  "Cucumber Lebanese" => [
    {
      "amountPerUnit": 5,
      "dateTime": "2020-01-01T01:01:00.000Z",
      "item": {
        "amount": 1,
        "description": "Cucumber Lebanese",
        "onSpecial": false,
        "productSeries": "Cucumber Lebanese",
        "quantity": 1,
      },
    },
    // repeat 3 times
    }
  ],
  // repeat 1000 times

When I run tests, I get this:

 FAIL  util.spec.ts > something > works
AssertionError: Snapshot `something > works 1` mismatched
 ❯ util.spec.ts:6:42
      4| describe("something", () => {
      5|   it("works", () => {
      6|     expect(something()).toMatchSnapshot();
       |                                          ^
      7|   });
      8| });

and then the process keeps on running while using ~10-20% of CPU.

After a long time I think the process fails with non-zero code without showing diff, but I'm not 100% sure about that.

Might be related to #2008

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 32.59 GB / 63.68 GB
  Binaries:
    Node: 19.3.0 - ~\AppData\Local\nvs\node\19.3.0\x64\node.EXE
    npm: 9.2.0 - ~\AppData\Local\nvs\node\19.3.0\x64\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.76)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions