onFakeNetwork
uses node:path
Running tcm on the fake network: identities looked up on it, sign-ins kept in a directory of the test's own, and a
browser that follows the sign-in page's redirect back to tcm, as if the person had said yes. Each run is alongside
this process (a spawnSync would stop the fake network answering): run says how it ended, ok insists it worked.
import type { Keep } from "#codebase/tcmts/cli/test/e2e/contributions"; import type { FakeAtproto } from "#codebase/tcmts/cli/test/e2e/examples"; import { plainEnv, strip, tcmBin, tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import { spawn } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; export function onFakeNetwork(keep: Keep, net: FakeAtproto) { const home = tempDir("atproto config"); const browse = path.join(home, "browse.mjs"); fs.writeFileSync( browse, `const r = await fetch(process.argv[2]);\nprocess.exit(r.ok ? 0 : 1);\n`, ); const env = { ...plainEnv(), TCM_AUTHOR: "ada", TCM_ATPROTO_DIRECTORY: net.url, // (its servers are on this machine, over http: allowed only so) TCM_ATPROTO_LOCAL: "1", XDG_CONFIG_HOME: home, BROWSER: `"${process.execPath}" "${browse}"`, }; const run = (dir: string, ...args: string[]) => new Promise<{ status: number | null; out: string }>((resolve) => { const c = keep(spawn(process.execPath, [tcmBin(), ...args], { cwd: dir, env })); let out = ""; c.stdout!.setEncoding("utf8").on("data", (d: string) => (out += d)); c.stderr!.setEncoding("utf8").on("data", (d: string) => (out += d)); c.on("close", (status) => resolve({ status, out: strip(out) })); }); const ok = async (dir: string, ...args: string[]) => { const r = await run(dir, ...args); assert.equal(r.status, 0, `tcm ${args.join(" ")}:\n${r.out}`); return r.out; }; return { home, run, ok }; }
uses
- tcmts.cli.test.e2e.contributions.Keep
- tcmts.cli.test.e2e.examples.FakeAtproto
- tcmts.cli.test.e2e.harness.plainEnv
- tcmts.cli.test.e2e.harness.strip
- tcmts.cli.test.e2e.harness.tcmBin
- tcmts.cli.test.e2e.harness.tempDir
used by
- tcmts.cli.test.e2e.hub.testHubShowsAnnouncedLibraries
- tcmts.cli.test.e2e.hub.testHubSignInAndStars
- tcmts.cli.test.e2e.libraries.testAnnouncementsAreCheckedBySignature
- tcmts.cli.test.e2e.libraries.testLibrariesFromAnnouncements
- tcmts.cli.test.e2e.libraries.testLibraryAttestations
- tcmts.cli.test.e2e.releases.testReleasesAnnounced
- tcmts.dev.hubTrial