{{ message }}
Repository navigation
fix(browser-runner): hoist mocks before side-effect imports - #16112
Open
carrerasdarren-cell wants to merge 1 commit into
Open
carrerasdarren-cell wants to merge 1 commit into
carrerasdarren-cell wants to merge 1 commit into
Conversation
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Proposed changes
Fixes #12624. A side-effect-only import in a factory-mocked component spec stays static today, so its module evaluates before the hoisted mock factory. A custom element can therefore capture the real dependency even though the equivalent binding import sees the mock.
Rewrite bare imports in the active spec as sequential
await import(...)expressions at their original positions. Dependency-level bare imports remain static, and specs without factory mocks retain their original code. The existing actual-module fallback is preserved. Add transform regressions and six separate component specs, wired into the normal browser-test chain.How you tested
pnpm run test:package wdio-browser-runner: 115 tests across 15 files passed, including explicit transform ordering, no-factory/manual/unmock controls and valid actual-namespace fallback.pnpm --dir e2e run test:browser:module-mocks: all six final component specs passed in Chrome 158 with standard coverage enabled (100% statements, branches, functions and lines). They cover an asynchronous factory, mixed bare/binding import order, single evaluation after a duplicate import, directly mocked bare imports with and without an actual-module argument, and real/no-mock behavior.pnpm exec tsc --noEmit -p packages/wdio-browser-runner/tsconfig.json,pnpm run test:oxlint, and focused oxlint for all 13 added component/spec JavaScript files passed.pnpm run test:componentcommand exits 1 at two existing Vue multi-element matcher assertions. Continuing the skipped standard lanes passed Svelte, Lit and Stencil; misc passed its four browser-error tests and five network-mock tests but failed two existing image-size assertions. The uncaught-error checker passed its expected two passing/one failing scenario. Both failure families reproduced with the original3b5e5dftransform after recompiling in the same configuration/dependency/Chrome environment: the same two Vue failures and the same two image dimensions (256×213 and 256×256). The reviewed fix and deterministic compiled bundle were then restored byte-for-byte. The full component suite is not claimed to pass.All local component runs used Chrome with
CIunset. The permanent specs retain browser-independent marker assertions.Types of changes
Checklist
Backport Request
Further comments
Implemented and tested with OpenAI Codex assistance. No v9 backport was evaluated. This change preserves actual-module evaluation for factories that request it, rather than introducing a new promise to suppress real-module side effects.