Skip to content

Commit 80496c0

Browse files
mishushakovclaude
andauthored
test(js-sdk): run the full unit test suite in a browser (#1609)
> [!NOTE] > **Both upstream blockers have rolled out — the browser leg is green, with nothing gated or skipped for being a browser.** > > | needed | blocked | status | > | --- | --- | --- | > | ~~[infra#3388](e2b-dev/runtime@e832b1ed40f488dd1159fdece027bad004522be0)~~ | ~~6 `Sandbox.list({ limit })` pagination tests~~ | **rolled out 2026-07-24** | > | ~~[belt#2068](e2b-dev/belt#2068 | ~~13 stopped-sandbox tests~~ | **rolled out 2026-08-26** | > | ~~belt#2068 on the **traffic-token path**~~ | ~~`sandbox requires traffic access token`~~ | **rolled out — the test passes as of 2026-09-09** | > > The 15th failure was **not** an infra problem and is **fixed in this PR** (`1964dde`) — see [the browser's connection-drop wording](#sdk-294) below. > > `pnpm test:browser` against production, 2026-09-09: **77 files (76 passed, 1 skipped), 424 tests (420 passed, 4 skipped), 0 failing**, 143s. The last gap — the proxy answering a traffic-token `403` and its preflight without CORS headers — is closed on the orchestrator side, so `sandbox requires traffic access token` now reads the `403` from Chromium as intended. It was deliberately left un-gated rather than skipped, so the leg went green on its own the moment the rollout completed. The Node suite is green on the same tree (`--project unit --project connectionConfig`: 88 files, 614 passed, 1 skipped). Staging Node legs may still fail repo-wide for reasons unrelated to this branch (staging template builder returning `template builder not found`, staging auto-pause losing sandboxes). ## What Promotes the browser leg from a single React smoke test to the **full unit + connectionConfig suite running inside a real headless Chromium** (`@vitest/browser` + Playwright) — the same coverage `test:bun` / `test:deno` / `test:cf` get. **77 files, 76 passing** against production, nothing red. The one skipped file is `tests/runtime.test.ts`, whose two tests assert Node/Workers runtime *detection* off `process.release` and so have nothing to assert on a browser host. ```bash pnpm test:browser # installs Chromium via pretest:browser, then runs the suite ``` React is gone as requested — the smoke test (`tests/runtimes/browser/run.test.tsx`) and its seven devDependencies (`react`, `react-dom`, `@types/react`, `@types/react-dom`, `@testing-library/react`, `@vitejs/plugin-react`, `vitest-browser-react`). Chromium installation moves off the default `pretest` hook onto `pretest:browser`, so plain `pnpm test` no longer downloads a browser. The one thing the smoke test uniquely covered — the SDK driven with **no `process` global at all**, the way a real browser bundle runs — is kept as a dedicated test, since the rest of the suite runs against a `process.env` shim that would mask a regression there: ```ts // tests/runtimes/browser/noProcessGlobal.test.ts Reflect.deleteProperty(globalThis, 'process') const sandbox = await Sandbox.create(template, { apiKey, domain }) await sandbox.files.write('hello.txt', 'Hello World') ``` Failure screenshots are off (`browser.screenshotFailures: false`): these tests never render anything, so vitest's default would write a PNG of a blank page per failed test into `.vitest-attachments/`. ## Test bugs the leg surfaced 1. **Two assertions were vacuous.** `commands/kill` and `pty/kill` asserted `rejects.toThrowError(ProcessExitError)` — but `ProcessExitError` has never been exported from `src`. Vite's SSR transform resolves the missing named import to `undefined`, so `toThrowError(undefined)` asserted nothing on *any* runtime; real ESM in the browser turns it into a hard `SyntaxError`. Now `CommandExitError`. 2. **`files/read.test.ts` ran three tests twice** — a byte-identical duplicated block, provisioning a second real sandbox for each on every runtime leg. 3. **A cold-cache-only flake, root-caused.** `api/http2` and `envd/http2` carried dead `vi.doUnmock('undici')` / `vi.doUnmock('../../src/utils')` calls from an old refactor (neither file mocks anything any more). The bare `'undici'` one made Vite discover and pre-bundle a Node HTTP client *mid-run*, reloading the browser page under the running suite and breaking whichever file was being collected. Verified: 1-in-4 failure before, three cold-cache runs green after. Node-only test APIs are replaced with cross-runtime equivalents: `node:crypto` `randomUUID`/`createHash` → WebCrypto, `Buffer` → `TextEncoder`/`TextDecoder`, `path.basename` → inline. ## Two real browser bugs found Both verified over the wire; neither was fixable in the SDK alone. **Pagination silently truncated** — the cursor lives in the `x-next-token` response header, which the API didn't name in `Access-Control-Expose-Headers`, so a browser withheld it and every page looked like the last: ```ts const paginator = Sandbox.list({ limit: 10 }) const all = [] while (paginator.hasNext) all.push(...(await paginator.nextItems())) // Node: all 200 sandboxes. Browser (before the fix): 10, hasNext === false, no error. ``` Fixed upstream in [infra#3388](e2b-dev/runtime@e832b1e), **rolled out 2026-07-24** — the six tests are un-gated here and pass. SDK-293. **SDK-294 — `isRunning()` threw instead of returning `false`.** A stopped sandbox's 502 came from the edge without CORS headers, so the probe rejected opaquely (`running: 204 + ACAO: *` / `paused: 502 + no ACAO`). Because a browser always preflights the SDK's envd requests (they carry `E2b-Sandbox-Id`/`E2b-Sandbox-Port`) and a preflight needs an ok status, adding the header to the 502 alone wasn't enough — the `OPTIONS` path needed a 2xx too. Fixed upstream in [belt#2068](e2b-dev/belt#2068) and **confirmed on production**: `isRunning()` now returns `false` for a stopped sandbox in the browser, and the 13 tests that depended on it pass. <a id="sdk-294"></a> **The kill-mid-request error was a separate, SDK-side bug** — originally filed under SDK-294 as another symptom of the missing CORS headers. It isn't: belt#2068 rolled out, the other 13 went green, and `killing the sandbox while a command is running throws an actionable error` still failed with `SandboxError: 2: [unknown] network error`. When the connection drops mid-request the SDK probes the sandbox's health to tell a killed sandbox from a transient blip, but the probe is gated on the connection-dropped message, whose wording is runtime-specific — and the browser's was missing: ```ts const CONNECTION_TERMINATED_MESSAGES = [ 'terminated', // Node (undici) 'The socket connection was closed unexpectedly', // Bun 'error reading a body from connection', // Deno 'Network connection lost', // Cloudflare Workers 'network error', // Browser ← added ] ``` So the probe never ran and the error stayed generic. The fragment is broad, which is fine by construction: matching only earns a health probe, and the error stays generic unless the probe confirms the sandbox is gone. A browser reports every failed request identically on purpose, so this is the only wording available. Both entry points (`handleRpcErrorWithHealthCheck` for RPC, `handleEnvdApiFetchError` for the envd HTTP API) share the predicate, so one edit covers both; the per-runtime tables in `handleRpcError.test.ts` and `handleEnvdApiError.test.ts` gain a `Browser` row. No Python counterpart — it detects this by exception type, not message wording, and has no browser runtime. belt#2068 also fixes the content negotiation the investigation turned up: the proxy chose HTML over JSON by User-Agent sniffing, and browser `fetch` can't override its UA, so an SDK call from a browser got the HTML error page where it expects JSON (`Accept` was ignored). That is un-gated here too. ## How limitations are handled **No capability flags — nothing is skipped to avoid a browser failure.** Four tests do skip, each on an assertion that does not exist in a browser rather than one that fails there: the two `tests/runtime.test.ts` detection tests above; `sandbox_url defaults to stable sandbox host in production`, which has a browser counterpart asserting the opposite (the stable host is deliberately not used there); and `an adopted foreign stream forwards cancellation to its source`, because a browser cannot stream a request body at all, so the SDK buffers instead of adopting the stream — the sibling assertion `expect(streamed).toBe(streams)` covers that positively. The one still-failing test is left red on purpose, waiting on the upstream rollout rather than gated around; see the callout at the top. The five tests that read a response from a server the test itself starts in the sandbox now start a CORS-enabled one, via `corsHttpServerCmd` in `tests/setup.ts`: ```ts // was: 'python3 -m http.server 8000' — no CORS headers, so a browser hands the // test an opaque `TypeError: Failed to fetch` instead of the response await sandbox.commands.run(corsHttpServerCmd(8000), { background: true }) ``` This was originally gated behind a `canFetchSandboxServers` flag as an inherent browser limitation. It isn't one: the server is the test's own, and a real browser app's server opts into CORS exactly the same way — so the gate was hiding coverage of `getHost` and the proxy path rather than documenting a wall. `Access-Control-Allow-Headers` plus `do_OPTIONS` also covers the traffic-access-token test, whose custom header the browser preflights. Confirmed on the browser leg: **all five tests this un-gates pass** — `ping server in running sandbox`, `sandbox works without token`, `auto-resume wakes paused sandbox on http request`, `pause and resume a sandbox with http server` (that one needed belt#2068, since it calls `isRunning()` on a paused sandbox), and `sandbox requires traffic access token`, which reads a proxy-synthesized `403` after a preflight that can't carry the token — the last piece of the belt#2068 rollout. That's the CORS server working end-to-end through the proxy against production. Two in-sandbox servers are written inline by their own tests rather than started from `corsHttpServerCmd` — the `maskRequestHost` header-capturing server and the self-signed HTTPS backend behind `httpsPorts` — and both send `Access-Control-Allow-Origin` for the same reason. The `exclude` list is only for genuinely Node-only suites (`tests/bundle/**` reads `dist` via `node:fs`, `tests/undici.test.ts` resolves packages off `process.versions.node`) plus the ten suites that mock the API with `msw/node`, whose entry pulls in `node:http` and can't be served to a browser. Porting those needs `setupWorker` plus a service worker from a public dir — tracked as a follow-up on SDK-292, and worth doing since cancellation is the most runtime-divergent part of this SDK. ## A real bug the leg caught `main` added `toUploadBody leaves an async-iterable foreign stream alone` while this branch was in review, and it failed in Chromium with `expected '[object ReadableStream]' to be 'hello'`. Not a test artifact — the mechanism, confirmed directly: ```ts const asyncIterable = { async *[Symbol.asyncIterator]() { yield new TextEncoder().encode('hello') } } await new Response(asyncIterable).text() // Node: 'hello' (undici accepts any async iterable) // Chromium: '[object ReadableStream]' (the web platform does not) ``` `toDispatchableStream` treats async-iterability as "the platform will accept this", which is an undici extension rather than web behavior. So buffering a stream via `new Response(stream)` in a browser stringified it, and this silently uploaded 23 bytes of text instead of the file: ```ts import { ReadableStream } from 'web-streams-polyfill' // or any replaced global / other realm await sandbox.files.write('data.bin', new ReadableStream({ /* ... */ })) // Before: the file contains the literal text "[object ReadableStream]" // After: the file contains the data ``` The fix drains the stream through its reader — the one part every implementation shares — instead of guessing what the platform accepts. Note the *obvious* fix is wrong: skipping the async-iterable branch in the browser re-wraps a native stream when `globalThis.ReadableStream` has been replaced by a polyfill, which is precisely what that branch exists to prevent (there's a test for it). Verified in Chromium and Node. ## CI New `browser` matrix leg on `ubuntu-22.04`, with the Playwright cache moved onto it (no other leg needs Chromium any more). The leg is dropped by `node-only` staging callers, and it's the only leg whose result depends on the API's CORS headers — the matrix comment now says so, rather than claiming the non-Node legs add no backend signal. ## Notes - **No longer test-only**: carries two source fixes, each with a patch changeset — the `toBlob` stream drain (below) and the browser connection-drop wording (above). Everything else is tests and CI. - **Kept up to date with `main` by merging** (four times so far; earlier revisions were rebased). What conflicted each time and how it was resolved: Playwright moved into a `playwright:install` script, so `pretest:browser` delegates to it; new `msw/node` suites are added to the browser suite's `exclude` list as they land (ten now); `packages/js-sdk/package.json` conflicts against every dev-dep refresh, since `main` still carries the seven React devDeps this branch drops — resolved to main's versions and `catalog:` specifiers minus those; `pnpm-lock.yaml` is always reset to main's and regenerated with `pnpm install --lockfile-only` rather than hand-merged, so its only delta from main is the React tree; `main`'s rewrites of the shared live tests (polling assertions, `vi.waitFor` helpers, and hoisting this branch's local `waitForHttpStatus` into `tests/setup.ts`) are taken wholesale, keeping only the `corsHttpServerCmd` call sites on top. Note the Playwright bump to ^1.62 invalidates a local Chromium cache — `pnpm run playwright:install`; CI is unaffected. - `vi.stubEnv` and `delete process.env.X` keep working in the browser because the shim aliases `process.env` to `import.meta.env`, which is where vitest puts config `env` and where `stubEnv` writes. Verified `E2B_DEBUG=1 pnpm test:browser` correctly skips the debug-gated tests. - Verification for the CORS server, since a browser-side change like this is easy to get subtly wrong: ran a local instance of the exact generated command and fetched it cross-origin (different port = different origin) from real Chromium — simple GET readable, and a custom-header request survives the preflight. Negative control against a plain `python -m http.server` reproduces the `TypeError: Failed to fetch` the browser leg was showing, so the probe is meaningful rather than vacuous. Also checked there's exactly one `Access-Control-Allow-Origin` header — a duplicate would make browsers reject the response. - Review feedback addressed: `noProcessGlobal.test.ts` imports the SDK dynamically inside the test body — a static import is evaluated at collection time, while the `process` shim is still installed, so it only covered the call path and not module evaluation. (An earlier revision also put the `canFetchSandboxServers` gate on `pause and resume a sandbox with http server`; that gate was deleted wholesale later in the branch when the tests moved to `corsHttpServerCmd`.) - No new type errors: 22 pre-existing test type errors before and after (the 2 that went away are the `ProcessExitError` ones this fixes). - **Not** addressed, pre-existing, flagged in case you want a follow-up: `tests/api/list.test.ts` duplicates five tests byte-for-byte (only the three `betaPause` ones intentionally differ, instance vs static), and `files/write.test.ts:130` repeats `write file` as a strict subset of the test at `:6` — together ~7 redundant sandboxes per run per leg. Left alone rather than deleting tests outside this change's scope. Closes SDK-292 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
1 parent e1fbe86 commit 80496c0

35 files changed

Lines changed: 358 additions & 747 deletions

‎.changeset/olive-jars-tap.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2b': patch
3+
---
4+
5+
Fix uploads of non-native `ReadableStream`s in the browser silently sending the text `[object ReadableStream]` instead of the data. Buffering a stream drained it with `new Response(stream)`, which accepts any async iterable on Node (an undici extension) but only its own stream class in a browser, stringifying anything else. Streams are now drained through the reader, which every implementation supports.

‎.changeset/soft-moons-repeat.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2b': patch
3+
---
4+
5+
Report a sandbox killed mid-request as an actionable `TimeoutError` in the browser. When the connection to a sandbox drops mid-request the SDK probes the sandbox's health to tell a killed sandbox apart from a transient network blip, but the probe only ran for connection-dropped wordings it recognized, and the browser's (`network error`) was missing — so killing a sandbox while a command was running surfaced a generic `SandboxError: [unknown] network error` instead of `TimeoutError: ... The sandbox was killed or reached its end of life while the request was in flight.`

‎.github/workflows/js_sdk_tests.yml‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
type: string
99
default: ''
1010
node-only:
11-
description: 'Run only the Node legs (skip Bun, Deno, and Cloudflare)'
11+
description: 'Run only the Node legs (skip Bun, Deno, Cloudflare, and the browser)'
1212
required: false
1313
type: boolean
1414
default: false
@@ -31,18 +31,22 @@ jobs:
3131
name: JS SDK - ${{ matrix.runtime }} (${{ matrix.os }})
3232
strategy:
3333
fail-fast: false
34-
# Each runtime keeps one live-test worker, so all six runtime/OS jobs can
35-
# run together without restoring Vitest's default worker multiplication.
36-
max-parallel: 6
34+
# Each runtime keeps one live-test worker, so all seven runtime/OS jobs
35+
# can run together without restoring Vitest's default worker
36+
# multiplication.
37+
max-parallel: 7
3738
# With node-only (set by staging callers) the matrix collapses to the
38-
# Node legs: the Bun/Deno/Cloudflare legs re-run suites the Node legs
39-
# already cover and add sandbox/build load without extra backend
40-
# signal, so the other runtimes are exercised against production only.
39+
# Node legs: the Bun/Deno/Cloudflare/browser legs re-run suites the Node
40+
# legs already cover and add sandbox/build load, so the other runtimes
41+
# are exercised against production only. Note this does drop backend
42+
# signal for the browser leg specifically — it's the only one that
43+
# depends on the API's CORS headers — so a staging-only CORS regression
44+
# surfaces on the production run rather than before merge.
4145
matrix:
4246
include: >-
4347
${{ inputs.node-only
4448
&& fromJSON('[{"runtime": "node", "os": "ubuntu-22.04"}, {"runtime": "node", "os": "windows-latest"}]')
45-
|| fromJSON('[{"runtime": "node", "os": "ubuntu-22.04"}, {"runtime": "node", "os": "windows-latest"}, {"runtime": "bun", "os": "ubuntu-22.04"}, {"runtime": "deno", "os": "ubuntu-22.04"}, {"runtime": "cloudflare", "os": "ubuntu-22.04"}, {"runtime": "cloudflare-deploy", "os": "ubuntu-22.04"}]') }}
49+
|| fromJSON('[{"runtime": "node", "os": "ubuntu-22.04"}, {"runtime": "node", "os": "windows-latest"}, {"runtime": "bun", "os": "ubuntu-22.04"}, {"runtime": "deno", "os": "ubuntu-22.04"}, {"runtime": "cloudflare", "os": "ubuntu-22.04"}, {"runtime": "cloudflare-deploy", "os": "ubuntu-22.04"}, {"runtime": "browser", "os": "ubuntu-22.04"}]') }}
4650
runs-on: ${{ matrix.os }}
4751
env:
4852
E2B_TEST_MAX_WORKERS: 1
@@ -90,22 +94,21 @@ jobs:
9094
run: |
9195
pnpm install --frozen-lockfile
9296
93-
# Only the Node runtime runs the vitest `browser` project, which drives
94-
# Chromium through Playwright.
97+
# Only the browser leg needs Chromium, which Playwright drives.
9598
- name: Get Playwright version
96-
if: matrix.runtime == 'node'
99+
if: matrix.runtime == 'browser'
97100
id: playwright-version
98101
run: echo "version=$(node -p "require('playwright/package.json').version")" >> "$GITHUB_OUTPUT"
99102

100103
- name: Cache Playwright browsers
101-
if: matrix.runtime == 'node'
104+
if: matrix.runtime == 'browser'
102105
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
103106
with:
104-
path: ${{ matrix.os == 'windows-latest' && '~/AppData/Local/ms-playwright' || '~/.cache/ms-playwright' }}
107+
path: ~/.cache/ms-playwright
105108
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
106109

107110
- name: Install Playwright Chromium
108-
if: matrix.runtime == 'node'
111+
if: matrix.runtime == 'browser'
109112
run: pnpm run playwright:install
110113

111114
# The unit bundle test and the Cloudflare deploy config fail in CI when
@@ -163,3 +166,13 @@ jobs:
163166
env:
164167
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
165168
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
169+
170+
# Full unit + connectionConfig suite inside Chromium (vitest browser mode).
171+
# Chromium comes from the cached install step above; `pretest:browser`
172+
# covers local runs, where it's a no-op once installed.
173+
- name: Run test suite in the browser
174+
if: matrix.runtime == 'browser'
175+
run: pnpm test:browser
176+
env:
177+
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
178+
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}

‎packages/js-sdk/package.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"generate:mcp": "json2ts -i ./../../spec/mcp-server.json -o src/sandbox/mcp.d.ts --unreachableDefinitions --style.singleQuote --no-style.semi",
3636
"check-deps": "knip",
3737
"playwright:install": "playwright install chromium",
38+
"pretest:browser": "pnpm run playwright:install",
39+
"test:browser": "vitest run --config tests/runtimes/browser/vitest.config.mts",
3840
"test:bun": "bunx --bun vitest run --project unit --project connectionConfig --project template",
3941
"test:cf": "vitest run --config tests/runtimes/cloudflare/vitest.config.mts",
4042
"test:cf:deploy": "vitest run --config tests/runtimes/cloudflare-deploy/vitest.config.mts",
@@ -46,13 +48,9 @@
4648
"devDependencies": {
4749
"@cloudflare/vitest-pool-workers": "^0.18.7",
4850
"@redocly/cli": "2.51.2",
49-
"@testing-library/react": "^16.3.3",
5051
"@types/node": "catalog:",
5152
"@types/platform": "^1.3.6",
52-
"@types/react": "^19.2.18",
53-
"@types/react-dom": "^19.2.5",
5453
"@typescript/native": "catalog:",
55-
"@vitejs/plugin-react": "^4.3.4",
5654
"@vitest/browser": "catalog:",
5755
"@vitest/browser-playwright": "catalog:",
5856
"dotenv": "^16.4.5",
@@ -63,12 +61,9 @@
6361
"npm-run-all": "^4.1.5",
6462
"openapi-typescript": "^7.13.0",
6563
"playwright": "^1.63.0",
66-
"react": "^19.2.8",
67-
"react-dom": "^19.2.8",
6864
"tsdown": "catalog:",
6965
"typescript": "catalog:",
7066
"vitest": "catalog:",
71-
"vitest-browser-react": "^2.3.0",
7267
"wrangler": "^4.129.0"
7368
},
7469
"files": [

‎packages/js-sdk/src/envd/rpc.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export type SandboxHealthCheck = () => Promise<boolean | undefined>
2929
* - Bun: `The socket connection was closed unexpectedly`
3030
* - Deno: `error reading a body from connection`
3131
* - Cloudflare Workers: `Network connection lost`
32+
* - Browser: `network error`
3233
*/
3334
const CONNECTION_TERMINATED_MESSAGES = [
3435
'terminated',
3536
'The socket connection was closed unexpectedly',
3637
'error reading a body from connection',
3738
'Network connection lost',
39+
'network error',
3840
]
3941

4042
/**

‎packages/js-sdk/src/utils.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,22 @@ export async function toBlob(
168168
if (isBlobLike(data)) {
169169
return new Blob([await data.arrayBuffer()], { type: data.type })
170170
}
171-
// ReadableStream - must consume to get Blob
171+
// ReadableStream - must consume to get Blob. Drained through the reader
172+
// rather than `new Response(stream)`: the platform only accepts a body it
173+
// recognizes, and what counts differs per runtime (undici takes any async
174+
// iterable, a browser takes only its own stream class and stringifies the
175+
// rest to "[object ReadableStream]"). The reader is the portable part.
172176
if (isReadableStreamLike(data)) {
173-
return new Response(toDispatchableStream(data)).blob()
177+
const reader = data.getReader()
178+
const chunks: BlobPart[] = []
179+
for (;;) {
180+
const { done, value } = await reader.read()
181+
if (done) {
182+
break
183+
}
184+
chunks.push(value)
185+
}
186+
return new Blob(chunks)
174187
}
175188
// String or ArrayBuffer - create Blob. A cross-realm ArrayBuffer needs no
176189
// special handling: buffer sources are recognized by V8, not by brand.

‎packages/js-sdk/tests/api/http2.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { afterEach, expect, test, vi } from 'vitest'
33
afterEach(() => {
44
vi.restoreAllMocks()
55
vi.resetModules()
6-
vi.doUnmock('undici')
7-
vi.doUnmock('../../src/utils')
86
delete process.env.E2B_API_CONNECTIONS
97
delete process.env.E2B_API_INFLIGHT_REQUESTS
108
})

‎packages/js-sdk/tests/api/list.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { assert } from 'vitest'
2-
import { randomUUID } from 'crypto'
32

43
import { Sandbox, SandboxInfo } from '../../src'
54
import { sandboxTest, isDebug } from '../setup.js'
@@ -20,7 +19,7 @@ sandboxTest.skipIf(isDebug)(
2019
)
2120

2221
sandboxTest.skipIf(isDebug)('list sandboxes with filter', async () => {
23-
const uniqueId = randomUUID()
22+
const uniqueId = crypto.randomUUID()
2423
const extraSbx = await Sandbox.create({ metadata: { uniqueId } })
2524

2625
try {
@@ -316,7 +315,7 @@ sandboxTest.skipIf(isDebug)(
316315
)
317316

318317
sandboxTest.skipIf(isDebug)('list sandboxes with filter', async () => {
319-
const uniqueId = randomUUID()
318+
const uniqueId = crypto.randomUUID()
320319
const extraSbx = await Sandbox.create({ metadata: { uniqueId } })
321320

322321
try {

‎packages/js-sdk/tests/connectionConfig.test.ts‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
setupRequestController,
66
wrapStreamWithConnectionCleanup,
77
} from '../src/connectionConfig'
8+
import { runtime } from '../src/utils'
89

910
// Store original env vars to restore after tests
1011
let originalEnv: { [key: string]: string | undefined }
@@ -68,21 +69,26 @@ test('api_url has correct priority', () => {
6869
assert.equal(config.apiUrl, 'http://localhost:8080')
6970
})
7071

71-
test('sandbox_url defaults to stable sandbox host in production', () => {
72-
delete process.env.E2B_SANDBOX_URL
73-
delete process.env.E2B_DOMAIN
74-
delete process.env.E2B_DEBUG
75-
76-
const config = new ConnectionConfig()
77-
78-
assert.equal(
79-
config.getSandboxUrl('sbx-test', {
80-
sandboxDomain: 'e2b.app',
81-
envdPort: 49983,
82-
}),
83-
'https://sandbox.e2b.app'
84-
)
85-
})
72+
// The stable host is deliberately not used in a browser (CORS); the browser
73+
// side of this branch is asserted in connectionConfig.browser.test.ts.
74+
test.skipIf(runtime === 'browser')(
75+
'sandbox_url defaults to stable sandbox host in production',
76+
() => {
77+
delete process.env.E2B_SANDBOX_URL
78+
delete process.env.E2B_DOMAIN
79+
delete process.env.E2B_DEBUG
80+
81+
const config = new ConnectionConfig()
82+
83+
assert.equal(
84+
config.getSandboxUrl('sbx-test', {
85+
sandboxDomain: 'e2b.app',
86+
envdPort: 49983,
87+
}),
88+
'https://sandbox.e2b.app'
89+
)
90+
}
91+
)
8692

8793
test('sandbox_direct_url keeps per-sandbox host in production', () => {
8894
delete process.env.E2B_SANDBOX_URL

‎packages/js-sdk/tests/envd/handleEnvdApiError.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ describe('handleEnvdApiFetchError', () => {
126126
Bun: new Error('The socket connection was closed unexpectedly'),
127127
Deno: new TypeError('error reading a body from connection'),
128128
'Cloudflare Workers': new Error('Network connection lost.'),
129+
Browser: new TypeError('network error'),
129130
}
130131

131132
for (const [runtime, error] of Object.entries(runtimeTerminatedErrors)) {

0 commit comments

Comments
 (0)