Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/**
* Build-artifact tests. Assume `bunx turbo build --filter=@suaveplan/storage-uri-plugin-bundle`
* has already produced `dist/`. The repo's turbo pipeline always builds before test.
* If you run these in isolation, run `bun run build` first.
*/
import { readFileSync, statSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "@suaveplan/testing/runner";
const distDir = fileURLToPath(new URL("../../dist/", import.meta.url));
describe("storage-uri-plugin-bundle build artifacts", () => {
it("build emits a non-empty dist/node-fetch/node-fetch.js", {
timeout: 30000,
}, () => {
const path = `${distDir}node-fetch/node-fetch.js`;
const stat = statSync(path);
expect(stat.isFile()).toBe(true);
expect(stat.size).toBeGreaterThan(0);
expect(path.endsWith(".js")).toBe(true);
});
it("dist/index.js contains no node: imports", { timeout: 30000 }, () => {
const source = readFileSync(`${distDir}index.js`, "utf8");
expect(source).not.toMatch(/from\s+["']node:/);
});
});

View File

@@ -0,0 +1,21 @@
/**
* Proves the emitted `dist/node-fetch/node-fetch.js` is actually runnable —
* not just present on disk. Dynamic-imports the built artifact and asserts
* the `nodeFileFetch` export is a function.
*/
import { describe, expect, it } from "@suaveplan/testing/runner";
describe("storage-uri-plugin-bundle ./node-fetch runtime import", () => {
it("emitted node-fetch.js exports nodeFileFetch as a function", {
timeout: 30000,
}, async () => {
const url = new URL(
"../../dist/node-fetch/node-fetch.js",
import.meta.url
);
const imported = (await import(url.href)) as {
nodeFileFetch: unknown;
};
expect(typeof imported.nodeFileFetch).toBe("function");
});
});

View File

@@ -0,0 +1,60 @@
// Universal test fixture: a tiny node:http server. Tests are
// run-only (not shipped); importing node:http here is permitted in the
// `tests/` directory which is excluded from tier-purity checks in
// `src/`. The src tree stays universal.
import {
createServer,
type IncomingMessage,
type Server,
type ServerResponse,
} from "node:http";
export type RouteHandler = (
req: IncomingMessage,
res: ServerResponse
) => void | Promise<void>;
export interface FixtureServer {
readonly url: string;
readonly port: number;
close(): Promise<void>;
}
/**
* Stand up a localhost `node:http` server with the given route handler.
* The returned `url` ends with `/` so it can be used as a `rootUrl`.
*/
export async function startFixtureServer(
handler: RouteHandler
): Promise<FixtureServer> {
const server: Server = createServer((req, res) => {
try {
const out = handler(req, res);
if (out !== undefined) {
void Promise.resolve(out).catch((err) => {
res.statusCode = 500;
res.end(String(err));
});
}
} catch (err) {
res.statusCode = 500;
res.end(String(err));
}
});
await new Promise<void>((resolve) =>
server.listen(0, "127.0.0.1", () => resolve())
);
const addr = server.address();
if (addr === null || typeof addr === "string") {
throw new Error("fixture server did not bind to a TCP port");
}
const port = addr.port;
return {
url: `http://127.0.0.1:${port}/`,
port,
close: () =>
new Promise<void>((resolve, reject) =>
server.close((err) => (err ? reject(err) : resolve()))
),
};
}

View File

@@ -0,0 +1,7 @@
// Polyfills for the test environment — none required beyond what
// `@suaveplan/testing/polyfills` already installs. Node 18+ provides
// `URL`, `AbortController`, `ReadableStream`, `Response`, and `fetch`
// natively; Node 21+ supports `fetch(file://)`. The file exists so
// vitest has a stable additional-setup entry alongside the
// package-local fixture imports.
export {};