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