Skip to content

test: prove edge conditional-export resolution + verify with the real Workers bundler - #122

Merged
patchstackdave merged 1 commit into
mainfrom
test/edge-export-resolution
Aug 13, 2026
Merged

test: prove edge conditional-export resolution + verify with the real Workers bundler#122
patchstackdave merged 1 commit into
mainfrom
test/edge-export-resolution

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

Closes the last gap the external review left open.

The gap

Our edge coverage bundled dist/protect.edge.js directly. That proves the artifact is edge-clean, but not that a consumer ever reaches it — a mis-ordered or mistyped exports condition would silently hand an edge bundler the Node build, and every existing test would still pass.

1. Resolution test (in the suite)

tests/protect/edge-export-resolution.test.ts imports the real specifier @patchstack/connect/protect from a fixture with the package linked into node_modules, and resolves it under workerd / worker / edge-light / deno / browser — asserting each lands on the edge artifact.

The control is what makes it meaningful: with no edge condition, the same import resolves to the Node build and fails to bundle for a Node-free target. So a pass is caused by the condition, not by a lenient target. Uses platform: 'neutral' deliberately — 'browser' would inject the browser condition and mask whether the edge conditions themselves work.

Mutation-checked: pointing workerd at ./dist/protect.js makes the test fail; restoring it makes it pass. It genuinely guards the regression.

2. Real platform verification (opt-in)

scripts/verify-edge-platform.mjs (npm run verify:edge) compiles a real Worker with the actual Cloudflare toolchain (wrangler deploy --dry-run) and asserts wrangler selected dist/protect.edge.js and emitted a bundle with no Node builtins.

Verified locally — wrangler 4 compiles it: Total Upload: 134.90 KiB, edge branch selected, zero Node imports.

It downloads wrangler and shells out to a platform bundler, so it is deliberately not in npm test (which CI runs across four Node versions). The two suite-level tests cover the same property cheaply; this is the end-to-end confirmation, suitable for a release job.

Remaining

A native next build Edge-middleware fixture is the one uncovered variant. Wrangler exercises the same constraint (workerd conditions + no Node builtins) at a fraction of the install cost, so this is a lower marginal return — noted rather than done.

779 tests green; typecheck + build clean.

…eal Workers bundler

Closes the last gap from the external review: our edge coverage bundled
dist/protect.edge.js DIRECTLY, which proves the artifact is edge-clean but not that a
consumer ever reaches it — a mis-ordered or mistyped `exports` condition would silently
hand an edge bundler the Node build.

- tests/protect/edge-export-resolution.test.ts imports the real specifier
  (`@patchstack/connect/protect`) from a fixture with the package linked into
  node_modules, and resolves it under workerd / worker / edge-light / deno / browser,
  asserting each lands on the edge artifact. The CONTROL is what makes it meaningful:
  with no edge condition the same import resolves to the Node build and FAILS to bundle
  for a Node-free target, so a pass is caused by the condition rather than a lenient
  target. Mutation-checked: pointing `workerd` at dist/protect.js makes it fail.
  (platform 'neutral' on purpose — 'browser' would inject the `browser` condition and
  mask whether the edge conditions themselves work.)

- scripts/verify-edge-platform.mjs (`npm run verify:edge`) compiles a real Worker with
  the actual Cloudflare toolchain (`wrangler deploy --dry-run`) and asserts wrangler
  selected dist/protect.edge.js and emitted a bundle with no Node builtins. Verified
  locally: wrangler 4 compiles it, 134.90 KiB, zero Node imports. It downloads wrangler
  and shells out to a platform bundler, so it is deliberately NOT in `npm test` (which CI
  runs on four Node versions) — the two suite-level tests cover the same property cheaply
  and this is the end-to-end confirmation for a release job.

A native `next build` fixture remains the one uncovered variant.

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

coderbuds Bot commented Aug 13, 2026

Copy link
Copy Markdown

Adds an end-to-end edge-bundler verification script with complementary export-resolution tests.

🎯 Quality: 100% Elite · 📦 Size: Medium

📈 This month: Your 55th PR — above team average · Averaging Excellent

See how your team is trending →

@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

@patchstackdave
patchstackdave merged commit c5a9652 into main Aug 13, 2026
5 checks passed
@patchstackdave
patchstackdave deleted the test/edge-export-resolution branch August 13, 2026 13:11
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