mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
test: decouple vitest config checks from ambient env
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import channelsConfig from "../vitest.channels.config.ts";
|
import { createChannelsVitestConfig } from "../vitest.channels.config.ts";
|
||||||
import { createExtensionsVitestConfig } from "../vitest.extensions.config.ts";
|
import { createExtensionsVitestConfig } from "../vitest.extensions.config.ts";
|
||||||
import { createGatewayVitestConfig } from "../vitest.gateway.config.ts";
|
import { createGatewayVitestConfig } from "../vitest.gateway.config.ts";
|
||||||
import { createScopedVitestConfig, resolveVitestIsolation } from "../vitest.scoped-config.ts";
|
import { createScopedVitestConfig, resolveVitestIsolation } from "../vitest.scoped-config.ts";
|
||||||
@@ -18,13 +18,14 @@ describe("resolveVitestIsolation", () => {
|
|||||||
|
|
||||||
describe("createScopedVitestConfig", () => {
|
describe("createScopedVitestConfig", () => {
|
||||||
it("applies non-isolated mode by default", () => {
|
it("applies non-isolated mode by default", () => {
|
||||||
const config = createScopedVitestConfig(["src/example.test.ts"]);
|
const config = createScopedVitestConfig(["src/example.test.ts"], { env: {} });
|
||||||
expect(config.test?.isolate).toBe(false);
|
expect(config.test?.isolate).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes through a scoped root dir when provided", () => {
|
it("passes through a scoped root dir when provided", () => {
|
||||||
const config = createScopedVitestConfig(["src/example.test.ts"], {
|
const config = createScopedVitestConfig(["src/example.test.ts"], {
|
||||||
dir: "src",
|
dir: "src",
|
||||||
|
env: {},
|
||||||
});
|
});
|
||||||
expect(config.test?.dir).toBe("src");
|
expect(config.test?.dir).toBe("src");
|
||||||
expect(config.test?.include).toEqual(["example.test.ts"]);
|
expect(config.test?.include).toEqual(["example.test.ts"]);
|
||||||
@@ -33,6 +34,7 @@ describe("createScopedVitestConfig", () => {
|
|||||||
it("relativizes scoped include and exclude patterns to the configured dir", () => {
|
it("relativizes scoped include and exclude patterns to the configured dir", () => {
|
||||||
const config = createScopedVitestConfig(["extensions/**/*.test.ts"], {
|
const config = createScopedVitestConfig(["extensions/**/*.test.ts"], {
|
||||||
dir: "extensions",
|
dir: "extensions",
|
||||||
|
env: {},
|
||||||
exclude: ["extensions/channel/**", "dist/**"],
|
exclude: ["extensions/channel/**", "dist/**"],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,11 +44,12 @@ describe("createScopedVitestConfig", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("scoped vitest configs", () => {
|
describe("scoped vitest configs", () => {
|
||||||
|
const defaultChannelsConfig = createChannelsVitestConfig({});
|
||||||
const defaultExtensionsConfig = createExtensionsVitestConfig({});
|
const defaultExtensionsConfig = createExtensionsVitestConfig({});
|
||||||
const defaultGatewayConfig = createGatewayVitestConfig();
|
const defaultGatewayConfig = createGatewayVitestConfig({});
|
||||||
|
|
||||||
it("defaults channel tests to non-isolated mode", () => {
|
it("defaults channel tests to non-isolated mode", () => {
|
||||||
expect(channelsConfig.test?.isolate).toBe(false);
|
expect(defaultChannelsConfig.test?.isolate).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("defaults extension tests to non-isolated mode", () => {
|
it("defaults extension tests to non-isolated mode", () => {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import fs from "node:fs";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
import unitConfig from "../vitest.unit.config.ts";
|
|
||||||
import {
|
import {
|
||||||
|
createUnitVitestConfig,
|
||||||
loadExtraExcludePatternsFromEnv,
|
loadExtraExcludePatternsFromEnv,
|
||||||
loadIncludePatternsFromEnv,
|
loadIncludePatternsFromEnv,
|
||||||
} from "../vitest.unit.config.ts";
|
} from "../vitest.unit.config.ts";
|
||||||
@@ -81,6 +81,7 @@ describe("loadExtraExcludePatternsFromEnv", () => {
|
|||||||
|
|
||||||
describe("unit vitest config", () => {
|
describe("unit vitest config", () => {
|
||||||
it("defaults unit tests to non-isolated mode", () => {
|
it("defaults unit tests to non-isolated mode", () => {
|
||||||
|
const unitConfig = createUnitVitestConfig({});
|
||||||
expect(unitConfig.test?.isolate).toBe(false);
|
expect(unitConfig.test?.isolate).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { channelTestInclude } from "./vitest.channel-paths.mjs";
|
import { channelTestInclude } from "./vitest.channel-paths.mjs";
|
||||||
import { createScopedVitestConfig } from "./vitest.scoped-config.ts";
|
import { createScopedVitestConfig } from "./vitest.scoped-config.ts";
|
||||||
|
|
||||||
export default createScopedVitestConfig(channelTestInclude, {
|
export function createChannelsVitestConfig(env?: Record<string, string | undefined>) {
|
||||||
pool: "threads",
|
return createScopedVitestConfig(channelTestInclude, {
|
||||||
exclude: ["src/gateway/**"],
|
env,
|
||||||
});
|
pool: "threads",
|
||||||
|
exclude: ["src/gateway/**"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createChannelsVitestConfig();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export function createExtensionsVitestConfig(
|
|||||||
) {
|
) {
|
||||||
return createScopedVitestConfig(loadIncludePatternsFromEnv(env) ?? ["extensions/**/*.test.ts"], {
|
return createScopedVitestConfig(loadIncludePatternsFromEnv(env) ?? ["extensions/**/*.test.ts"], {
|
||||||
dir: "extensions",
|
dir: "extensions",
|
||||||
|
env,
|
||||||
pool: "threads",
|
pool: "threads",
|
||||||
passWithNoTests: true,
|
passWithNoTests: true,
|
||||||
// Channel implementations live under extensions/ but are tested by
|
// Channel implementations live under extensions/ but are tested by
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { createScopedVitestConfig } from "./vitest.scoped-config.ts";
|
import { createScopedVitestConfig } from "./vitest.scoped-config.ts";
|
||||||
|
|
||||||
export function createGatewayVitestConfig() {
|
export function createGatewayVitestConfig(env?: Record<string, string | undefined>) {
|
||||||
return createScopedVitestConfig(["src/gateway/**/*.test.ts"], {
|
return createScopedVitestConfig(["src/gateway/**/*.test.ts"], {
|
||||||
dir: "src/gateway",
|
dir: "src/gateway",
|
||||||
|
env,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export function createScopedVitestConfig(
|
|||||||
include: string[],
|
include: string[],
|
||||||
options?: {
|
options?: {
|
||||||
dir?: string;
|
dir?: string;
|
||||||
|
env?: Record<string, string | undefined>;
|
||||||
exclude?: string[];
|
exclude?: string[];
|
||||||
pool?: "threads" | "forks";
|
pool?: "threads" | "forks";
|
||||||
passWithNoTests?: boolean;
|
passWithNoTests?: boolean;
|
||||||
@@ -68,7 +69,7 @@ export function createScopedVitestConfig(
|
|||||||
...base,
|
...base,
|
||||||
test: {
|
test: {
|
||||||
...baseTest,
|
...baseTest,
|
||||||
isolate: resolveVitestIsolation(),
|
isolate: resolveVitestIsolation(options?.env),
|
||||||
...(scopedDir ? { dir: scopedDir } : {}),
|
...(scopedDir ? { dir: scopedDir } : {}),
|
||||||
include: relativizeScopedPatterns(include, scopedDir),
|
include: relativizeScopedPatterns(include, scopedDir),
|
||||||
exclude,
|
exclude,
|
||||||
|
|||||||
@@ -38,19 +38,23 @@ export function loadExtraExcludePatternsFromEnv(
|
|||||||
return loadPatternListFile(extraExcludeFile, "OPENCLAW_VITEST_EXTRA_EXCLUDE_FILE");
|
return loadPatternListFile(extraExcludeFile, "OPENCLAW_VITEST_EXTRA_EXCLUDE_FILE");
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export function createUnitVitestConfig(env: Record<string, string | undefined> = process.env) {
|
||||||
...base,
|
return defineConfig({
|
||||||
test: {
|
...base,
|
||||||
...baseTest,
|
test: {
|
||||||
isolate: resolveVitestIsolation(),
|
...baseTest,
|
||||||
runner: "./test/non-isolated-runner.ts",
|
isolate: resolveVitestIsolation(env),
|
||||||
include: loadIncludePatternsFromEnv() ?? unitTestIncludePatterns,
|
runner: "./test/non-isolated-runner.ts",
|
||||||
exclude: [
|
include: loadIncludePatternsFromEnv(env) ?? unitTestIncludePatterns,
|
||||||
...new Set([
|
exclude: [
|
||||||
...exclude,
|
...new Set([
|
||||||
...unitTestAdditionalExcludePatterns,
|
...exclude,
|
||||||
...loadExtraExcludePatternsFromEnv(),
|
...unitTestAdditionalExcludePatterns,
|
||||||
]),
|
...loadExtraExcludePatternsFromEnv(env),
|
||||||
],
|
]),
|
||||||
},
|
],
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createUnitVitestConfig();
|
||||||
|
|||||||
Reference in New Issue
Block a user