MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / setup

Function setup

apps/cloud/scripts/test-globalsetup.ts:41–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39 * resource without allowing PGlite shutdown to erase Vitest's failure status.
40 */
41export default async function setup() {
42 db = await PGlite.create();
43 await migrate(drizzle(db), { migrationsFolder: MIGRATIONS_FOLDER });
44
45 // PGlite is single-session; pglite-socket multiplexes connections onto it
46 // by queueing whole transactions. Two connections let a test open two
47 // transactions and interleave them (the mirror's scan-vs-feeder race in
48 // auth/workos-mirror.node.test.ts); a third would be refused at once.
49 server = new PGLiteSocketServer({ db, port: PORT, host: "127.0.0.1", maxConnections: 2 });
50 await server.start();
51
52 // eslint-disable-next-line no-console
53 console.log(`[test-db] PGlite socket server listening on 127.0.0.1:${PORT}`);
54
55 return async () => {
56 // PGlite sets an internal 99 sentinel on startup and replaces it with 0 on
57 // close. Preserve Vitest's failure status across that close so
58 // teardown can turn neither a red test green nor a green test red.
59 const testsFailed = process.exitCode === 1;
60 await server?.stop();
61 await db?.close();
62 if (testsFailed) process.exitCode = 1;
63 };
64}

Callers

nothing calls this directly

Calls 3

logMethod · 0.80
startMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected