unenv
unenv copied to clipboard
test: setup workerd isolate tests
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:workerdpnpm test:workerd --watch(watch mode)DUMP_MODULES=1 pnpm test:workerd(dump server modules totest/workerd/.tmpfor inspection)