diff --git a/TESTING.md b/TESTING.md index c92f9fbda..e430c891c 100644 --- a/TESTING.md +++ b/TESTING.md @@ -108,6 +108,15 @@ share a scheduling phase. `vp run test:unit` includes `unit`, `unit-pglite`, and The cf runner's transport checks live in `cf-version-transport.test.ts` so real subprocesses do not serialize the whole runner suite. Both files use the same fixture helpers with per-file isolated roots and cleanup; keep their real HTTP, process, and deadline assertions. +The cf runner, transport, build-output, and operation-process files run their real-subprocess cases +concurrently within each file (`const it = serialIt.concurrent`). A case that uses `vi` mocks or +spies must use `serialIt`: Vitest clears mock history whenever a test starts, so a concurrent +neighbor would erase the calls being asserted. Resolve fixture output through `outputRoot(prepared)` +instead of a shared "latest root" variable. +Browser suites with independent variants (`page-errors-*`, `server-auth-errors-*`, +`http-errors-playground-*`) keep their cases in a `*-suite.ts` module and expose one thin test file +per variant, so the variants spread across workers. Add a new variant as another thin file and give +it an estimate in `test/integration-timings.ts`. Unit files and most API integration files use isolated worker threads to reduce startup time. On Linux and macOS, API integration files and the PGlite unit files (`unit-pglite`, `platform-unit-pglite`) use forks to isolate PGlite's WebAssembly JIT allocations after native Node 24 crashes in shared worker processes. API tests diff --git a/packages/platform/package.json b/packages/platform/package.json index 48d29417f..40a01f187 100644 --- a/packages/platform/package.json +++ b/packages/platform/package.json @@ -46,7 +46,7 @@ "access": "public" }, "scripts": { - "build": "vp pack && node scripts/build-runtime.mjs && vp run build:stamp", + "build": "vp pack && vp run build:runtime && vp run build:stamp", "dev": "vp pack --watch", "typecheck": "tsc --noEmit" }, diff --git a/packages/platform/vite.config.ts b/packages/platform/vite.config.ts index 84c7423a5..d9151121e 100644 --- a/packages/platform/vite.config.ts +++ b/packages/platform/vite.config.ts @@ -3,6 +3,15 @@ import { defineConfig } from 'vite-plus'; export default defineConfig({ run: { tasks: { + // The middle step of the `build` script. It empties dist/runtime before writing it, which + // the task cache records as reading those files. `build:stamp` then edits the manifest in + // that directory, so without this exclusion the runtime build would never be a cache hit. + 'build:runtime': { + command: 'node scripts/build-runtime.mjs', + cache: { + input: [{ auto: true }, '!dist/runtime/**'], + }, + }, // The last step of the `build` script: records the source revision in the runtime manifest. // It isn't cached, so a new revision reruns only this step, and it gets the full // environment, including VOID_PLATFORM_SOURCE_REVISION. diff --git a/packages/void/test/helpers/cf-version-fixture.ts b/packages/void/test/helpers/cf-version-fixture.ts index 0b704127e..18c45982a 100644 --- a/packages/void/test/helpers/cf-version-fixture.ts +++ b/packages/void/test/helpers/cf-version-fixture.ts @@ -5,12 +5,13 @@ import type { AddressInfo } from 'node:net'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { afterEach, expect, vi } from 'vite-plus/test'; +import { afterAll, afterEach, expect, vi } from 'vite-plus/test'; import { prepareCfBuildOutput } from '../../src/cli/cf-build-output.ts'; import { createCfCommand } from '../../src/cli/cf-version-runner.ts'; // Vitest's per-file module isolation gives each suite its own roots and hooks. const roots: Array = []; +const outputRoots = new WeakMap(); const cleanups: Array<() => unknown> = []; const pinnedCfVersion = JSON.parse( readFileSync(fileURLToPath(import.meta.resolve('cf/package.json')), 'utf8'), @@ -23,9 +24,17 @@ const cfUserAgent: string = `cf-cli/${pinnedCfVersion} void/${voidVersion}`; const REAL_CF_TIMEOUT_MS: number = process.platform === 'win32' ? 20_000 : 15_000; const REAL_CF_ACTIVATION_TIMEOUT_MS: number = process.platform === 'win32' ? 60_000 : 30_000; -afterEach(async () => { - vi.restoreAllMocks(); - syncBuiltinESMExports(); +afterEach(({ task }) => { + // Only serial tests patch globals. Restoring after a concurrent test would also reset the + // local mocks of the tests still running beside it. + if (!task.concurrent) { + vi.restoreAllMocks(); + syncBuiltinESMExports(); + } +}); +// Concurrent tests share these lists, so one test's end must not release another test's +// servers and directories. Everything is released when the file ends. +afterAll(async () => { for (const cleanup of cleanups.splice(0).reverse()) { await cleanup(); } @@ -114,15 +123,26 @@ async function output( ); const prepared = await prepareCfBuildOutput(worker, 'account-id'); expect(prepared).not.toBeNull(); + outputRoots.set(prepared!, root); return prepared!; } +/** The project root that `output()` created for this prepared output. */ +function outputRoot(prepared: object): string { + const root = outputRoots.get(prepared); + if (!root) { + throw new Error('This output was not created by output().'); + } + return root; +} + export { cfUserAgent, cleanups, expectSameJson, listen, output, + outputRoot, pinnedCf, pinnedCfVersion, REAL_CF_ACTIVATION_TIMEOUT_MS, diff --git a/packages/void/test/helpers/cloudflare-operation-process.ts b/packages/void/test/helpers/cloudflare-operation-process.ts index 2d35b0f23..869e58cda 100644 --- a/packages/void/test/helpers/cloudflare-operation-process.ts +++ b/packages/void/test/helpers/cloudflare-operation-process.ts @@ -6,13 +6,17 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { pathToFileURL } from 'node:url'; import type { CloudflareOperation } from '@void/deploy-cloudflare'; -import { afterEach } from 'vite-plus/test'; +import { afterAll } from 'vite-plus/test'; import { encodeCloudflareOperation } from '../../src/cli/cloudflare-process.ts'; import { resolveCloudflareOperationArgv } from '../../src/cli/preset.ts'; -/** Cleanups run after each test, last registered first. Tests may push their own. */ +/** + * Cleanups run when the file ends, last registered first. Tests may push their own. + * Tests that only wait for a child process run concurrently, so the end of one test must not + * release the servers and directories of another. + */ export const cleanups: Array<() => unknown> = []; -afterEach(async () => { +afterAll(async () => { for (const cleanup of cleanups.splice(0).reverse()) { await cleanup(); } diff --git a/packages/void/test/integration/http-errors-playground-dev.test.ts b/packages/void/test/integration/http-errors-playground-dev.test.ts new file mode 100644 index 000000000..8d98c9c93 --- /dev/null +++ b/packages/void/test/integration/http-errors-playground-dev.test.ts @@ -0,0 +1,3 @@ +import { describeHttpErrorsPlayground } from './http-errors-playground-suite.ts'; + +describeHttpErrorsPlayground('dev'); diff --git a/packages/void/test/integration/http-errors-playground-production.test.ts b/packages/void/test/integration/http-errors-playground-production.test.ts new file mode 100644 index 000000000..8588fcb5c --- /dev/null +++ b/packages/void/test/integration/http-errors-playground-production.test.ts @@ -0,0 +1,3 @@ +import { describeHttpErrorsPlayground } from './http-errors-playground-suite.ts'; + +describeHttpErrorsPlayground('production'); diff --git a/packages/void/test/integration/http-errors-playground.test.ts b/packages/void/test/integration/http-errors-playground-suite.ts similarity index 97% rename from packages/void/test/integration/http-errors-playground.test.ts rename to packages/void/test/integration/http-errors-playground-suite.ts index 3f7a9bb6f..0a17993b9 100644 --- a/packages/void/test/integration/http-errors-playground.test.ts +++ b/packages/void/test/integration/http-errors-playground-suite.ts @@ -111,7 +111,14 @@ type PageData = { deferredKeys?: Record; }; -describe.each(['dev', 'production'] as const)('HTTP errors playground (%s)', (mode) => { +export type HttpErrorsMode = 'dev' | 'production'; + +/** Each mode runs from its own test file, so both servers and browser matrices run in parallel. */ +export function describeHttpErrorsPlayground(mode: HttpErrorsMode): void { + describe(`HTTP errors playground (${mode})`, () => httpErrorsSuite(mode)); +} + +function httpErrorsSuite(mode: HttpErrorsMode): void { let playground: IsolatedPlayground; let server: StartedServer; let browser: Browser; @@ -367,4 +374,4 @@ describe.each(['dev', 'production'] as const)('HTTP errors playground (%s)', (mo expect(await page.title()).toBe('HTTP Errors Example'); }); }); -}); +} diff --git a/packages/void/test/integration/page-errors-react.test.ts b/packages/void/test/integration/page-errors-react.test.ts new file mode 100644 index 000000000..18a166fb9 --- /dev/null +++ b/packages/void/test/integration/page-errors-react.test.ts @@ -0,0 +1,3 @@ +import { describePageErrors } from './page-errors-suite.ts'; + +describePageErrors('react'); diff --git a/packages/void/test/integration/page-errors-solid.test.ts b/packages/void/test/integration/page-errors-solid.test.ts new file mode 100644 index 000000000..31d39a842 --- /dev/null +++ b/packages/void/test/integration/page-errors-solid.test.ts @@ -0,0 +1,3 @@ +import { describePageErrors } from './page-errors-suite.ts'; + +describePageErrors('solid'); diff --git a/packages/void/test/integration/page-errors.test.ts b/packages/void/test/integration/page-errors-suite.ts similarity index 98% rename from packages/void/test/integration/page-errors.test.ts rename to packages/void/test/integration/page-errors-suite.ts index 5c284eef7..3e9eea013 100644 --- a/packages/void/test/integration/page-errors.test.ts +++ b/packages/void/test/integration/page-errors-suite.ts @@ -23,9 +23,17 @@ import { PAGES_PROTOCOL_VERSION } from '../../../edge/src/pages-protocol.ts'; import { deserializePageData } from '../../src/pages/serialize.ts'; const repository = join(import.meta.dirname, '../../../..'); -const frameworks = ['react', 'vue', 'svelte', 'solid'] as const; +export type PageErrorsFramework = 'react' | 'vue' | 'svelte' | 'solid'; -describe.each(frameworks)('Pages errors with %s', (framework) => { +/** + * Each framework runs from its own test file, so the four fixtures build and serve in parallel + * workers instead of one after another. + */ +export function describePageErrors(framework: PageErrorsFramework): void { + describe(`Pages errors with ${framework}`, () => pageErrorsSuite(framework)); +} + +function pageErrorsSuite(framework: PageErrorsFramework): void { let fixture: IsolatedPlayground; let child: ReturnType; let browser: Browser; @@ -708,4 +716,4 @@ export const loader = defineHandler(c => { expect(native404).not.toContain('type="module"'); } }); -}); +} diff --git a/packages/void/test/integration/page-errors-svelte.test.ts b/packages/void/test/integration/page-errors-svelte.test.ts new file mode 100644 index 000000000..acaa728a0 --- /dev/null +++ b/packages/void/test/integration/page-errors-svelte.test.ts @@ -0,0 +1,3 @@ +import { describePageErrors } from './page-errors-suite.ts'; + +describePageErrors('svelte'); diff --git a/packages/void/test/integration/page-errors-vue.test.ts b/packages/void/test/integration/page-errors-vue.test.ts new file mode 100644 index 000000000..69729fd49 --- /dev/null +++ b/packages/void/test/integration/page-errors-vue.test.ts @@ -0,0 +1,3 @@ +import { describePageErrors } from './page-errors-suite.ts'; + +describePageErrors('vue'); diff --git a/packages/void/test/integration/server-auth-errors-session.test.ts b/packages/void/test/integration/server-auth-errors-session.test.ts new file mode 100644 index 000000000..5bb21170d --- /dev/null +++ b/packages/void/test/integration/server-auth-errors-session.test.ts @@ -0,0 +1,3 @@ +import { describeServerAuthErrors } from './server-auth-errors-suite.ts'; + +describeServerAuthErrors('session'); diff --git a/packages/void/test/integration/server-auth-errors-signed-in.test.ts b/packages/void/test/integration/server-auth-errors-signed-in.test.ts new file mode 100644 index 000000000..7c09a41e0 --- /dev/null +++ b/packages/void/test/integration/server-auth-errors-signed-in.test.ts @@ -0,0 +1,3 @@ +import { describeServerAuthErrors } from './server-auth-errors-suite.ts'; + +describeServerAuthErrors('signed in'); diff --git a/packages/void/test/integration/server-auth-errors-signed-out.test.ts b/packages/void/test/integration/server-auth-errors-signed-out.test.ts new file mode 100644 index 000000000..e746e9f32 --- /dev/null +++ b/packages/void/test/integration/server-auth-errors-signed-out.test.ts @@ -0,0 +1,3 @@ +import { describeServerAuthErrors } from './server-auth-errors-suite.ts'; + +describeServerAuthErrors('signed out'); diff --git a/packages/void/test/integration/server-auth-errors.test.ts b/packages/void/test/integration/server-auth-errors-suite.ts similarity index 96% rename from packages/void/test/integration/server-auth-errors.test.ts rename to packages/void/test/integration/server-auth-errors-suite.ts index 62a2d5c10..9cd55811e 100644 --- a/packages/void/test/integration/server-auth-errors.test.ts +++ b/packages/void/test/integration/server-auth-errors-suite.ts @@ -139,10 +139,21 @@ async function expectRedirect( await page.waitForURL(`${server.base}${destination}`); } -describe.each([ - { state: 'signed out', signedIn: false }, - { state: 'signed in', signedIn: true }, -])('server auth: $state', ({ signedIn }) => { +export type ServerAuthErrorsPart = 'signed out' | 'signed in' | 'session'; + +/** + * Each part runs from its own test file with its own dev server and database, so the three + * serial browser matrices run in parallel workers. + */ +export function describeServerAuthErrors(part: ServerAuthErrorsPart): void { + if (part === 'session') { + describe('demo session and navigation', sessionSuite); + } else { + describe(`server auth: ${part}`, () => authStateSuite(part === 'signed in')); + } +} + +function authStateSuite(signedIn: boolean): void { beforeEach(() => newPage(signedIn)); describe.each(visits)('%s', (visit) => { @@ -268,9 +279,9 @@ describe.each([ expect(page.url()).toBe(`${server.base}/`); await expectLayout(timeOrigin, true); }); -}); +} -describe('demo session and navigation', () => { +function sessionSuite(): void { beforeEach(() => newPage()); it.each(['throw-redirect', 'auth-redirect'])( @@ -419,4 +430,4 @@ describe('demo session and navigation', () => { }) .toBe(false); }); -}); +} diff --git a/packages/void/test/unit/cf-build-output.test.ts b/packages/void/test/unit/cf-build-output.test.ts index 41b7c7680..b3ca61d68 100644 --- a/packages/void/test/unit/cf-build-output.test.ts +++ b/packages/void/test/unit/cf-build-output.test.ts @@ -32,7 +32,7 @@ import { } from '@void/deploy-cloudflare'; import { toSlash } from 'pathslash'; import { createBuilder } from 'vite'; -import { afterEach, expect, it, vi } from 'vite-plus/test'; +import { afterAll, afterEach, expect, it as serialIt, vi } from 'vite-plus/test'; import { type CfBuildOutput, prepareCfFrameworkBuildOutput, @@ -50,11 +50,19 @@ const roots: Array = []; const CF_BUILD_TIMEOUT_MS = process.platform === 'win32' ? 45_000 : 15_000; afterEach(() => { vi.unstubAllEnvs(); +}); +// Concurrent tests share this list, so directories are removed when the file ends. +afterAll(() => { for (const root of roots.splice(0)) { rmSync(root, { recursive: true, force: true }); } }); +// Most tests here wait for a real cf child process with their own directory and local API +// server, so they run concurrently. Tests that use `vi` run alone through serialIt: they patch +// globals, and Vitest clears every mock's call history whenever another test starts. +const it = serialIt.concurrent; + function worker(config: Record): string { const root = mkdtempSync(join(tmpdir(), 'void-cf-build-output-test-')); roots.push(root); @@ -418,7 +426,7 @@ it('returns only the public fields of the prepared output', async () => { }); }); -it.skipIf(process.platform === 'win32')( +serialIt.skipIf(process.platform === 'win32')( 'rejects a legacy asset symlink outside the asset directory', async () => { const output = worker({ @@ -439,13 +447,13 @@ it.skipIf(process.platform === 'win32')( }, ); -it.skipIf(process.platform === 'win32')('rejects symlinked native modules', async () => { +serialIt.skipIf(process.platform === 'win32')('rejects symlinked native modules', async () => { const root = await nativeBuild(); symlinkSync('index.js', join(getWorkerBundleDir(root), 'alias.js')); await expect(prepareCfBuildOutput(root)).rejects.toThrow('Symlinks are not permitted'); }); -it.skipIf(process.platform === 'win32')('rejects symlinked native assets', async () => { +serialIt.skipIf(process.platform === 'win32')('rejects symlinked native assets', async () => { const root = await nativeBuild(); const secret = join(root, 'secret.txt'); writeFileSync(secret, 'private'); @@ -853,7 +861,7 @@ it( CF_BUILD_TIMEOUT_MS, ); -it( +serialIt( 'keeps local .env client values out of framework Worker output', async () => { const root = mkdtempSync(join(tmpdir(), 'void-cf-framework-env-test-')); @@ -1316,7 +1324,7 @@ it('reads a framework config as JSONC and still rejects one that is not an objec } }); -it.skipIf(process.platform === 'win32')( +serialIt.skipIf(process.platform === 'win32')( 'builds a named Sandbox image into cf prebuilt output and cleans up its local tag', async () => { const output = worker({ diff --git a/packages/void/test/unit/cf-version-runner.test.ts b/packages/void/test/unit/cf-version-runner.test.ts index 7539ce59f..a877c9b43 100644 --- a/packages/void/test/unit/cf-version-runner.test.ts +++ b/packages/void/test/unit/cf-version-runner.test.ts @@ -15,7 +15,7 @@ import { } from '@cloudflare/build-output-utils'; import { BuildOutputContainerConfigSchema } from '@cloudflare/config'; import type { CloudflareCommandResult } from '@void/deploy-cloudflare'; -import { describe, expect, it, vi } from 'vite-plus/test'; +import { describe, expect, it as serialIt, vi } from 'vite-plus/test'; import { cloudflareCommandDiagnostic } from '../../../deploy-cloudflare/src/diagnostics.ts'; import { activateCloudflareVersion, @@ -41,6 +41,7 @@ import { expectSameJson, listen, output, + outputRoot, pinnedCf, pinnedCfVersion, REAL_CF_TIMEOUT_MS, @@ -48,6 +49,11 @@ import { voidVersion, } from '../helpers/cf-version-fixture.ts'; +// Most tests here wait for a real cf child process with their own directory and local API +// server, so they run concurrently. Tests that use `vi` run alone through serialIt: they patch +// globals, and Vitest clears every mock's call history whenever another test starts. +const it = serialIt.concurrent; + it.each([false, true])( 'uploads the same package versions as real cf when preserving secrets (atomic=%s)', async (atomic) => { @@ -1121,7 +1127,7 @@ it('reports a live version whose atomic upload lost its target', async () => { }); }); -it.each(['missing name', 'duplicate name', 'external collision', 'class collision'] as const)( +serialIt.each(['missing name', 'duplicate name', 'external collision', 'class collision'] as const)( 'rejects an invalid local Workflow declaration before any provider request: %s', async (mode) => { const prepared = await output({ secrets: { required: ['AUTH_SECRET'] } }); @@ -1244,7 +1250,7 @@ it.each(['missing', 'owned', 'foreign', 'malformed', 'unrelated 404'] as const)( }, ); -it.each([ +serialIt.each([ 'unsafe binding', 'unknown export', 'scheduler Container', @@ -1285,7 +1291,9 @@ it.each([ }); } const secretsFilePath = - mode === 'explicit secret collision' ? join(roots.at(-1)!, 'secrets.json') : undefined; + mode === 'explicit secret collision' + ? join(outputRoot(prepared), 'secrets.json') + : undefined; if (secretsFilePath) { writeFileSync(secretsFilePath, JSON.stringify({ AUTH_SECRET: 'private-secret' })); } @@ -1320,7 +1328,7 @@ it.each([ }, ); -it('refuses a new imageless Container before version publication', async () => { +serialIt('refuses a new imageless Container before version publication', async () => { const prepared = await containerOutput(); try { const built = await readBuildOutput(prepared.directory); @@ -1359,46 +1367,49 @@ it('refuses a new imageless Container before version publication', async () => { } }); -it('bounds pending Container image preparation before uploading a Worker version', async () => { - const prepared = await containerOutput(); - try { - let pending = false; - vi.spyOn(Date, 'now').mockImplementation(() => (pending ? 900_001 : 0)); - const requests: Array = []; - vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => { - requests.push(String(url)); - if (String(url).endsWith('/image-preparations')) { - pending = true; +serialIt( + 'bounds pending Container image preparation before uploading a Worker version', + async () => { + const prepared = await containerOutput(); + try { + let pending = false; + vi.spyOn(Date, 'now').mockImplementation(() => (pending ? 900_001 : 0)); + const requests: Array = []; + vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => { + requests.push(String(url)); + if (String(url).endsWith('/image-preparations')) { + pending = true; + return Response.json({ + success: true, + result: { image: containerImage, status: 'pending' }, + }); + } return Response.json({ success: true, - result: { image: containerImage, status: 'pending' }, + result: { + id: activePinnedVersion, + bindings: [{ name: 'AUTH_SECRET', type: 'secret_text' }], + }, }); - } - return Response.json({ - success: true, - result: { - id: activePinnedVersion, - bindings: [{ name: 'AUTH_SECRET', type: 'secret_text' }], - }, }); - }); - await expect( - uploadPinnedCloudflareVersion({ - output: prepared, - accountId: 'account-id', - apiBaseUrl: 'http://127.0.0.1:1', - workerName: 'void-test', - token: 'synthetic-token', - atomic: true, - verifyUploader: () => true, - }), - ).rejects.toThrow('image preparation timed out'); - expect(requests).toHaveLength(2); - expect(requests.at(-1)).toContain('/image-preparations'); - } finally { - await prepared.dispose(); - } -}); + await expect( + uploadPinnedCloudflareVersion({ + output: prepared, + accountId: 'account-id', + apiBaseUrl: 'http://127.0.0.1:1', + workerName: 'void-test', + token: 'synthetic-token', + atomic: true, + verifyUploader: () => true, + }), + ).rejects.toThrow('image preparation timed out'); + expect(requests).toHaveLength(2); + expect(requests.at(-1)).toContain('/image-preparations'); + } finally { + await prepared.dispose(); + } + }, +); const activePinnedVersion = '11111111-1111-4111-8111-111111111111'; const uploadedPinnedVersion = '22222222-2222-4222-8222-222222222222'; @@ -1641,7 +1652,7 @@ async function containerApi(mode: ContainerMode) { }; } -it.each(['settings-change', 'keys-change', 'readiness-failure'] as const)( +serialIt.each(['settings-change', 'keys-change', 'readiness-failure'] as const)( 'leaves the live Sandbox application unchanged when activation stops: %s', async (mode) => { const api = await containerApi(mode); @@ -1681,7 +1692,7 @@ it.each(['settings-change', 'keys-change', 'readiness-failure'] as const)( const result = await activateCloudflareVersion({ runWrangler: runner, workerName: 'void-test', - configPath: join(roots.at(-1)!, 'dist/ssr/wrangler.json'), + configPath: join(outputRoot(api.prepared), 'dist/ssr/wrangler.json'), verifyUploader: () => true, message: 'Verify Container candidate isolation.', readinessAttempts: 1, @@ -1710,7 +1721,7 @@ it.each(['settings-change', 'keys-change', 'readiness-failure'] as const)( }, ); -it.each([ +serialIt.each([ 'create', 'existing', 'pending', @@ -1966,7 +1977,7 @@ it.each([false, true])( workerName: 'void-test', runCf, verifyResources: createCfResourceVerifier({ - configPath: join(roots.at(-1)!, 'dist/ssr/wrangler.json'), + configPath: join(outputRoot(prepared), 'dist/ssr/wrangler.json'), runCf, runWrangler: () => { throw new Error('An app without paid bindings must not probe paid services.'); @@ -1983,7 +1994,7 @@ it.each([false, true])( const result = await activateCloudflareVersion({ runWrangler: runner, workerName: 'void-test', - configPath: join(roots.at(-1)!, 'dist/ssr/wrangler.json'), + configPath: join(outputRoot(prepared), 'dist/ssr/wrangler.json'), verifyUploader: () => true, pinActiveSecrets, atomic, @@ -2069,7 +2080,7 @@ it( REAL_CF_TIMEOUT_MS, ); -it.each([ +serialIt.each([ { diagnostic: 'synthetic provider failure [10007]', args: ['--version'] }, { diagnostic: 'You cannot upload a new version of a Worker that does not yet exist.', @@ -2425,7 +2436,7 @@ it.each([ verifyUploader: () => true, }, }); - const configPath = join(roots.at(-1)!, 'dist/ssr/wrangler.json'); + const configPath = join(outputRoot(prepared), 'dist/ssr/wrangler.json'); const result = await deployCloudflareVersionTriggers({ runWrangler: runner, workerName: 'void-test', @@ -2543,7 +2554,7 @@ it.each(['restore', 'remove'] as const)( }; const result = await deployCloudflareVersionTriggers({ workerName: 'void-test', - configPath: join(roots.at(-1)!, 'dist', 'ssr', 'wrangler.json'), + configPath: join(outputRoot(prepared), 'dist', 'ssr', 'wrangler.json'), runWrangler: runner, triggerConfig: { ...base, @@ -2614,7 +2625,7 @@ it( }); const result = await deployCloudflareVersionTriggers({ workerName: 'void-test', - configPath: join(roots.at(-1)!, 'dist', 'ssr', 'wrangler.json'), + configPath: join(outputRoot(prepared), 'dist', 'ssr', 'wrangler.json'), runWrangler: runner, triggerConfig: { workers_dev: false, @@ -2743,7 +2754,7 @@ it.each([ it('uses cf for Queue triggers, consumer cleanup, and version binding reads', async () => { const prepared = await output(); - const triggerConfig = join(roots.at(-1)!, 'legacy-trigger.json'); + const triggerConfig = join(outputRoot(prepared), 'legacy-trigger.json'); writeFileSync( triggerConfig, JSON.stringify({ name: 'void-test', queues: { consumers: [{ queue: 'jobs' }] } }), @@ -2872,7 +2883,7 @@ it.each(['r2', 'queue'] as const)( ? { queues: { producers: [{ binding: 'QUEUE', queue: 'jobs' }] } } : {}), }); - const triggerConfig = join(roots.at(-1)!, 'triggers.json'); + const triggerConfig = join(outputRoot(prepared), 'triggers.json'); writeFileSync(triggerConfig, JSON.stringify({ name: 'void-test', workers_dev: true })); const cfCalls: Array> = []; const runCf = (args: Array) => { @@ -2880,7 +2891,7 @@ it.each(['r2', 'queue'] as const)( return { status: 1, stdout: '', stderr: 'Resource not found.' }; }; const verifier = createCfResourceVerifier({ - configPath: join(roots.at(-1)!, 'dist', 'ssr', 'wrangler.json'), + configPath: join(outputRoot(prepared), 'dist', 'ssr', 'wrangler.json'), runCf, verifyCompatibilityRunner: () => true, runWrangler: operationFixture(async () => ({ @@ -2942,7 +2953,7 @@ it('uploads when existing R2 and Queue bindings are verified by exact identity', workerName: 'void-test', runCf, verifyResources: createCfResourceVerifier({ - configPath: join(roots.at(-1)!, 'dist', 'ssr', 'wrangler.json'), + configPath: join(outputRoot(prepared), 'dist', 'ssr', 'wrangler.json'), runCf, verifyCompatibilityRunner: () => true, runWrangler: operationFixture(async (args) => { @@ -2965,7 +2976,7 @@ it('uploads when existing R2 and Queue bindings are verified by exact identity', 'info', 'jobs', '-c', - join(roots.at(-1)!, 'dist', 'ssr', 'wrangler.json'), + join(outputRoot(prepared), 'dist', 'ssr', 'wrangler.json'), '--env=', ], ]); @@ -3078,7 +3089,7 @@ describe('session credential failures', () => { it('keeps the helper child status and crash for the settings publisher', async () => { const prepared = await output(); - const triggerConfig = join(roots.at(-1)!, 'trigger.json'); + const triggerConfig = join(outputRoot(prepared), 'trigger.json'); writeFileSync( triggerConfig, JSON.stringify({ name: 'void-test', observability: { enabled: true } }), @@ -3105,7 +3116,7 @@ describe('session credential failures', () => { } }); - it('never reads an auth failure as a missing Worker that needs a bootstrap', async () => { + serialIt('never reads an auth failure as a missing Worker that needs a bootstrap', async () => { const prepared = await output(); const getToken = vi.fn(async () => ({ ok: false as const, @@ -3231,7 +3242,7 @@ describe('settings credential before activation', () => { } }; - it.each([ + serialIt.each([ { label: 'observability', settings: { observability: { enabled: true } } }, { label: 'logpush', settings: { logpush: false } }, ])('stops before upload when the $label publisher has no credential', async ({ settings }) => { @@ -3250,7 +3261,7 @@ describe('settings credential before activation', () => { ); }); - it.each([ + serialIt.each([ { label: 'no Worker settings', config: triggers }, { label: 'a preserved snapshot', @@ -3291,7 +3302,7 @@ describe('settings credential before activation', () => { }), ); const prepared = await output(); - const triggerConfig = join(roots.at(-1)!, 'trigger.json'); + const triggerConfig = join(outputRoot(prepared), 'trigger.json'); writeFileSync( triggerConfig, JSON.stringify({ name: 'void-test', observability: { enabled: true } }), diff --git a/packages/void/test/unit/cf-version-transport.test.ts b/packages/void/test/unit/cf-version-transport.test.ts index 018f09313..012da9538 100644 --- a/packages/void/test/unit/cf-version-transport.test.ts +++ b/packages/void/test/unit/cf-version-transport.test.ts @@ -5,7 +5,7 @@ import { syncBuiltinESMExports } from 'node:module'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { getWorkerConfigPath } from '@cloudflare/build-output-utils'; -import { expect, it, vi } from 'vite-plus/test'; +import { expect, it as serialIt, vi } from 'vite-plus/test'; import { cloudflareCommandDiagnostic } from '../../../deploy-cloudflare/src/diagnostics.ts'; import { isVoidSecretOnlyDraft } from '../../../deploy-cloudflare/src/secret-draft.ts'; import { @@ -24,12 +24,18 @@ import { cfUserAgent, listen, output, + outputRoot, pinnedCf, REAL_CF_ACTIVATION_TIMEOUT_MS, REAL_CF_TIMEOUT_MS, roots, } from '../helpers/cf-version-fixture.ts'; +// Most tests here wait for a real cf child process with their own directory and local API +// server, so they run concurrently. Tests that use `vi` run alone through serialIt: they patch +// globals, and Vitest clears every mock's call history whenever another test starts. +const it = serialIt.concurrent; + it.each([false, true])( 'reads immutable version source through the real pinned cf HTTP transport (large=%s)', async (large) => { @@ -528,7 +534,7 @@ it.each([ verifyUploader: () => true, }, verifyResources: createCfResourceVerifier({ - configPath: join(roots.at(-1)!, 'dist/ssr/wrangler.json'), + configPath: join(outputRoot(prepared), 'dist/ssr/wrangler.json'), runCf, runWrangler: () => { throw new Error('An app without paid bindings must not probe paid services.'); @@ -538,7 +544,7 @@ it.each([ }); const result = await activateCloudflareVersion({ runWrangler: runner, - configPath: join(roots.at(-1)!, 'dist/ssr/wrangler.json'), + configPath: join(outputRoot(prepared), 'dist/ssr/wrangler.json'), workerName: 'void-test', verifyUploader: () => true, verifyInheritedSecrets: true, @@ -642,7 +648,7 @@ it( REAL_CF_TIMEOUT_MS, ); -it.runIf(process.platform !== 'win32')( +serialIt.runIf(process.platform !== 'win32')( 'bounds a Container command by terminating its actual child and descendant before returning', async () => { const originalSpawn = childProcess.spawn; diff --git a/packages/void/test/unit/cloudflare-operation-process.test.ts b/packages/void/test/unit/cloudflare-operation-process.test.ts index be72b235d..fe3122e82 100644 --- a/packages/void/test/unit/cloudflare-operation-process.test.ts +++ b/packages/void/test/unit/cloudflare-operation-process.test.ts @@ -5,7 +5,7 @@ import type { AddressInfo } from 'node:net'; import { connect } from 'node:net'; import { join } from 'node:path'; import type { Duplex } from 'node:stream'; -import { expect, it } from 'vite-plus/test'; +import { expect, it as serialIt } from 'vite-plus/test'; import { isVoidSecretOnlyDraft } from '../../../deploy-cloudflare/src/secret-draft.ts'; import { voidSecretDraftVersion } from '../../../deploy-cloudflare/test/secret-draft-fixture.ts'; import { @@ -24,6 +24,10 @@ import { tokenEnv, } from '../helpers/cloudflare-operation-process.ts'; +// Each test waits for a real child process with its own directory and local API server. +// Running them concurrently overlaps those waits; every test still spawns its own process. +const it = serialIt.concurrent; + const voidVersion = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')) .version as string; const cfVersion = JSON.parse(readFileSync(new URL(import.meta.resolve('cf/package.json')), 'utf8')) diff --git a/test/integration-timings.ts b/test/integration-timings.ts index ef386ccae..5f3f4d736 100644 --- a/test/integration-timings.ts +++ b/test/integration-timings.ts @@ -1,5 +1,7 @@ // Windows file durations measured in https://github.com/voidzero-dev/void/actions/runs/36572350995. // Edited suites use conservative estimates adjusted for removed browser cases and duplicate builds. +// The split browser suites (page-errors-*, server-auth-errors-*, http-errors-playground-*) use twice +// their local macOS durations until a Windows run supplies measured values. // These values schedule shards only; every discovered test is still included. export const integrationTimings: Readonly> = { 'packages/md/test/integration/markdown-blog.test.ts': 42014, @@ -12,14 +14,16 @@ export const integrationTimings: Readonly> = { 'packages/void/test/integration/astro.test.ts': 26000, 'packages/void/test/integration/cli-help.test.ts': 1718, 'packages/void/test/integration/cli-runtime-check.test.ts': 900, - 'packages/void/test/integration/cloudflare-durable-build.test.ts': 15000, 'packages/void/test/integration/cloudflare-deploy-build.test.ts': 6700, + 'packages/void/test/integration/cloudflare-durable-build.test.ts': 15000, 'packages/void/test/integration/cloudflare-isr-policy.test.ts': 15391, 'packages/void/test/integration/durable-state-rpc.test.ts': 1160, 'packages/void/test/integration/env-cli.test.ts': 2970, 'packages/void/test/integration/env-server-build.test.ts': 873, 'packages/void/test/integration/env-types-typecheck.test.ts': 1395, 'packages/void/test/integration/full-deploy-manifest.test.ts': 6370, + 'packages/void/test/integration/http-errors-playground-dev.test.ts': 40000, + 'packages/void/test/integration/http-errors-playground-production.test.ts': 37000, 'packages/void/test/integration/kitchen-sink-build.test.ts': 7365, 'packages/void/test/integration/kitchen-sink.test.ts': 20887, 'packages/void/test/integration/mysql-test.test.ts': 11000, @@ -30,6 +34,10 @@ export const integrationTimings: Readonly> = { 'packages/void/test/integration/node-target.test.ts': 10833, 'packages/void/test/integration/nuxt.test.ts': 43000, 'packages/void/test/integration/operator-cli.test.ts': 4910, + 'packages/void/test/integration/page-errors-react.test.ts': 27000, + 'packages/void/test/integration/page-errors-solid.test.ts': 16000, + 'packages/void/test/integration/page-errors-svelte.test.ts': 17000, + 'packages/void/test/integration/page-errors-vue.test.ts': 15000, 'packages/void/test/integration/pages-target-assets.test.ts': 10966, 'packages/void/test/integration/pg-api-test.test.ts': 11000, 'packages/void/test/integration/pg-test.test.ts': 16237, @@ -38,6 +46,9 @@ export const integrationTimings: Readonly> = { 'packages/void/test/integration/queue-dispatch.test.ts': 208, 'packages/void/test/integration/react-router.test.ts': 21000, 'packages/void/test/integration/sandbox-managed-rpc.test.ts': 722, + 'packages/void/test/integration/server-auth-errors-session.test.ts': 31000, + 'packages/void/test/integration/server-auth-errors-signed-in.test.ts': 32000, + 'packages/void/test/integration/server-auth-errors-signed-out.test.ts': 31000, 'packages/void/test/integration/spa-middleware-auth.test.ts': 26264, 'packages/void/test/integration/ssr-playground.test.ts': 13008, 'packages/void/test/integration/static-pages.test.ts': 7034, diff --git a/vite.config.ts b/vite.config.ts index e960c9262..ce84b93e5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,6 +18,7 @@ const pgliteUnitTests = [ ]; const cliUnitTests = [ 'packages/void/test/unit/cf-*.test.ts', + 'packages/void/test/unit/cloudflare-operation-process*.test.ts', 'packages/void/test/unit/provision-*.test.ts', 'packages/void/test/unit/deploy-drift.test.ts', ]; @@ -461,7 +462,10 @@ export default defineConfig({ include: cliUnitTests, pool: 'threads', maxWorkers, - ...(process.platform === 'win32' ? { testTimeout: 20_000 } : {}), + // These files run their real subprocess tests concurrently. A test then also waits + // while its neighbours block the thread in a synchronous spawn, so Vitest's 5-second + // default is too short on a busy machine. + testTimeout: 20_000, }, }, {