unenv icon indicating copy to clipboard operation
unenv copied to clipboard

test: setup workerd isolate tests

Open pi0 opened this issue 1 year ago • 0 comments

This PR adds isolated tests via workerd.

This setup uses a small Node.js wrapper that starts a module fallback server (based on https://github.com/cloudflare/workerd/pull/1423) and then spawns workerd test to run tests.

The fallback server, maps unenv/runtime/* requests to source code (transpiled with esbuild to allow HMR). esbuild config uses env(nodeless, cloudflare) aliases to match the expected bundler behavior when resolving internal node: aliases.

As sample, two tests for crypto.getRandomValues and url.parse (fail behavior) are added. We shall iterate and add more coverage for runtime safety as we introduce new features.

Usage:

  • pnpm test:workerd
  • pnpm test:workerd --watch (watch mode)
  • DUMP_MODULES=1 pnpm test:workerd (dump server modules to test/workerd/.tmp for inspection)

pi0 avatar Sep 19 '24 14:09 pi0