feat(mock-e2e): browser E2E harness + createMockClient testing export#261
feat(mock-e2e): browser E2E harness + createMockClient testing export#261decrypto21 wants to merge 1 commit into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning [Security] Socket has found a problem with the dependencies from this PR. Check the details below to solve the issue. If the affected dependency is unreachable, we still recommend you to use a patched version. Remember: according to Parity's Security Policy, you must resolve all "Block" alerts before proceeding. It is recommended to resolve "Warn" alerts too. Learn more about Socket for GitHub.
|
Resolves #260 (the browser-E2E follow-up). Stacked on #258.
Summary
On top of the mock host from #258, this adds the highest-fidelity proof and the ergonomic entry point that were left as follow-ups:
@parity/truapi-mock-e2e— a private workspace package that drives a product against the mock host in a real browser: the realtruapi-serverWASM core runs in aWeb Worker, the product runs in aniframeand connects via the SDK's realgetClientSync()sandbox path over a realMessageChannel, and Playwright drives it headless. This is a level above the headlesswasm-bridge.test.ts(which stops at the JS↔SCALE↔WASM boundary): it exercises the full production transport, with no mock code in the product.createMockClient— a@parity/truapi-host-wasm/testingsubpath export that collapsescreateMockHost+createWebWorkerProvider+createClientinto one call, returning the product client plus the mock for assertions.mock-e2eCI job that builds the WASM + workspace packages, installs Chromium, and runs the Playwright suite.The harness resolves its dependencies through the npm workspace, so it runs anywhere the repo does — no machine-specific paths.
What's in it
@parity/truapi-mock-e2e— new private (unpublished) packageA Vite + React browser harness with two topologies:
src/main.tsx): host + product in one page, wired with a singlecreateMockClient()call.src/host.tsx+src/product.tsx): mirrors production embedding — the host boots the core +createIframeHost; the product runs in aniframewith no mock code, connecting throughgetClientSync().Files:
package.json,tsconfig.json,vite.config.ts,playwright.config.ts,index.html/host.html/product.html,src/{main,host,product}.tsx,tests/e2e.spec.ts,README.md,.gitignore.@parity/truapi-host-wasm—src/testing.ts(new./testingexport)createMockClient(worker, config?)→{ client, mock }. ComposescreateMockHost+createWebWorkerProvider+createClient(createTransport(...)); the caller supplies the coreWorkerso their bundler owns how it's produced.clientis the exact object a product uses in production;mockexposes the recorded oracles for assertions.Public API:
createMockClient,MockClient.Why it's additive (and what it proves)
wasm-bridge.test.ts(feat: mock platform #258) proves the SCALE bridge decodes/dispatches, but with no realWeb Worker, noiframe, and no product transport. This harness closes that gap: a real product, in a real browser, over the production transport, reaching the real core only throughgetClientSync().createMockClientmakes "switch a product to mock mode" a one-liner. It is dogfooded by the single-page harness and has executing runtime coverage via test (2) below — not just typecheck.Verification
All green locally (this is the executed state, not aspiration):
codegen→ build@parity/truapi→ build@parity/truapi-host-wasm(compilescreateMockClient) — pass.tsctypecheck of the harness (@parity/truapi-mock-e2e) — pass.make wasm/build:wasm—truapi_server_bg.wasm≈ 1.96 MB.createMockClientat runtime.mock-e2ejob — not yet run in CI (branch verified locally only; CI runs it on first push).CI
A new
mock-e2ejob (needs: codegen): downloads the codegen artifact,npm ci, builds@parity/truapi, installswasm-pack 0.15.0, runsbuild:wasm, builds@parity/truapi-host-wasm, installs Chromium (npx playwright install --with-deps chromium), then runs the Playwright suite; the report is uploaded on failure.Deliberately not a required gate yet:
mock-e2eis omitted from theci-statusneedsand results (with an explaining comment) — it runs for signal but neither gates merges nor makes the aggregate status wait on its (up to 30-min) run. Promote it into the gate once it has a green CI baseline.Dependencies
react/react-dom/vite/@vitejs/plugin-react/@playwright/test/typescript/@types/*— all harness/dev scoped to the unpublished package and hoisted at the workspace root. No new runtime dependency for any shipped package.@parity/truapi-host-wasm: one new subpath export (./testing);createMockClientimportscreateClient/createTransportfrom@parity/truapi, already a dependency — no new host-wasm dep.package-lock.jsonrefreshed for the new workspace member.