дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
A Playwright project had no test tree and no Rerun Failed Tests: its output went through the Jest / Vitest parser, single tests ran with Jest's `-t`, and projects without a `test` script weren't detected at all. - Detection: a `package.json` script that runs `playwright test` is a test configuration and records `testRunner: "playwright"` (new optional `RunExtras.test_runner`, `test-runner` in `run.toml`); a package with a `playwright.config.*` that no script runs gets `npx playwright test`. - Test tree: test runs add `--reporter=list` unless a reporter is named, parsed into file › [project] › describe chain › test with status, duration, location and failure details. - Gutter: `test.describe` blocks and `fixme` / `fail` / `serial` tests get run / debug icons and run by declaration line (`file:line`); in a project with Playwright and another runner, specs run on Playwright's configuration and other tests on the other runner's. - Rerun Failed Tests / run selected tests: the files plus `--grep` on the describe chain and title, with `--project` when the run named projects. New fixture `fixtures/playwright-app`; `smoke/run.test.ts` runs it after `ts-app`. Co-authored-by: wildcatDownstairs <[email protected]>
198 рядки
7.2 KiB
TypeScript
198 рядки
7.2 KiB
TypeScript
/** Picks the test output parser for a run configuration. */
|
|
import type { RunConfig } from "@/platform/ipc";
|
|
import { cargoParser } from "./cargo";
|
|
import { goParser } from "./go";
|
|
import { jsParser } from "./js";
|
|
import { jvmParser } from "./jvm";
|
|
import { phpunitParser, withTeamcity } from "./phpunit";
|
|
import { playwrightParser } from "./playwright";
|
|
import { pytestParser } from "./pytest";
|
|
import { rubyParser } from "./ruby";
|
|
import { unittestParser } from "./unittest";
|
|
import { zigParser } from "./zig";
|
|
import type { TestEvent, TestOutputParser } from "./types";
|
|
import { appendScriptArgs } from "../scriptArgs";
|
|
|
|
export type { TestEvent, TestOutputParser, TestStatus } from "./types";
|
|
export { formatDuration, parseDuration } from "./types";
|
|
export { TestResults, nodeDuration, nodeOutput, nodeStatus, type TestNode } from "./results";
|
|
export {
|
|
cargoParser,
|
|
goParser,
|
|
jsParser,
|
|
jvmParser,
|
|
phpunitParser,
|
|
playwrightParser,
|
|
pytestParser,
|
|
rubyParser,
|
|
unittestParser,
|
|
zigParser,
|
|
};
|
|
|
|
/** Runs several parsers side by side (unknown tool: e.g. `make test`). */
|
|
export function combinedParser(parsers: TestOutputParser[]): TestOutputParser {
|
|
return {
|
|
feed: (line) => parsers.flatMap((p) => p.feed(line)),
|
|
end: () => parsers.flatMap((p) => p.end?.() ?? []),
|
|
};
|
|
}
|
|
|
|
export type Framework =
|
|
| "cargo"
|
|
| "js"
|
|
| "playwright"
|
|
| "pytest"
|
|
| "unittest"
|
|
| "phpunit"
|
|
| "go"
|
|
| "jvm"
|
|
| "ruby"
|
|
| "dotnet"
|
|
| "zig"
|
|
| "auto";
|
|
|
|
type FrameworkConfig = Pick<RunConfig, "kind" | "command" | "args"> & Partial<Pick<RunConfig, "testRunner">>;
|
|
|
|
export function frameworkFor(config: FrameworkConfig): Framework {
|
|
const cmd = [config.command, ...config.args].join(" ");
|
|
// A `package.json` script names its runner only in package.json: detection records it.
|
|
if (config.testRunner === "playwright" || /\bplaywright\s+test\b/.test(cmd)) return "playwright";
|
|
switch (config.kind) {
|
|
case "dotnet-test":
|
|
return "dotnet";
|
|
case "cargo":
|
|
return "cargo";
|
|
case "npm":
|
|
case "deno":
|
|
case "bun":
|
|
return "js";
|
|
case "pytest":
|
|
return "pytest";
|
|
case "python":
|
|
// `manage.py test` made as a Python configuration before the Django tests type existed.
|
|
return /\bmanage\.py test\b/.test(cmd) ? "unittest" : "pytest";
|
|
case "django-test":
|
|
return "unittest";
|
|
case "phpunit":
|
|
return "phpunit";
|
|
case "go":
|
|
return "go";
|
|
case "gradle":
|
|
case "maven":
|
|
return "jvm";
|
|
case "ruby":
|
|
case "rake":
|
|
case "rspec":
|
|
return "ruby";
|
|
case "zig":
|
|
return "zig";
|
|
}
|
|
if (/(^|[/\\])dotnet(?:\.exe)?$/i.test(config.command) && config.args[0] === "test") return "dotnet";
|
|
if (/\bcargo\b/.test(cmd)) return "cargo";
|
|
if (/\b(jest|vitest|npm|pnpm|yarn|bun|npx|deno)\b/.test(cmd)) return "js";
|
|
if (/\bpytest\b/.test(cmd)) return "pytest";
|
|
if (/\bmanage\.py test\b/.test(cmd)) return "unittest";
|
|
if (/(^|[/\\\s])(phpunit|pest)(\.phar|\.bat)?(\s|$)/.test(cmd)) return "phpunit";
|
|
if (/\bgo\s+test\b/.test(cmd)) return "go";
|
|
if (/\b(gradlew?|mvnw?)\b/.test(cmd)) return "jvm";
|
|
return "auto";
|
|
}
|
|
|
|
/** `TESTOPTS=-v` / a trailing `-v`: Minitest prints a line per test only when verbose. */
|
|
function rubyVerbose<T extends Pick<RunConfig, "kind" | "command" | "args">>(config: T): T {
|
|
if (config.kind === "rspec") return config;
|
|
if (config.kind === "rake") {
|
|
const at = config.args.findIndex((a) => a.startsWith("TESTOPTS="));
|
|
if (at < 0) return { ...config, args: [...config.args, "TESTOPTS=-v"] };
|
|
// Options already given (`--name=Class#test_x`): add ours unless verbosity was chosen.
|
|
return /(^|\s)(-v|--verbose)(\s|$)/.test(config.args[at]!)
|
|
? config
|
|
: { ...config, args: config.args.map((a, i) => (i === at ? `${a} -v` : a)) };
|
|
}
|
|
const chosen = config.args.some((a) => a === "-v" || a === "--verbose");
|
|
return chosen ? config : { ...config, args: [...config.args, "-v"] };
|
|
}
|
|
|
|
/**
|
|
* Launch arguments that make a test run reportable per test: pytest and
|
|
* Django print only progress dots by default, so passed tests would never
|
|
* reach the tree. `-v` (Django: `-v 2`) adds one line per test (live, like
|
|
* IDEA's runner) unless the user chose a verbosity already.
|
|
*/
|
|
export function withTestReporting<T extends FrameworkConfig>(config: T): T {
|
|
if (frameworkFor(config) === "playwright") {
|
|
// The list reporter prints a line per test; a project's own (`html`, `dot` on CI) may print none.
|
|
const chosen = config.args.some((a) => a === "--reporter" || a.startsWith("--reporter="));
|
|
return chosen ? config : { ...config, args: appendScriptArgs(config.command, config.args, ["--reporter=list"]) };
|
|
}
|
|
if (frameworkFor(config) === "go" && config.args[0] === "test") {
|
|
const boundary = config.args.findIndex((a) => a === "-args" || a === "--");
|
|
const tool = boundary < 0 ? config.args : config.args.slice(0, boundary);
|
|
const args = tool.filter((a) => a !== "-json" && !a.startsWith("-json="));
|
|
return {
|
|
...config,
|
|
args: ["test", "-json", ...args.slice(1), ...(boundary < 0 ? [] : config.args.slice(boundary))],
|
|
};
|
|
}
|
|
if (frameworkFor(config) === "phpunit") return { ...config, args: withTeamcity(config.args) };
|
|
if (frameworkFor(config) === "zig" && config.args[0] === "build") {
|
|
// `zig build test` prints nothing for a passing (or cached) run; the summary reports the counts.
|
|
return config.args.includes("--summary") ? config : { ...config, args: [...config.args, "--summary", "all"] };
|
|
}
|
|
if (frameworkFor(config) === "unittest") {
|
|
const chosen = config.args.some((a) => /^(-v|--verbosity)(=?\d)?$/.test(a));
|
|
return chosen ? config : { ...config, args: [...config.args, "-v", "2"] };
|
|
}
|
|
if (frameworkFor(config) === "ruby") return rubyVerbose(config);
|
|
if (frameworkFor(config) !== "pytest") return config;
|
|
const cmd = [config.command, ...config.args];
|
|
const pytestAt = cmd.findIndex((a) => /(^|[/\\])pytest(\.exe)?$/.test(a));
|
|
if (pytestAt < 0) return config;
|
|
const chosen = cmd.slice(pytestAt + 1).some((a) => /^-[vq]+$|^--(verbose|quiet)$|^--verbosity/.test(a));
|
|
return chosen ? config : { ...config, args: [...config.args, "-v"] };
|
|
}
|
|
|
|
export function createTestParser(config: FrameworkConfig): TestOutputParser {
|
|
switch (frameworkFor(config)) {
|
|
case "dotnet":
|
|
return { feed: () => [] };
|
|
case "cargo":
|
|
return cargoParser();
|
|
case "js":
|
|
return jsParser();
|
|
case "playwright":
|
|
return playwrightParser();
|
|
case "pytest":
|
|
return pytestParser();
|
|
case "unittest":
|
|
return unittestParser();
|
|
case "phpunit":
|
|
return phpunitParser();
|
|
case "go":
|
|
return goParser();
|
|
case "jvm":
|
|
return jvmParser();
|
|
case "ruby":
|
|
return rubyParser();
|
|
case "zig":
|
|
return zigParser();
|
|
default:
|
|
return combinedParser([
|
|
cargoParser(),
|
|
jsParser(),
|
|
pytestParser(),
|
|
unittestParser(),
|
|
phpunitParser(),
|
|
goParser(),
|
|
jvmParser(),
|
|
rubyParser(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/** Convenience for tests and batch parsing. */
|
|
export function parseAll(parser: TestOutputParser, text: string): TestEvent[] {
|
|
const events = text.split("\n").flatMap((l) => parser.feed(l.replace(/\r$/, "")));
|
|
return [...events, ...(parser.end?.() ?? [])];
|
|
}
|