test: default scoped vitest configs to no-isolate

This commit is contained in:
Peter Steinberger 2026-03-22 19:09:26 -07:00
parent 74cb08bede
commit 3ccf1bee2c
No known key found for this signature in database
5 changed files with 55 additions and 1 deletions

View File

@ -73,7 +73,8 @@ Think of the suites as “increasing realism” (and increasing flakiness/cost):
- Base Vitest config still defaults to `forks`.
- Unit wrapper lanes default to `threads`, with explicit manifest fork-only exceptions.
- Extension scoped config defaults to `threads`.
- `pnpm test` also defaults to `--isolate=false` at the wrapper level for faster file startup.
- Unit, channel, and extension configs default to `isolate: false` for faster file startup.
- `pnpm test` also passes `--isolate=false` at the wrapper level.
- Opt back into Vitest file isolation with `OPENCLAW_TEST_ISOLATE=1 pnpm test`.
- `OPENCLAW_TEST_NO_ISOLATE=0` or `OPENCLAW_TEST_NO_ISOLATE=false` also force isolated runs.

View File

@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import channelsConfig from "../vitest.channels.config.ts";
import extensionsConfig from "../vitest.extensions.config.ts";
import { createScopedVitestConfig, resolveVitestIsolation } from "../vitest.scoped-config.ts";
describe("resolveVitestIsolation", () => {
it("defaults shared scoped configs to non-isolated workers", () => {
expect(resolveVitestIsolation({})).toBe(false);
});
it("restores isolate mode when explicitly requested", () => {
expect(resolveVitestIsolation({ OPENCLAW_TEST_ISOLATE: "1" })).toBe(true);
expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "0" })).toBe(true);
expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "false" })).toBe(true);
});
});
describe("createScopedVitestConfig", () => {
it("applies non-isolated mode by default", () => {
const config = createScopedVitestConfig(["src/example.test.ts"]);
expect(config.test?.isolate).toBe(false);
});
});
describe("scoped vitest configs", () => {
it("defaults channel tests to non-isolated mode", () => {
expect(channelsConfig.test?.isolate).toBe(false);
});
it("defaults extension tests to non-isolated mode", () => {
expect(extensionsConfig.test?.isolate).toBe(false);
});
});

View File

@ -2,6 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import unitConfig from "../vitest.unit.config.ts";
import {
loadExtraExcludePatternsFromEnv,
loadIncludePatternsFromEnv,
@ -77,3 +78,9 @@ describe("loadExtraExcludePatternsFromEnv", () => {
).toThrow(/JSON array/u);
});
});
describe("unit vitest config", () => {
it("defaults unit tests to non-isolated mode", () => {
expect(unitConfig.test?.isolate).toBe(false);
});
});

View File

@ -1,6 +1,16 @@
import { defineConfig } from "vitest/config";
import baseConfig from "./vitest.config.ts";
export function resolveVitestIsolation(
env: Record<string, string | undefined> = process.env,
): boolean {
const forceIsolation = env.OPENCLAW_TEST_ISOLATE === "1" || env.OPENCLAW_TEST_ISOLATE === "true";
if (forceIsolation) {
return true;
}
return env.OPENCLAW_TEST_NO_ISOLATE === "0" || env.OPENCLAW_TEST_NO_ISOLATE === "false";
}
export function createScopedVitestConfig(
include: string[],
options?: { exclude?: string[]; pool?: "threads" | "forks" },
@ -14,6 +24,7 @@ export function createScopedVitestConfig(
...base,
test: {
...baseTest,
isolate: resolveVitestIsolation(),
include,
exclude,
...(options?.pool ? { pool: options.pool } : {}),

View File

@ -1,6 +1,7 @@
import fs from "node:fs";
import { defineConfig } from "vitest/config";
import baseConfig from "./vitest.config.ts";
import { resolveVitestIsolation } from "./vitest.scoped-config.ts";
import {
unitTestAdditionalExcludePatterns,
unitTestIncludePatterns,
@ -41,6 +42,7 @@ export default defineConfig({
...base,
test: {
...baseTest,
isolate: resolveVitestIsolation(),
runner: "./test/non-isolated-runner.ts",
include: loadIncludePatternsFromEnv() ?? unitTestIncludePatterns,
exclude: [