Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 19, 2024
1 parent 9f0099e commit 7c13593
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- run: pnpm lint
- run: pnpm test:types
- run: pnpm test:node
- run: pnpm test:workerd
- run: pnpm build
- name: nightly release
if: |
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
"test": "pnpm lint && pnpm test:types && pnpm test:node",
"test:cf": "pnpm jiti test/cloudflare.ts",
"test:deno": "NODE_NO_WARNINGS=1 pnpm jiti test/deno.ts",
"test:node-coverage": "node test/node-coverage.mjs",
"test:node": "node --test --import jiti/register ./test/node/test-*",
"test:node-coverage": "node test/node-coverage.mjs",
"test:node:watch": "node --test --watch --import jiti/register ./test/node/test-*",
"test:types": "tsc --noEmit",
"test:vc": "pnpm jiti test/vercel.ts"
"test:vc": "pnpm jiti test/vercel.ts",
"test:workerd": "node test/workerd/_run.mjs"
},
"dependencies": {
"defu": "^6.1.4",
Expand Down
25 changes: 14 additions & 11 deletions test/workerd/_run.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import watcher from "@parcel/watcher";
import workerd from "workerd";
import { createModuleServer } from "./_server.mjs";

Expand All @@ -14,21 +13,25 @@ console.log(
);

// Start module server
await createModuleServer(8888);
const server = await createModuleServer(8888);
server.unref();

// Run tests once
runTests();

// Start watcher
const watchDirs = [srcDir, testsDir];
console.log(
`Watching for changes:\n${watchDirs.map((d) => ` - ${d}`).join("\n")}`,
);
for (const dir of watchDirs) {
watcher.subscribe(dir, () => {
console.clear();
runTests();
});
if (process.argv.includes("--watch")) {
const watcher = await import("@parcel/watcher").then((r) => r.default);
const watchDirs = [srcDir, testsDir];
console.log(
`Watching for changes:\n${watchDirs.map((d) => ` - ${d}`).join("\n")}`,
);
for (const dir of watchDirs) {
watcher.subscribe(dir, () => {
console.clear();
runTests();
});
}
}

// Workerd runner
Expand Down
3 changes: 1 addition & 2 deletions test/workerd/_server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const rootDir = fileURLToPath(new URL("../..", import.meta.url));

export async function createModuleServer(port = 8888) {
const server = createServer(async (req, res) => {
console.log(req.url);
const resolveMethod = req.headers["x-resolve-method"];
const url = new URL(req.url, "http://localhost");
const referrer = url.searchParams.get("referrer");
Expand Down Expand Up @@ -44,7 +43,7 @@ export async function createModuleServer(port = 8888) {
write: false,
format: "esm",
target: "esnext",
platform: "neutral",
platform: "node",
sourcemap: false,
});

Expand Down
2 changes: 1 addition & 1 deletion test/workerd/tests.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import crypto from "node:crypto";
import process from "node:process";

globalThis.Buffer = process.getBuiltinModule("buffer").Buffer;

export const cryptoTests = {
async test(ctrl, env, ctx) {
const crypto = await import("node:crypto");
crypto.randomBytes(10);
},
};

0 comments on commit 7c13593

Please sign in to comment.