mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 03:50:43 +00:00
test: tighten scoped config setup assertions
This commit is contained in:
@@ -85,6 +85,14 @@ function matchingExcludePatterns(patterns: string[], file: string): string[] {
|
||||
return patterns.filter((pattern) => path.matchesGlob(file, pattern));
|
||||
}
|
||||
|
||||
function requireTestConfig<T extends { test?: unknown }>(config: T): NonNullable<T["test"]> {
|
||||
expect(config.test).toBeDefined();
|
||||
if (!config.test) {
|
||||
throw new Error("expected scoped vitest test config");
|
||||
}
|
||||
return config.test as NonNullable<T["test"]>;
|
||||
}
|
||||
|
||||
describe("resolveVitestIsolation", () => {
|
||||
it("aliases private QA plugin SDK subpaths for source tests only", () => {
|
||||
expect(sharedVitestConfig.resolve.alias).toEqual(
|
||||
@@ -120,19 +128,21 @@ describe("resolveVitestIsolation", () => {
|
||||
|
||||
it("resolves scoped discovery dirs from the repo root after config relocation", () => {
|
||||
const config = createExtensionMatrixVitestConfig({});
|
||||
const testConfig = requireTestConfig(config);
|
||||
|
||||
expect(config.root).toBe(process.cwd());
|
||||
expect(config.test?.dir).toBe(path.join(process.cwd(), "extensions"));
|
||||
expect(config.test?.include).toContain("matrix/**/*.test.ts");
|
||||
expect(testConfig.dir).toBe(path.join(process.cwd(), "extensions"));
|
||||
expect(testConfig.include).toContain("matrix/**/*.test.ts");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createScopedVitestConfig", () => {
|
||||
it("applies the non-isolated runner by default", () => {
|
||||
const config = createScopedVitestConfig(["src/example.test.ts"], { env: {} });
|
||||
expect(config.test?.isolate).toBe(false);
|
||||
expect(normalizeConfigPath(config.test?.runner)).toBe("test/non-isolated-runner.ts");
|
||||
expect(normalizeConfigPaths(config.test?.setupFiles)).toEqual([
|
||||
const testConfig = requireTestConfig(config);
|
||||
expect(testConfig.isolate).toBe(false);
|
||||
expect(normalizeConfigPath(testConfig.runner)).toBe("test/non-isolated-runner.ts");
|
||||
expect(normalizeConfigPaths(testConfig.setupFiles)).toEqual([
|
||||
"test/setup.ts",
|
||||
"test/setup-openclaw-runtime.ts",
|
||||
]);
|
||||
@@ -143,8 +153,9 @@ describe("createScopedVitestConfig", () => {
|
||||
dir: "src",
|
||||
env: {},
|
||||
});
|
||||
expect(config.test?.dir).toBe(path.join(process.cwd(), "src"));
|
||||
expect(config.test?.include).toEqual(["example.test.ts"]);
|
||||
const testConfig = requireTestConfig(config);
|
||||
expect(testConfig.dir).toBe(path.join(process.cwd(), "src"));
|
||||
expect(testConfig.include).toEqual(["example.test.ts"]);
|
||||
});
|
||||
|
||||
it("keeps scoped cli directory filters aligned with repo-root include patterns", () => {
|
||||
@@ -155,7 +166,7 @@ describe("createScopedVitestConfig", () => {
|
||||
passWithNoTests: true,
|
||||
});
|
||||
|
||||
expect(config.test?.include).toEqual(["slack/**/*.test.*"]);
|
||||
expect(requireTestConfig(config).include).toEqual(["slack/**/*.test.*"]);
|
||||
});
|
||||
|
||||
it("keeps broad scoped cli directory filters aligned with repo-root include patterns", () => {
|
||||
@@ -166,7 +177,7 @@ describe("createScopedVitestConfig", () => {
|
||||
passWithNoTests: true,
|
||||
});
|
||||
|
||||
expect(config.test?.include).toEqual(["speech-core/**/*.test.*"]);
|
||||
expect(requireTestConfig(config).include).toEqual(["speech-core/**/*.test.*"]);
|
||||
});
|
||||
|
||||
it("relativizes scoped include and exclude patterns to the configured dir", () => {
|
||||
@@ -175,9 +186,10 @@ describe("createScopedVitestConfig", () => {
|
||||
env: {},
|
||||
exclude: [EXTENSIONS_CHANNEL_GLOB, "dist/**"],
|
||||
});
|
||||
const testConfig = requireTestConfig(config);
|
||||
|
||||
expect(config.test?.include).toEqual(["**/*.test.ts"]);
|
||||
expect(config.test?.exclude).toEqual(expect.arrayContaining(["channel/**", "dist/**"]));
|
||||
expect(testConfig.include).toEqual(["**/*.test.ts"]);
|
||||
expect(testConfig.exclude).toEqual(expect.arrayContaining(["channel/**", "dist/**"]));
|
||||
});
|
||||
|
||||
it("narrows scoped includes to matching CLI file filters", () => {
|
||||
@@ -186,9 +198,10 @@ describe("createScopedVitestConfig", () => {
|
||||
dir: "extensions",
|
||||
env: {},
|
||||
});
|
||||
const testConfig = requireTestConfig(config);
|
||||
|
||||
expect(config.test?.include).toEqual(["browser/index.test.ts"]);
|
||||
expect(config.test?.passWithNoTests).toBe(true);
|
||||
expect(testConfig.include).toEqual(["browser/index.test.ts"]);
|
||||
expect(testConfig.passWithNoTests).toBe(true);
|
||||
});
|
||||
|
||||
it("loads scoped include overrides from OPENCLAW_VITEST_INCLUDE_FILE", () => {
|
||||
@@ -204,7 +217,7 @@ describe("createScopedVitestConfig", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(config.test?.include).toEqual(["utils/utils-misc.test.ts"]);
|
||||
expect(requireTestConfig(config).include).toEqual(["utils/utils-misc.test.ts"]);
|
||||
} finally {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
@@ -216,7 +229,7 @@ describe("createScopedVitestConfig", () => {
|
||||
setupFiles: ["test/setup.extensions.ts"],
|
||||
});
|
||||
|
||||
expect(normalizeConfigPaths(config.test?.setupFiles)).toEqual([
|
||||
expect(normalizeConfigPaths(requireTestConfig(config).setupFiles)).toEqual([
|
||||
"test/setup.ts",
|
||||
"test/setup.extensions.ts",
|
||||
"test/setup-openclaw-runtime.ts",
|
||||
@@ -224,7 +237,7 @@ describe("createScopedVitestConfig", () => {
|
||||
});
|
||||
|
||||
it("keeps bundled unit test includes out of the bundled exclude list", () => {
|
||||
const excludePatterns = bundledVitestConfig.test?.exclude ?? [];
|
||||
const excludePatterns = requireTestConfig(bundledVitestConfig).exclude ?? [];
|
||||
for (const file of bundledPluginDependentUnitTestFiles) {
|
||||
expect(
|
||||
excludePatterns.some((pattern) => bundledExcludePatternCouldMatchFile(pattern, file)),
|
||||
|
||||
Reference in New Issue
Block a user