js-sdk: run the msw-mocked suites in the browser leg - #1871
js-sdk: run the msw-mocked suites in the browser leg#1871devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Add a runtime-aware setupMockApi helper: msw/node's setupServer on Node and the compat runtimes, msw/browser's setupWorker behind a Service Worker in Chromium. The browser vitest config swaps the module and serves mockServiceWorker.js from the installed msw package. Port the ten suites that imported msw/node directly and drop them from the browser exclude list. Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Package ArtifactsBuilt from 87518c4. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.48.1-devin-1789147597-browser-msw-worker.0.tgzCLI ( npm install ./e2b-cli-2.18.3-devin-1789147597-browser-msw-worker.0.tgzCode Interpreter JS SDK ( npm install ./e2b-code-interpreter-2.8.1-devin-1789147597-browser-msw-worker.0.tgzDesktop JS SDK ( npm install ./e2b-desktop-2.4.1-devin-1789147597-browser-msw-worker.0.tgzPython SDK ( pip install ./e2b-2.48.0+devin.1789147597.browser.msw.worker-py3-none-any.whlCode Interpreter Python SDK ( pip install ./e2b_code_interpreter-2.10.0+devin.1789147597.browser.msw.worker-py3-none-any.whlDesktop Python SDK ( pip install ./e2b_desktop-2.5.0+devin.1789147597.browser.msw.worker-py3-none-any.whl |
There was a problem hiding this comment.
TASTE.md review — no violations found.
The diff is test infrastructure only (tests/mockApi.ts, tests/runtimes/browser/mockApi.ts, the browser vitest config, and the import swap in the ten msw suites) — no public SDK surface changes, so most of TASTE.md doesn't bind here. Checked anyway against the rules that could apply to new SDK-owned code: T-1/T-2 (no JS-only behavior added that needs a Python mirror — this is JS test tooling), T-3/T-3a (setupMockApi(...handlers) mirrors setupServer; listen(options?) keeps optionals in a trailing object), T-12 (MockApi, nodeMockApi, browserMockApi case the acronym as a word; the all-caps secretID/volumeID are wire fields, which T-12 explicitly exempts), T-19 (MockApi is a type, not a class), T-20 (resolveId returns undefined, not null), T-54 (nothing added to the package entry point), T-56 (msw's worker script is resolved from the installed package rather than pinned/copied, so no version string is hardcoded).
Two notes that are deliberate rather than violations: the listen/close pair reads against T-30 ("what you start, you stop"), but T-30 governs SDK *Handle classes and close() is the right name when mirroring the wrapped msw SetupServer/SetupWorker API — consistency with the library beats local optimality. And test.skipIf(runtime === 'browser') on client.Template builds template instances is a test-harness exclusion, not a parity break in the surface itself (the builder is Node-only for the same reason tests/template/** is excluded).
Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
Summary
Follow-up to #1609. The ten suites that mock the API with msw (
client,abortSignal,egressProxy,iam,lifecycleRequest,networkTransform,onResumeRequest,secret,volume,volume/file— 181 tests) were excluded from the browser leg only because they importedmsw/node, whose entry pulls innode:http. The SDK code they cover (Secrets, Volumes, cancellation, workload identity, lifecycle/network request shapes,E2Bclient binding) is browser-runnable, so this makes them run in Chromium too, unchanged for Node/Bun/Deno/Workers.Runtime-aware helper. The suites now import
setupMockApifromtests/mockApi.tsinstead ofsetupServerfrommsw/node:tests/mockApi.tswrapssetupServer(Node and the compat runtimes).tests/runtimes/browser/mockApi.tswrapssetupWorkerfrommsw/browser(listen → worker.start({ quiet: true }),close → worker.stop()).The browser vitest config gets a small
enforce: 'pre'Vite plugin that resolves any import oftests/mockApi.tsto the browser implementation, and serves/mockServiceWorker.jsstraight fromnode_modules/msw/lib/(no checked-in copy to drift from the msw version). The ten suites are dropped from the browserexcludelist.Per-suite diff is the import swap +
setupServer(...)→setupMockApi(...);listen/closewere already called frombeforeAll/afterAllso awaiting them needed no restructuring.secret,volumeandmockVolumeContentswapnode:cryptorandomUUID()forcrypto.randomUUID(). One test inclient.test.ts(client.Template builds template instances) isskipIf(runtime === 'browser'): the template builder is Node-only (node:path), same reasontests/template/**is excluded.Verified
No SDK source changes, so no changeset.
Link to Devin session: https://app.devin.ai/sessions/5c01919711e14a1a8ec90fba1505e4e8
Open in Devin Desktop: https://app.devin.ai/desktop/session/5c01919711e14a1a8ec90fba1505e4e8?variant=devin
Requested by: @mishushakov