forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathvitest.unit.config.ts
More file actions
64 lines (58 loc) · 2.24 KB
/
vitest.unit.config.ts
File metadata and controls
64 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 {
unitTestAdditionalExcludePatterns,
unitTestIncludePatterns,
} from "./vitest.unit-paths.mjs";
const sharedTest = sharedVitestConfig.test ?? {};
const exclude = sharedTest.exclude ?? [];
export function loadIncludePatternsFromEnv(
env: Record<string, string | undefined> = process.env,
): string[] | null {
return loadPatternListFromEnv("OPENCLAW_VITEST_INCLUDE_FILE", env);
}
export function loadExtraExcludePatternsFromEnv(
env: Record<string, string | undefined> = process.env,
): string[] {
return loadPatternListFromEnv("OPENCLAW_VITEST_EXTRA_EXCLUDE_FILE", env) ?? [];
}
export function createUnitVitestConfigWithOptions(
env: Record<string, string | undefined> = process.env,
options: {
includePatterns?: string[];
extraExcludePatterns?: string[];
name?: string;
argv?: string[];
} = {},
) {
const isolate = resolveVitestIsolation(env);
const defaultIncludePatterns = options.includePatterns ?? unitTestIncludePatterns;
const cliIncludePatterns = narrowIncludePatternsForCli(defaultIncludePatterns, options.argv);
return defineProject({
...sharedVitestConfig,
test: {
...sharedTest,
name: options.name ?? "unit",
isolate,
...(isolate ? { runner: undefined } : { runner: "./test/non-isolated-runner.ts" }),
setupFiles: [
...new Set([...(sharedTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"]),
],
include: loadIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? defaultIncludePatterns,
exclude: [
...new Set([
...exclude,
...(options.extraExcludePatterns ?? unitTestAdditionalExcludePatterns),
...loadExtraExcludePatternsFromEnv(env),
]),
],
...(cliIncludePatterns !== null ? { passWithNoTests: true } : {}),
},
});
}
export function createUnitVitestConfig(env: Record<string, string | undefined> = process.env) {
return createUnitVitestConfigWithOptions(env);
}
export default createUnitVitestConfigWithOptions();