Skip to content

Crash when printing diff of playwright ElementHandle #7009

@hi-ogawa

Description

@hi-ogawa

Describe the bug

(related: #7092)

I had an odd error in Vite playground test https://github.com/vitejs/vite/blob/ccee3d7c7d34fc66854029f27f6cc89de7dcf3c5/playground/html/__tests__/html.spec.ts#L187 and this is probably because of diffing (not sure if chai or pretty-format) failing to handle a large cyclic object.

Minimal repro:

  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto("https://vitest.dev/");
  expect(await page.$("h1")).toBeNull(); // this fails and tries to show diff
 DEV  v2.1.6 /home/hiroshi/code/personal/reproductions/vitest-diff-crash-playwright

 ❯ src/basic.test.ts (1)
   ⠦ basic

<--- Last few GCs --->

[73555:0x26860000]     6761 ms: Scavenge (interleaved) 1278.9 (1325.1) -> 1274.3 (1325.1) MB, pooled: 0 MB, 0.95 / 0.01 ms  (average mu = 0.868, current mu = 0.821) allocation failure; 
[73555:0x26860000]     6789 ms: Mark-Compact 1286.1 (1336.9) -> 240.4 (286.2) MB, pooled: 1050 MB, 12.75 / 0.00 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 32 ms) (average mu = 0.972, current mu = 

<--- JS stacktrace --->

FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory

Not sure if this is fixable if the object is simply too large, but it's worth investigating this.

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/vitest-diff-crash-playwright

System Info

System:
    OS: Linux 6.12 Arch Linux
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 18.38 GB / 31.05 GB
    Container: Yes
    Shell: 5.2.37 - /usr/bin/bash
  Binaries:
    Node: 22.11.0 - ~/.volta/tools/image/node/22.11.0/bin/node
    npm: 10.9.0 - ~/.volta/tools/image/node/22.11.0/bin/npm
    pnpm: 10.0.0-beta.1 - ~/.volta/bin/pnpm
    bun: 1.1.29 - ~/.volta/bin/bun
  Browsers:
    Chromium: 131.0.6778.85
  npmPackages:
    vitest: 2.1.6 => 2.1.6

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