Skip to content

Updating inline snapshot passes without actually updating code in Browser Mode when slowHijackESM: true #5280

@hi-ogawa

Description

@hi-ogawa

Describe the bug

See #5278 (comment)

Currently inline snapshot update is not working due to #5263, but even after the fix #5278, it's still not working when slowHijackESM: true for a different reason.

It looks like there's something wrong with stacktrace and it's not finding the right position. I was debug logging around here:

private _addSnapshot(
key: string,
receivedSerialized: string,
options: { isInline: boolean; rawSnapshot?: RawSnapshotInfo; error?: Error },
): void {
this._dirty = true
if (options.isInline) {
const stacks = parseErrorStacktrace(options.error || new Error('snapshot'), { ignoreStackEntries: [] })
const stack = this._inferInlineSnapshotStack(stacks)

Reproduction

  1. Replace the following code with expect(2).toMatchInlineSnapshot('1'):

test('inline snapshot', () => {
expect(1).toMatchInlineSnapshot('1')
})

  1. Run test
$ pnpm -C test/browser test-fixtures run -u test/snapshot.test.ts -t inline
...

 ✓ test/snapshot.test.ts (3)
   ✓ inline snapshot
   ↓ snapshot [skipped]
   ↓ file snapshot [skipped]

  Snapshots  1 updated 
 Test Files  1 passed (1)
      Tests  1 passed | 2 skipped (3)
   Start at  17:47:52
   Duration  1.22s (transform 0ms, setup 0ms, collect 13ms, tests 7ms, environment 0ms, prepare 0ms)
  1. See test/snapshot.test.ts still has expect(2).toMatchInlineSnapshot('1')

System Info

System:
    OS: Linux 6.7 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5625U with Radeon Graphics
    Memory: 4.23 GB / 14.98 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 18.19.0 - ~/.volta/tools/image/node/18.19.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 10.2.3 - ~/.volta/tools/image/node/18.19.0/bin/npm
    pnpm: 8.10.3 - ~/.volta/tools/image/node/18.19.0/bin/pnpm
    bun: 1.0.26 - ~/.volta/bin/bun
  Browsers:
    Chromium: 122.0.6261.57
  npmPackages:
    @vitest/browser: workspace:* => 1.3.1 
    @vitest/coverage-istanbul: workspace:* => 1.3.1 
    @vitest/coverage-v8: workspace:* => 1.3.1 
    @vitest/ui: workspace:* => 1.3.1 
    vite: ^5.0.12 => 5.0.12 
    vitest: workspace:* => 1.3.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

Labels

feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

Type

No type

Projects

Status

Has plan

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions