Skip to content

fix: locate inline snapshots on Windows - #2292

Merged
dprevost-LMI merged 5 commits into
webdriverio:v7from
dprevost-LMI:fix/v7-inline-snapshot-windows-stack
Oct 1, 2026
Merged

dprevost-LMI merged 5 commits into
webdriverio:v7from
dprevost-LMI:fix/v7-inline-snapshot-windows-stack

Conversation

@dprevost-LMI

@dprevost-LMI dprevost-LMI commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Proposed changes

Found with the multi-remote e2e of webdriverio/webdriverio#15838, which fails on Windows only:

Error: expect(received).toBe(expected)
- "<h1>WebdriverJS Testpage</h1>"
+ { "browserA": "<h1 data-locale="en">…", … }

The expected value is the snapshot of the other toMatchInlineSnapshot call in the same file.

Cause: toMatchInlineSnapshot removes its own stack frames, so that Vitest's snapshot manager takes the frame of the test as the snapshot location (__INLINE_SNAPSHOT__ + 2). It found them with path.sep. But Node prints the frames of an ES module as file:/// URLs, with / also on Windows. So on Windows:

  1. The lib/matchers/snapshot.js frame stays in the stack.
  2. Every inline snapshot of a file gets the same location: a frame in the expect package.
  3. @vitest/snapshot throws "toMatchInlineSnapshot with different snapshots cannot be called at the same location" for the second different snapshot, with the first snapshot as expected.

The jasmine-core filter had the opposite problem: it only matched node_modules/jasmine-core/, but Windows paths use \.

Fix:

  • Both filters accept / and \.
  • They move to filterInlineSnapshotStack in src/util/stackUtil.ts, so they can be unit-tested. The unit tests load src/, where the lib/ frame filter never matches.

main (v8) has the same code. I will port the fix after this PR.

How you tested

  • New test/util/stackUtil.test.ts: for POSIX paths, Windows paths and file:/// URLs (Windows and POSIX), the location that Vitest takes is the test frame, and jasmine-core frames are removed. With the old filter and the Windows path.sep, the Windows file:/// URL case and the Windows jasmine-core case fail.
  • With the real @vitest/snapshot 4.1.11 _resolveInlineStack, I simulated 2 different inline snapshots at lines 76 and 208:
    • macOS-style frames → 2 locations (:76, :208)
    • Windows file:/// frames with the old filter → the same error as the CI log, expected = the line 76 snapshot
  • Unit suite (48 files, 2635 tests), lint, tsc and build pass. In the first full run, toHaveHTML.test.ts failed once at the file level. 2 more full runs passed, and the file passes alone with and without this change.
  • New test in test/snapshot.test.ts: two different inline snapshots in one test, through the real matcher and snapshot client. With one extra matcher frame left in the stack, it fails with the "same location" error. The existing tests did not catch that (one snapshot per test, or equal snapshots).

🤖 Generated with Claude Code

The inline snapshot matcher removes its own stack frames, so that
Vitest's snapshot manager takes the frame of the test as the snapshot
location. It found them with `path.sep`, but Node prints the frames of
an ES module as `file:///` URLs, with `/` also on Windows. So on Windows
the frames stayed, every inline snapshot of a file got the same location
(a frame in the `expect` package), and the second different snapshot
failed with "toMatchInlineSnapshot with different snapshots cannot be
called at the same location". The jasmine-core filter had the opposite
problem: it only matched `/`, but Windows paths use `\`.

Both filters now accept `/` and `\`. They move to `filterInlineSnapshotStack`
in `src/util/stackUtil.ts`, with unit tests for POSIX paths, Windows
paths and `file:///` URLs.

Found with the multi-remote e2e of webdriverio/webdriverio#15838.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dprevost-LMI
dprevost-LMI marked this pull request as ready for review October 1, 2026 02:05
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes inline snapshot location detection on Windows.

The PR appears safe to merge; no outstanding finding or new actionable issue remains.

Findings

  1. P2 Fast-failure check loses coverage ▶

Summary

The PR makes inline-snapshot stack filtering accept Windows paths and file URLs, adds regression coverage, and runs the multi-remote playground on Windows. The latest change replaces a fixed timing threshold with a comparison against an explicit short-wait assertion.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Inline snapshot call] --> B[Matcher stack]
  B --> C[Filter matcher and Jasmine frames]
  C --> D[Test call-site frame]
  D --> E[Snapshot client location]
Loading

Reviews (5) · Last reviewed commit: "test(playgrounds): compare the multi-rem..."

Comment thread test/util/stackUtil.test.ts Resolved
dprevost-LMI and others added 3 commits September 30, 2026 22:09
The new stackUtil tests build their own frames. This test goes through
the real matcher and the snapshot client: if a frame of the matcher stays
in the stack, both calls get the same location, and the second one fails
with "toMatchInlineSnapshot with different snapshots cannot be called at
the same location". The other tests have one snapshot per test, or equal
snapshots, so they did not catch a wrong location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inline snapshot bug of this PR showed only on Windows, where the
stack frames are `\` paths or `file:///` URLs, and all CI jobs run on
ubuntu. The multi-remote-mocha playground runs the built `lib/` and has
8 different inline snapshots in `snapshot.test.ts`, so on Windows it
fails with "toMatchInlineSnapshot with different snapshots cannot be
called at the same location" without the fix.

The job sets npm's `script-shell` to Git Bash, because the root
`compile:check` script, run when the playgrounds install, uses POSIX
shell syntax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test checks that `setDefaultOptions({ wait: 1 })` makes a failing
assertion fast. It required less than 500ms, but one multi-remote
assertion queries every browser, and on the new Windows job it took
817ms (10 browsers share the runner). Require less than half of the
default wait (5000ms), which still fails if the global option is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eline

The 5000ms limit did not catch an ignored `setDefaultOptions({ wait: 1 })`:
the playground's own default wait is 1000ms, so the assertion still passed.
Measure the same failing assertion with an explicit `wait: 1` first, and
require the global-option run to stay within 500ms of it. This keeps the
Windows margin (one assertion queries every browser) and fails again when
the global option is ignored (1057ms against a 614ms limit locally).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dprevost-LMI
dprevost-LMI merged commit 127c53e into webdriverio:v7 Oct 1, 2026
11 checks passed
dprevost-LMI added a commit that referenced this pull request Oct 1, 2026
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
dprevost-LMI added a commit to dprevost-LMI/webdriverio that referenced this pull request Oct 1, 2026
expect-webdriverio 7.0.1 locates inline snapshots on Windows
(webdriverio/expect-webdriverio#2292), so the skip is not necessary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dprevost-LMI added a commit to dprevost-LMI/webdriverio that referenced this pull request Oct 1, 2026
7.0.1 locates inline snapshots on Windows, where ES module stack frames
are `file:///` URLs (webdriverio/expect-webdriverio#2292).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dprevost-LMI added a commit to webdriverio/webdriverio that referenced this pull request Oct 1, 2026
* Upgrade to expect-wdio 7 for multiRemote support

* feat(@wdio/globals): expose expect.multiRemote and add multiremote expect e2e

- Proxy `expect.multiRemote()` from `@wdio/globals` to expect-webdriverio v7
- Add an e2e spec that covers the multiremote matchers
- Document multiremote assertions in the Multiremote guide

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: require webdriverio 9.31.5 where expect-webdriverio 7 is used

expect-webdriverio 7 has the peer `webdriverio: ^9.31.5`: its
multi-remote matchers need the multi-remote `select` changes of #15538.
@wdio/globals, @wdio/runner, @wdio/browser-runner and
@wdio/jasmine-framework still accepted `^9.28.0`, so webdriverio
9.28.0 to 9.31.4 satisfied them but not expect-webdriverio. The
lockfile also resolved webdriverio 9.31.2 for @wdio/globals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): skip the per-instance inline snapshot test on Windows

On Windows, expect-webdriverio 7.0.0 does not remove its own stack
frames from the inline snapshot error: it filters them with `path.sep`,
but ES module frames are `file:///` URLs with `/`. So every inline
snapshot of the file resolves to the same frame in the `expect` package,
and the second one fails with "toMatchInlineSnapshot with different
snapshots cannot be called at the same location" (expected: the first
snapshot). Skip the test on win32 until expect-webdriverio has the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(e2e): run the per-instance inline snapshot test on Windows again

expect-webdriverio 7.0.1 locates inline snapshots on Windows
(webdriverio/expect-webdriverio#2292), so the skip is not necessary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(deps): update expect-webdriverio to 7.0.1

7.0.1 locates inline snapshots on Windows, where ES module stack frames
are `file:///` URLs (webdriverio/expect-webdriverio#2292).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(@wdio/globals): build against the workspace webdriverio

`@wdio/globals` had `webdriverio` only as a peer dependency, so pnpm
installed it from npm. With the `^9.31.5` peer range, that is
`webdriverio@9.32.0`, which declares
`getInstance(): WebdriverIO.Browser | undefined`. These global types
merged into the build of the services, and `@wdio/testingbot-service`
and `@wdio/shared-store-service` failed with "Object is possibly
'undefined'".

Add `webdriverio: workspace:*` as a devDependency, as
`@wdio/browser-runner` does, so the build uses the workspace package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants