-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: setup workerd isolate tests #311
base: main
Are you sure you want to change the base?
Conversation
import assert from "node:assert"; | ||
import process from "node:process"; | ||
|
||
globalThis.process = process; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, workerd fail:
workerd/io/worker.c++:1950: info: uncaught exception; source = Uncaught (in promise); stack = ReferenceError: process is not defined
at unenv/runtime/node/crypto:387:21
workerd/io/io-context.c++:348: info: uncaught exception; exception = workerd/jsg/_virtual_includes/jsg/workerd/jsg/value.h:1367: failed: jsg.ReferenceError: process is not defined
(process is used for process.getBuiltinModule("node:crypto")
...)
format: "esm", | ||
target: "esnext", | ||
platform: "node", | ||
sourcemap: "inline", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems not being picked by workerd.
}, | ||
}; | ||
|
||
// ---- node:url ---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have all Node.js upstream tests for url
, in test/node/*
now. But since this entry is inlined in capnp config, I'm not sure how to dynamically bring them. If we can, we can reuse same impl.
This PR adds isolated tests via workerd.
This setup uses a small Node.js wrapper that starts a module fallback server (based on cloudflare/workerd#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 usesenv(nodeless, cloudflare)
aliases to match the expected bundler behavior when resolving internalnode:
aliases.As sample, two tests for
crypto.getRandomValues
andurl.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 totest/workerd/.tmp
for inspection)