mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 15:34:46 +00:00
fix(test): defer unit coverage source discovery
This commit is contained in:
@@ -132,9 +132,21 @@ describe("unit vitest config", () => {
|
||||
expect(testConfig.exclude).toContain("src/security/**");
|
||||
});
|
||||
|
||||
it("scopes default coverage to source files owned by the unit lane", () => {
|
||||
it("skips default coverage source discovery when coverage is disabled", () => {
|
||||
const unitConfig = createUnitVitestConfig({});
|
||||
const testConfig = requireTestConfig(unitConfig);
|
||||
|
||||
expect(testConfig.coverage?.include).toBeUndefined();
|
||||
});
|
||||
|
||||
it("scopes default coverage to source files owned by the unit lane", () => {
|
||||
const unitConfig = createUnitVitestConfigWithOptions(
|
||||
{},
|
||||
{
|
||||
argv: ["node", "vitest", "run", "--coverage"],
|
||||
},
|
||||
);
|
||||
const testConfig = requireTestConfig(unitConfig);
|
||||
const coverageInclude = testConfig.coverage?.include;
|
||||
expect(coverageInclude).toContain("src/commitments/runtime.ts");
|
||||
expect(coverageInclude).toContain("src/media-generation/runtime-shared.ts");
|
||||
|
||||
@@ -84,6 +84,20 @@ export function resolveDefaultUnitCoverageIncludePatterns(
|
||||
return [...sourceFiles].toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function isEnabledFlagValue(value: string): boolean {
|
||||
return !["0", "false", "no", "off"].includes(value.trim().toLowerCase());
|
||||
}
|
||||
|
||||
function isCoverageEnabledFromArgv(argv: string[] = process.argv): boolean {
|
||||
return argv.some((arg) => {
|
||||
if (arg === "--coverage" || arg === "--coverage.enabled") {
|
||||
return true;
|
||||
}
|
||||
const match = arg.match(/^--coverage(?:\.enabled)?=(.*)$/u);
|
||||
return match ? isEnabledFlagValue(match[1] ?? "") : false;
|
||||
});
|
||||
}
|
||||
|
||||
export function createUnitVitestConfigWithOptions(
|
||||
env: Record<string, string | undefined> = process.env,
|
||||
options: {
|
||||
@@ -95,11 +109,13 @@ export function createUnitVitestConfigWithOptions(
|
||||
} = {},
|
||||
) {
|
||||
const isolate = resolveVitestIsolation(env);
|
||||
const argv = options.argv ?? process.argv;
|
||||
const unitFastTestFiles = getUnitFastTestFiles();
|
||||
const envIncludePatterns = loadIncludePatternsFromEnv(env);
|
||||
const defaultIncludePatterns = options.includePatterns ?? unitTestIncludePatterns;
|
||||
const cliIncludePatterns = narrowIncludePatternsForCli(defaultIncludePatterns, options.argv);
|
||||
const cliIncludePatterns = narrowIncludePatternsForCli(defaultIncludePatterns, argv);
|
||||
const coverageIncludePatterns =
|
||||
isCoverageEnabledFromArgv(argv) &&
|
||||
options.includePatterns === undefined &&
|
||||
envIncludePatterns === null &&
|
||||
cliIncludePatterns === null
|
||||
|
||||
Reference in New Issue
Block a user