docs(spikes): Deno 2.9.7 + TS 7 compatibility spike and ADR-004
Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
fe3613ee8f
commit
cf85481d95
147 files changed
+15213
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { createServer, type Server } from "node:http";
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm, writeFile, statfs } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { createApp } from "../src/http.ts";
|
||||
import { redact } from "@spike/x";
|
||||
|
||||
let server: Server;
|
||||
let base = "";
|
||||
beforeAll(async () => {
|
||||
server = createServer((req, res) => {
|
||||
res.setHeader("content-type", "application/json");
|
||||
res.end(JSON.stringify({ path: req.url, method: req.method }));
|
||||
});
|
||||
await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
|
||||
const addr = server.address();
|
||||
base = `http://127.0.0.1:${typeof addr === "object" && addr ? addr.port : 0}`;
|
||||
});
|
||||
afterAll(async () => { await new Promise((r) => server.close(r)); });
|
||||
|
||||
describe("node compat under test runner", () => {
|
||||
it("node:http mock server + fetch", async () => {
|
||||
const r = await fetch(`${base}/api/v2/torrents/info?x=1`);
|
||||
expect(await r.json()).toEqual({ path: "/api/v2/torrents/info?x=1", method: "GET" });
|
||||
});
|
||||
it("node:child_process spawn + kill", async () => {
|
||||
const child = spawn("sleep", ["30"]);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
const exited = new Promise<{ code: number | null; signal: string | null }>((r) => child.on("exit", (code, signal) => r({ code, signal })));
|
||||
expect(child.kill("SIGKILL")).toBe(true);
|
||||
expect(await exited).toEqual({ code: null, signal: "SIGKILL" });
|
||||
});
|
||||
it("fs temp dir + statfs", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "umt-"));
|
||||
await writeFile(join(dir, "a.txt"), "hi");
|
||||
expect(await readFile(join(dir, "a.txt"), "utf8")).toBe("hi");
|
||||
const s = await statfs(dir);
|
||||
expect(s.bsize).toBeGreaterThan(0);
|
||||
expect(typeof s.bavail).toBe("number");
|
||||
await rm(dir, { recursive: true });
|
||||
});
|
||||
it("hono app.request SSE", async () => {
|
||||
const res = await createApp().request("/api/v1/events?after=1");
|
||||
expect(res.headers.get("content-type")).toContain("text/event-stream");
|
||||
const text = await res.text();
|
||||
expect(text).toContain("id: 2");
|
||||
expect(text).toContain("event: tick");
|
||||
});
|
||||
it("workspace package import", () => {
|
||||
expect(redact({ token: "x" })).toEqual({ token: "[REDACTED]" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
|
||||
import { expect } from "@std/expect";
|
||||
import { createServer, type Server } from "node:http";
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm, writeFile, statfs } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { createApp } from "../src/http.ts";
|
||||
import { redact } from "@spike/x";
|
||||
|
||||
let server: Server;
|
||||
let base = "";
|
||||
beforeAll(async () => {
|
||||
server = createServer((req, res) => {
|
||||
res.setHeader("content-type", "application/json");
|
||||
res.end(JSON.stringify({ path: req.url, method: req.method }));
|
||||
});
|
||||
await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
|
||||
const addr = server.address();
|
||||
base = `http://127.0.0.1:${typeof addr === "object" && addr ? addr.port : 0}`;
|
||||
});
|
||||
afterAll(async () => { await new Promise((r) => server.close(r)); });
|
||||
|
||||
describe("node compat under test runner", () => {
|
||||
it("node:http mock server + fetch", async () => {
|
||||
const r = await fetch(`${base}/api/v2/torrents/info?x=1`);
|
||||
expect(await r.json()).toEqual({ path: "/api/v2/torrents/info?x=1", method: "GET" });
|
||||
});
|
||||
it("node:child_process spawn + kill", async () => {
|
||||
const child = spawn("sleep", ["30"]);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
const exited = new Promise<{ code: number | null; signal: string | null }>((r) => child.on("exit", (code, signal) => r({ code, signal })));
|
||||
expect(child.kill("SIGKILL")).toBe(true);
|
||||
expect(await exited).toEqual({ code: null, signal: "SIGKILL" });
|
||||
});
|
||||
it("fs temp dir + statfs", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "umt-"));
|
||||
await writeFile(join(dir, "a.txt"), "hi");
|
||||
expect(await readFile(join(dir, "a.txt"), "utf8")).toBe("hi");
|
||||
const s = await statfs(dir);
|
||||
expect(s.bsize).toBeGreaterThan(0);
|
||||
expect(typeof s.bavail).toBe("number");
|
||||
await rm(dir, { recursive: true });
|
||||
});
|
||||
it("hono app.request SSE", async () => {
|
||||
const res = await createApp().request("/api/v1/events?after=1");
|
||||
expect(res.headers.get("content-type")).toContain("text/event-stream");
|
||||
const text = await res.text();
|
||||
expect(text).toContain("id: 2");
|
||||
expect(text).toContain("event: tick");
|
||||
});
|
||||
it("workspace package import", () => {
|
||||
expect(redact({ token: "x" })).toEqual({ token: "[REDACTED]" });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user