chore(storage): bound build retention, caches and test resources
Track build ownership, qualified pins and bounded cache/log lifecycles. Move Vite fixtures to a job-owned server helper and preserve private outputs outside Git.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { access, readdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { test } from "node:test";
|
||||
import { createServer, testCacheRoot } from "./support/vite-server.mjs";
|
||||
|
||||
async function absent(path) {
|
||||
await assert.rejects(access(path), { code: "ENOENT" });
|
||||
}
|
||||
|
||||
test("SSR servers load real modules without dependency bundles and remove only their own cache", async () => {
|
||||
assert.equal(testCacheRoot, fileURLToPath(new URL("../../../.runtime/frontend-unit-tests/", import.meta.url)));
|
||||
const first = await createServer({ logLevel: "silent" });
|
||||
const second = await createServer({ configFile: false, logLevel: "silent" });
|
||||
try {
|
||||
assert.notEqual(first.config.cacheDir, second.config.cacheDir);
|
||||
for (const server of [first, second]) {
|
||||
for (const name of ["client", "ssr"]) {
|
||||
assert.equal(server.environments[name].config.optimizeDeps.noDiscovery, true);
|
||||
assert.deepEqual(server.environments[name].config.optimizeDeps.include, []);
|
||||
}
|
||||
const loaded = await server.ssrLoadModule("/src/core/simulation/urbanMap.ts");
|
||||
assert.equal(typeof loaded.loadUrbanMap, "function");
|
||||
assert.deepEqual(await readdir(server.config.cacheDir), []);
|
||||
}
|
||||
const survivor = join(second.config.cacheDir, "owned-marker");
|
||||
await writeFile(survivor, "keep");
|
||||
await Promise.all([first.close(), first.close()]);
|
||||
await absent(first.config.cacheDir);
|
||||
await access(survivor);
|
||||
} finally {
|
||||
await first.close();
|
||||
await second.close();
|
||||
}
|
||||
await absent(second.config.cacheDir);
|
||||
});
|
||||
|
||||
test("failed Vite configuration removes its scratch directory", async () => {
|
||||
const before = (await readdir(testCacheRoot)).sort();
|
||||
await assert.rejects(createServer({
|
||||
configFile: false,
|
||||
logLevel: "silent",
|
||||
plugins: [{ name: "intentional-startup-failure", config() { throw new Error("expected startup failure"); } }],
|
||||
}), /expected startup failure/);
|
||||
assert.deepEqual((await readdir(testCacheRoot)).sort(), before);
|
||||
});
|
||||
Reference in New Issue
Block a user