testLibraryEffects
what a library's code reaches outside itself is worked out from the code, a package's included, and said when it's added, listed, and upgraded (what's new then)
import { codebase } from "#codebase/tcmts/cli/test/e2e/releases"; import assert from "node:assert/strict"; export const testLibraryEffects = () => { const alice = codebase("alice effects"); alice.save( [ "// tcm: namespace geo", 'import { startOfToday } from "date-fns";', 'export const manifest = { name: "geo" };', "export const area = (side: number) => side * side;", "export const now = () => Date.now();", "export const home = () => process.env.HOME;", "export const today = () => startOfToday();", "export const testArea = () => { if (area(2) !== 4 || Date.now() < 0) throw new Error(); };", "", ].join("\n"), "add", ); alice.tcm("release", "geo@1.0.0"); const me = codebase("me effects"); me.save(`// tcm: namespace app\nexport const greeting = "hi";\n`, "add"); const added = me.tcm("lib", "add", alice.dir, "geo"); assert.match(added, /reaches the clock: now, today \(date-fns\)\n/); assert.match(added, /reaches the environment: home\n/); // (its tests aren't what it does) assert.doesNotMatch(added, /testArea/); assert.doesNotMatch(added, /the network/); assert.match(me.tcm("lib"), /· reaches the clock, the environment/); // an upgrade says what it newly reaches alice.save("// tcm: namespace geo\nexport const load = (url: string) => fetch(url);\n", "add"); alice.tcm("release", "geo"); const up = me.tcm("lib", "upgrade", "geo", "--check"); assert.match(up, /now reaches the network: load\n/); assert.doesNotMatch(up, /now reaches the clock/); // and a library reaching nothing says so const bob = codebase("bob effects"); bob.save( '// tcm: namespace shapes\nexport const manifest = { name: "shapes" };\nexport const sq = (n: number) => n * n;\n', "add", ); bob.tcm("release", "shapes@1.0.0"); assert.match(me.tcm("lib", "add", bob.dir, "shapes"), /reaches nothing outside itself/); }