From 53669b0b4af20248272c9942d23d82423cd18db1 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 15 Oct 2026 02:37:36 +0800 Subject: [PATCH] test(void): run PGlite initdb once for the wrapper migration tests Each new PGlite runs initdb. On Linux CI that took most of the 5s test deadline, and the pg bundle test timed out at 5108ms. Run initdb once in a hook with its own budget, and load each test's fresh database from the saved data directory. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH --- packages/void/test/unit/wrapper.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/void/test/unit/wrapper.test.ts b/packages/void/test/unit/wrapper.test.ts index 45cbeb8eb..d34ccdad6 100644 --- a/packages/void/test/unit/wrapper.test.ts +++ b/packages/void/test/unit/wrapper.test.ts @@ -20,7 +20,7 @@ import { PGlite } from '@electric-sql/pglite'; import { Miniflare, convertV4MiniflareOptions } from 'miniflare'; import { createServer as createPgServer } from 'pglite-server'; import { parseSync } from 'vite'; -import { afterEach, describe, expect, it, vi } from 'vite-plus/test'; +import { afterEach, beforeAll, describe, expect, it, vi } from 'vite-plus/test'; import { cleanupWrapper, needsWrapper, @@ -504,6 +504,18 @@ describe('generated wrapper queue dispatch', () => { describe('generateWrapper with migrations', () => { const roots: Array = []; + // Each new PGlite runs initdb, which can take seconds on CI. Run it once in this hook, with its + // own budget; each PostgreSQL test loads a fresh database from the initialized data directory. + let pgDataDir: Blob; + beforeAll( + async () => { + const pglite = new PGlite(); + await pglite.waitReady; + pgDataDir = await pglite.dumpDataDir('none'); + await pglite.close(); + }, + process.platform === 'win32' ? 30_000 : undefined, + ); afterEach(() => { for (const root of roots.splice(0)) { rmSync(root, { recursive: true, force: true }); @@ -754,7 +766,7 @@ describe('generateWrapper with migrations', () => { migrationDialect: 'postgresql', }); - const pglite = new PGlite(); + const pglite = new PGlite({ loadDataDir: pgDataDir }); // pglite-server does not wait for PGlite: a query that arrives during startup spins forever. await pglite.waitReady; const server = createPgServer(pglite); @@ -894,7 +906,7 @@ export default async function () { async function withPgUsers( run: (connectionString: string, connections: () => number) => Promise, ): Promise { - const pglite = new PGlite(); + const pglite = new PGlite({ loadDataDir: pgDataDir }); await pglite.waitReady; await pglite.exec( "CREATE TABLE users (id serial PRIMARY KEY, name text NOT NULL); INSERT INTO users (name) VALUES ('alice');",