testBuildsOfOneAppAtOnce
Builds of one app at once (two verifies, say) all succeed and give the same build: each is made in a directory of its own and put in place whole, and nothing of either is left behind
import { tcmInBackground, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { setUp } from "#codebase/tcmts/cli/test/e2e/prod"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testBuildsOfOneAppAtOnce = () => withChildren(async (keep) => { const { dir, tcm, scratch } = setUp(); scratch(`// tcm: namespace app export async function greeting(name: string): Promise<string> { return "hello " + name + " from " + process.pid; } export async function main() { document.querySelector("#app")!.textContent = await greeting("ada"); } `); tcm("add"); const apps = path.join(dir, ".tcm", "apps"); for (const flags of [[], ["--force"]]) { const made = await Promise.all( // (three, so they overlap however the machine schedules them) [1, 2, 3].map(() => tcmInBackground(keep, dir, "build", "app.main", ...flags)), ); for (const m of made) assert.equal(m.status, 0, m.out); const said = new Set( made.flatMap((m) => /built app\.main #([a-z2-7]{8})/.exec(m.out)?.[1] ?? []), ); assert.ok(said.size === 1, `the same build: ${[...said].join(", ")}`); const builds = fs.readdirSync(apps).filter((f) => /^[a-z2-7]{52}$/.test(f)); assert.equal(builds.length, 1); assert.ok(builds[0]!.startsWith([...said][0]!)); const manifest = JSON.parse( fs.readFileSync(path.join(apps, builds[0]!, "tcm-app.json"), "utf8"), ) as { assets: string[] }; assert.ok(fs.existsSync(path.join(apps, builds[0]!, "index.html")), "whole"); for (const a of manifest.assets) assert.ok(fs.existsSync(path.join(apps, "assets", a)), a); assert.deepEqual(fs.readdirSync(path.join(dir, ".tcm", "build")), [], "nothing left behind"); } assert.doesNotMatch(tcm("build", "app.main"), /built/, "and it's reused"); })