Skip to content

Commit

Permalink
fixup! update module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jan 25, 2025
1 parent 27dab23 commit ee8d022
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/unenv-preset/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { version } from "../package.json";
import type { Preset } from "unenv";

// Built-in APIs provided by workerd.
//
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
// https://github.com/cloudflare/workerd/tree/main/src/node
//
// Last checked: 2025-01-24
const cloudflareNodeCompatModules = [
//
// NOTE: Please sync any changes to `testNodeCompatModules`.
const nodeCompatModules = [
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
Expand Down Expand Up @@ -53,7 +57,7 @@ export const cloudflare: Preset = {
},
alias: {
...Object.fromEntries(
cloudflareNodeCompatModules.flatMap((p) => [
nodeCompatModules.flatMap((p) => [
[p, p],
[`node:${p}`, `node:${p}`],
])
Expand Down Expand Up @@ -92,5 +96,5 @@ export const cloudflare: Preset = {
],
},
polyfill: [],
external: cloudflareNodeCompatModules.flatMap((p) => [p, `node:${p}`]),
external: nodeCompatModules.flatMap((p) => [p, `node:${p}`]),
};
4 changes: 2 additions & 2 deletions packages/unenv-preset/tests/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import assert from "node:assert";
export const TESTS = {
testCryptoGetRandomValues,
testImplementsBuffer,
testModules,
testNodeCompatModules,
testUtilImplements,
testPath,
testDns,
Expand Down Expand Up @@ -75,7 +75,7 @@ async function testImplementsBuffer() {
assert.strictEqual(typeof buffer.resolveObjectURL, "function");
}

async function testModules() {
async function testNodeCompatModules() {
const module = await import("node:module");
// @ts-expect-error exposed by workerd
const require = module.createRequire("/");
Expand Down

0 comments on commit ee8d022

Please sign in to comment.