merge: PR #35을 합친 검사 브랜치에 넣는다
This commit is contained in:
@@ -16,6 +16,15 @@ import { reachablePackageScripts } from "./package-script-graph.ts";
|
||||
export const UNGATED_TESTS_PATH = "config/ci/ungated-tests.json";
|
||||
|
||||
const TEST_FILE = /\.(?:test|spec)\.tsx?$/u;
|
||||
// vitest.config.ts includes only the `*.test.ts` and `*.test.tsx` files below tests.
|
||||
const VITEST_TEST_FILE = /\.test\.tsx?$/u;
|
||||
|
||||
/**
|
||||
* 0929/12-06. A gated path and the runner that reaches it. A Vitest path
|
||||
* runs its `*.test.*` files only; a Playwright `testDir` runs what the
|
||||
* Playwright default `testMatch` takes, `*.spec.*` and `*.test.*`.
|
||||
*/
|
||||
export type GatedTestTarget = Readonly<{ path: string; runner: "vitest" | "playwright" }>;
|
||||
|
||||
const ungatedTestsSchema = z
|
||||
.object({
|
||||
@@ -54,14 +63,26 @@ export function gatedTestPaths(
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): string[] {
|
||||
const paths = new Set<string>();
|
||||
return [...new Set(gatedTestTargets(scripts, entryScripts, readConfig).map(({ path: target }) => target))].sort();
|
||||
}
|
||||
|
||||
export function gatedTestTargets(
|
||||
scripts: Readonly<Record<string, string>>,
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): GatedTestTarget[] {
|
||||
const targets = new Map<string, GatedTestTarget>();
|
||||
const add = (target: string, runner: GatedTestTarget["runner"]) => {
|
||||
const normalized = target.replace(/\/$/u, "");
|
||||
targets.set(`${runner} ${normalized}`, { path: normalized, runner });
|
||||
};
|
||||
const addVitestPaths = (tokens: readonly string[]) => {
|
||||
const vitestRun = tokens.findIndex(
|
||||
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
|
||||
);
|
||||
if (vitestRun < 0) return;
|
||||
for (const token of tokens.slice(vitestRun + 1)) {
|
||||
if (!token.startsWith("-")) paths.add(token.replace(/\/$/u, ""));
|
||||
if (!token.startsWith("-")) add(token, "vitest");
|
||||
}
|
||||
};
|
||||
for (const script of reachablePackageScripts(scripts, entryScripts)) {
|
||||
@@ -79,20 +100,30 @@ export function gatedTestPaths(
|
||||
const configFlag = tokens.indexOf("--config");
|
||||
const config = configFlag >= 0 ? tokens[configFlag + 1]! : "playwright.config.ts";
|
||||
const testDir = /testDir:\s*["']\.?\/?([^"']+)["']/u.exec(readConfig(config))?.[1];
|
||||
if (testDir) paths.add(testDir.replace(/\/$/u, ""));
|
||||
if (testDir) add(testDir, "playwright");
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...paths].sort();
|
||||
return [...targets.values()].sort(
|
||||
(left, right) => left.path.localeCompare(right.path) || left.runner.localeCompare(right.runner),
|
||||
);
|
||||
}
|
||||
|
||||
export function ungatedTestFailures(input: Readonly<{
|
||||
testFiles: readonly string[];
|
||||
gatedPaths: readonly string[];
|
||||
/** A bare string is a Vitest path. */
|
||||
gatedPaths: readonly (string | GatedTestTarget)[];
|
||||
exclusions: readonly UngatedTestExclusion[];
|
||||
}>): string[] {
|
||||
const targets = input.gatedPaths.map((target): GatedTestTarget =>
|
||||
typeof target === "string" ? { path: target, runner: "vitest" } : target,
|
||||
);
|
||||
const gated = (file: string) =>
|
||||
input.gatedPaths.some((gatedPath) => file === gatedPath || file.startsWith(`${gatedPath}/`));
|
||||
targets.some(
|
||||
({ path: gatedPath, runner }) =>
|
||||
(file === gatedPath || file.startsWith(`${gatedPath}/`)) &&
|
||||
(runner === "playwright" || VITEST_TEST_FILE.test(file)),
|
||||
);
|
||||
const excluded = new Set(input.exclusions.map(({ path: file }) => file));
|
||||
const failures = input.testFiles
|
||||
.filter((file) => !gated(file) && !excluded.has(file))
|
||||
|
||||
Reference in New Issue
Block a user