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,15 @@
|
||||
# SSR unit-test server
|
||||
|
||||
Import `createServer` from `./support/vite-server.mjs` in tests, instead of from Vite.
|
||||
The helper keeps normal project resolution and plugins, disables browser/SSR
|
||||
prebundling after plugin configuration, and gives every server its own directory
|
||||
under the repository `.runtime/frontend-unit-tests`.
|
||||
|
||||
Keep the server alive for the whole test file: create it in `before`, and await
|
||||
`server?.close()` in the file's existing `after` hook. A server created inside a
|
||||
test must close in `finally`. Closing twice is safe. The helper cleans its own
|
||||
cache after close and on initialization failure; it does not register a nested
|
||||
`after` hook, which could close a file-scoped server before later tests use it.
|
||||
|
||||
`npm run test:unit` executes files sequentially for the operator Mac's memory
|
||||
budget. Production and development Vite configuration is unchanged.
|
||||
@@ -0,0 +1,62 @@
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createServer as createViteServer } from "vite";
|
||||
|
||||
export const testCacheRoot = fileURLToPath(
|
||||
new URL("../../../../.runtime/frontend-unit-tests/", import.meta.url),
|
||||
);
|
||||
|
||||
// SSR unit tests compile modules; they never need the browser dependency scan.
|
||||
// Each server owns its scratch directory, including failed initialization.
|
||||
export async function createServer(options = {}) {
|
||||
await mkdir(testCacheRoot, { recursive: true });
|
||||
const cacheDir = await mkdtemp(`${testCacheRoot}vite-`);
|
||||
const noDiscovery = { noDiscovery: true, include: [] };
|
||||
let server;
|
||||
try {
|
||||
server = await createViteServer({
|
||||
...options,
|
||||
plugins: [
|
||||
...(options.plugins ?? []),
|
||||
{
|
||||
name: "mission-core-ssr-unit-test",
|
||||
configResolved(config) {
|
||||
// React and other plugins can add includes in their config hooks.
|
||||
// Disable both client and SSR prebundling after those hooks finish.
|
||||
for (const environment of Object.values(config.environments)) {
|
||||
environment.optimizeDeps.noDiscovery = true;
|
||||
environment.optimizeDeps.include = [];
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
cacheDir,
|
||||
server: { ...options.server, middlewareMode: true, hmr: false, watch: null },
|
||||
optimizeDeps: { ...options.optimizeDeps, ...noDiscovery },
|
||||
environments: {
|
||||
...options.environments,
|
||||
client: {
|
||||
...options.environments?.client,
|
||||
optimizeDeps: { ...options.environments?.client?.optimizeDeps, ...noDiscovery },
|
||||
},
|
||||
ssr: {
|
||||
...options.environments?.ssr,
|
||||
optimizeDeps: { ...options.environments?.ssr?.optimizeDeps, ...noDiscovery },
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
await rm(cacheDir, { recursive: true, force: true });
|
||||
throw error;
|
||||
}
|
||||
const close = server.close.bind(server);
|
||||
let closing;
|
||||
server.close = () => closing ??= (async () => {
|
||||
try {
|
||||
await close();
|
||||
} finally {
|
||||
await rm(cacheDir, { recursive: true, force: true });
|
||||
}
|
||||
})();
|
||||
return server;
|
||||
}
|
||||
Reference in New Issue
Block a user