mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: restore moved Vitest config paths
This commit is contained in:
@@ -203,12 +203,13 @@ describe("base vitest config", () => {
|
||||
});
|
||||
|
||||
it("keeps the base setup file minimal", () => {
|
||||
expect(baseConfig.test?.setupFiles).toEqual(["test/setup.ts"]);
|
||||
expect(baseConfig.test?.setupFiles).toHaveLength(1);
|
||||
expect(baseConfig.test?.setupFiles?.[0]).toMatch(/(?:^|\/)test\/setup\.ts$/u);
|
||||
});
|
||||
|
||||
it("keeps the base runner non-isolated by default", () => {
|
||||
expect(baseConfig.test?.isolate).toBe(false);
|
||||
expect(baseConfig.test?.runner).toBe("./test/non-isolated-runner.ts");
|
||||
expect(baseConfig.test?.runner).toMatch(/(?:^|\/)test\/non-isolated-runner\.ts$/u);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "../plugin-sdk/facade-loader.js";
|
||||
@@ -74,16 +75,34 @@ export function resolveBundledPluginPublicModulePath(params: {
|
||||
);
|
||||
}
|
||||
|
||||
function resolveVitestSourceModulePath(targetPath: string): string {
|
||||
if (!targetPath.endsWith(".js")) {
|
||||
return targetPath;
|
||||
}
|
||||
const sourcePath = `${targetPath.slice(0, -".js".length)}.ts`;
|
||||
return pathExists(sourcePath) ? sourcePath : targetPath;
|
||||
}
|
||||
|
||||
function pathExists(filePath: string): boolean {
|
||||
try {
|
||||
return Boolean(filePath) && path.isAbsolute(filePath) && fs.statSync(filePath).isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveRelativeBundledPluginPublicModuleId(params: {
|
||||
fromModuleUrl: string;
|
||||
pluginId: string;
|
||||
artifactBasename: string;
|
||||
}): string {
|
||||
const fromFilePath = fileURLToPath(params.fromModuleUrl);
|
||||
const targetPath = resolveBundledPluginPublicModulePath({
|
||||
pluginId: params.pluginId,
|
||||
artifactBasename: params.artifactBasename,
|
||||
});
|
||||
const targetPath = resolveVitestSourceModulePath(
|
||||
resolveBundledPluginPublicModulePath({
|
||||
pluginId: params.pluginId,
|
||||
artifactBasename: params.artifactBasename,
|
||||
}),
|
||||
);
|
||||
const relativePath = path
|
||||
.relative(path.dirname(fromFilePath), targetPath)
|
||||
.replaceAll(path.sep, "/");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defineProject } from "vitest/config";
|
||||
import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts";
|
||||
import { resolveVitestIsolation } from "./vitest.scoped-config.ts";
|
||||
import { sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import { boundaryTestFiles } from "./vitest.unit-paths.mjs";
|
||||
|
||||
export function loadBoundaryIncludePatternsFromEnv(
|
||||
@@ -22,7 +22,7 @@ export function createBoundaryVitestConfig(
|
||||
...sharedVitestConfig.test,
|
||||
name: "boundary",
|
||||
isolate,
|
||||
...(isolate ? { runner: undefined } : { runner: "./test/non-isolated-runner.ts" }),
|
||||
...(isolate ? { runner: undefined } : { runner: nonIsolatedRunnerPath }),
|
||||
include: loadBoundaryIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? boundaryTestFiles,
|
||||
...(cliIncludePatterns !== null ? { passWithNoTests: true } : {}),
|
||||
// Boundary workers still need the shared isolated HOME/bootstrap. Only
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
resolveDefaultVitestPool,
|
||||
resolveLocalVitestMaxWorkers,
|
||||
resolveLocalVitestScheduling,
|
||||
nonIsolatedRunnerPath,
|
||||
sharedVitestConfig,
|
||||
} from "./vitest.shared.config.ts";
|
||||
|
||||
@@ -68,7 +69,7 @@ export default defineConfig({
|
||||
...sharedVitestConfig,
|
||||
test: {
|
||||
...sharedVitestConfig.test,
|
||||
runner: "./test/non-isolated-runner.ts",
|
||||
runner: nonIsolatedRunnerPath,
|
||||
projects: [...rootVitestProjects],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
|
||||
const base = sharedVitestConfig as Record<string, unknown>;
|
||||
const baseTest = sharedVitestConfig.test ?? {};
|
||||
@@ -10,7 +10,7 @@ export function createContractsVitestConfig() {
|
||||
test: {
|
||||
...baseTest,
|
||||
isolate: false,
|
||||
runner: "./test/non-isolated-runner.ts",
|
||||
runner: nonIsolatedRunnerPath,
|
||||
setupFiles: baseTest.setupFiles ?? [],
|
||||
include: [
|
||||
"src/channels/plugins/contracts/**/*.test.ts",
|
||||
|
||||
@@ -2,6 +2,7 @@ import os from "node:os";
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { BUNDLED_PLUGIN_E2E_TEST_GLOB } from "./vitest.bundled-plugin-paths.ts";
|
||||
import baseConfig from "./vitest.config.ts";
|
||||
import { resolveRepoRootPath } from "./vitest.shared.config.ts";
|
||||
|
||||
const base = baseConfig as unknown as Record<string, unknown>;
|
||||
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
|
||||
@@ -31,7 +32,11 @@ export default defineConfig({
|
||||
...baseTest,
|
||||
maxWorkers: e2eWorkers,
|
||||
silent: !verboseE2E,
|
||||
setupFiles: [...new Set([...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"])],
|
||||
setupFiles: [
|
||||
...new Set(
|
||||
[...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(resolveRepoRootPath),
|
||||
),
|
||||
],
|
||||
include: [
|
||||
"test/**/*.e2e.test.ts",
|
||||
"src/**/*.e2e.test.ts",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { BUNDLED_PLUGIN_LIVE_TEST_GLOB } from "./vitest.bundled-plugin-paths.ts";
|
||||
import baseConfig from "./vitest.config.ts";
|
||||
import { resolveRepoRootPath } from "./vitest.shared.config.ts";
|
||||
|
||||
const base = baseConfig as unknown as Record<string, unknown>;
|
||||
const baseTestWithProjects =
|
||||
@@ -20,7 +21,11 @@ export default defineConfig({
|
||||
// Vitest's buffered per-test console capture.
|
||||
disableConsoleIntercept: true,
|
||||
maxWorkers: 1,
|
||||
setupFiles: [...new Set([...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"])],
|
||||
setupFiles: [
|
||||
...new Set(
|
||||
[...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(resolveRepoRootPath),
|
||||
),
|
||||
],
|
||||
include: ["src/**/*.live.test.ts", "test/**/*.live.test.ts", BUNDLED_PLUGIN_LIVE_TEST_GLOB],
|
||||
exclude,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
|
||||
export function createProjectShardVitestConfig(projects: readonly string[]) {
|
||||
const maxWorkers = sharedVitestConfig.test.maxWorkers;
|
||||
@@ -10,7 +10,7 @@ export function createProjectShardVitestConfig(projects: readonly string[]) {
|
||||
...sharedVitestConfig,
|
||||
test: {
|
||||
...sharedVitestConfig.test,
|
||||
runner: "./test/non-isolated-runner.ts",
|
||||
runner: nonIsolatedRunnerPath,
|
||||
projects: [...projects],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import path from "node:path";
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts";
|
||||
import { repoRoot, sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import {
|
||||
nonIsolatedRunnerPath,
|
||||
repoRoot,
|
||||
resolveRepoRootPath,
|
||||
sharedVitestConfig,
|
||||
} from "./vitest.shared.config.ts";
|
||||
import { unitFastTestFiles } from "./vitest.unit-fast-paths.mjs";
|
||||
|
||||
function normalizePathPattern(value: string): string {
|
||||
@@ -160,9 +165,9 @@ export function createScopedVitestConfig(
|
||||
...(options?.setupFiles ?? []),
|
||||
...(options?.includeOpenClawRuntimeSetup === false ? [] : ["test/setup-openclaw-runtime.ts"]),
|
||||
]),
|
||||
];
|
||||
].map(resolveRepoRootPath);
|
||||
const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate;
|
||||
const runner = useNonIsolatedRunner ? "./test/non-isolated-runner.ts" : undefined;
|
||||
const runner = useNonIsolatedRunner ? nonIsolatedRunnerPath : undefined;
|
||||
const scopedGroupOrder = resolveScopedProjectGroupOrder(options?.name, scopedDir, include);
|
||||
|
||||
return defineConfig({
|
||||
|
||||
@@ -160,6 +160,10 @@ export function resolveDefaultVitestPool(
|
||||
}
|
||||
|
||||
export const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
export const nonIsolatedRunnerPath = path.join(repoRoot, "test", "non-isolated-runner.ts");
|
||||
export function resolveRepoRootPath(value: string): string {
|
||||
return path.isAbsolute(value) ? value : path.join(repoRoot, value);
|
||||
}
|
||||
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
|
||||
const isWindows = process.platform === "win32";
|
||||
const defaultPool = resolveDefaultVitestPool();
|
||||
@@ -208,7 +212,7 @@ export const sharedVitestConfig = {
|
||||
unstubGlobals: true,
|
||||
isolate: false,
|
||||
pool: defaultPool,
|
||||
runner: "./test/non-isolated-runner.ts",
|
||||
runner: nonIsolatedRunnerPath,
|
||||
maxWorkers: isCI ? ciWorkers : localScheduling.maxWorkers,
|
||||
fileParallelism: isCI ? true : localScheduling.fileParallelism,
|
||||
forceRerunTriggers: [
|
||||
@@ -315,7 +319,7 @@ export const sharedVitestConfig = {
|
||||
"ui/src/ui/app-gateway.sessions.node.test.ts",
|
||||
"ui/src/ui/chat/slash-command-executor.node.test.ts",
|
||||
],
|
||||
setupFiles: ["test/setup.ts"],
|
||||
setupFiles: [resolveRepoRootPath("test/setup.ts")],
|
||||
exclude: [
|
||||
"dist/**",
|
||||
"test/fixtures/**",
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { defineProject } from "vitest/config";
|
||||
import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts";
|
||||
import { resolveVitestIsolation } from "./vitest.scoped-config.ts";
|
||||
import { sharedVitestConfig } from "./vitest.shared.config.ts";
|
||||
import {
|
||||
nonIsolatedRunnerPath,
|
||||
resolveRepoRootPath,
|
||||
sharedVitestConfig,
|
||||
} from "./vitest.shared.config.ts";
|
||||
import { unitFastTestFiles } from "./vitest.unit-fast-paths.mjs";
|
||||
import {
|
||||
isBundledPluginDependentUnitTestFile,
|
||||
@@ -51,9 +55,13 @@ export function createUnitVitestConfigWithOptions(
|
||||
...sharedTest,
|
||||
name: options.name ?? "unit",
|
||||
isolate,
|
||||
...(isolate ? { runner: undefined } : { runner: "./test/non-isolated-runner.ts" }),
|
||||
...(isolate ? { runner: undefined } : { runner: nonIsolatedRunnerPath }),
|
||||
setupFiles: [
|
||||
...new Set([...(sharedTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"]),
|
||||
...new Set(
|
||||
[...(sharedTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(
|
||||
resolveRepoRootPath,
|
||||
),
|
||||
),
|
||||
],
|
||||
include: loadIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? defaultIncludePatterns,
|
||||
exclude: [
|
||||
|
||||
Reference in New Issue
Block a user