fix(run): preserve pnpm test selection arguments (#2092)

Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-08 16:14:54 +08:00
1 джерело 11911a12c6
коміт 86ed4d6c59
6 files changed
+53 -12

No files matched your search

+19 -3
Переглянути файл
@@ -86,15 +86,23 @@ describe("rerunFailedConfig", () => {
expect(c.args).toEqual(["test", "--", "--nocapture", "old", "a", "--exact"]);
});
it("jest/vitest via npm: files + -t pattern", () => {
const c = rerunFailedConfig(cfg("npm", "pnpm", ["run", "test"]), [
it.each([
["npm", ["--"]],
["pnpm", []],
["/opt/bin/pnpm", []],
["C:\\tools\\pnpm.CMD", []],
["yarn", ["--"]],
["bun", ["--"]],
["npx", []],
])("jest/vitest via %s: files + -t pattern", (command, separator) => {
const c = rerunFailedConfig(cfg("npm", command, ["run", "test"]), [
["src/a.test.ts", "math", "adds (1+1)"],
["src/b.test.ts"],
])!;
expect(c.args).toEqual([
"run",
"test",
"--",
...separator,
"src/a.test.ts",
"src/b.test.ts",
"-t",
@@ -102,6 +110,14 @@ describe("rerunFailedConfig", () => {
]);
});
it.each([
["run", "test", "-t", "old"],
["run", "test", "--", "--testNamePattern=old"],
])("replaces an existing pnpm test filter in %j", (...args) => {
const c = rerunFailedConfig(cfg("npm", "pnpm", args), [["src/a.test.ts", "new"]])!;
expect(c.args).toEqual(["run", "test", ...(args.includes("--") ? ["--"] : []), "src/a.test.ts", "-t", "^(?:new)$"]);
});
it("pytest: node ids replace explicit paths", () => {
const c = rerunFailedConfig(cfg("pytest", ".venv/bin/pytest", ["-q", "tests/", "-k", "slow"]), [
["tests/test_x.py", "TestC", "test_y[1]"],
+4 -4
Переглянути файл
@@ -5,6 +5,7 @@
import { phpunitArgs, phpunitFilter } from "./phpunit";
import type { RunConfig } from "@/platform/ipc";
import { formatArgs } from "../configs";
import { appendScriptArgs } from "../scriptArgs";
import { djangoTestsOf } from "../djangoTypes";
import { goTestParts, withoutGoSelection } from "../goArguments";
import { frameworkFor } from "./index";
@@ -71,11 +72,10 @@ function jsArgs(config: RunConfig, paths: string[][]): string[] | null {
const names = unique(paths.filter((p) => p.length > 1).map((p) => p.slice(1).join(" ")));
if (!files.length) return null;
const { before, after } = splitDashDash(base);
const rest = dropFlag(after ?? [], ["-t", "--testNamePattern"]);
const flags = ["-t", "--testNamePattern"];
const args = after === null ? dropFlag(before, flags) : [...before, "--", ...dropFlag(after, flags)];
const filter = names.length ? ["-t", `^(?:${names.map(escapeRegExp).join("|")})$`] : [];
// npm/pnpm/yarn/bun pass everything after `--` to the script; deno/npx take them directly.
const needsDashDash = after !== null || /(^|\/)(npm|pnpm|yarn|bun)$/.test(config.command);
return needsDashDash ? [...before, "--", ...rest, ...files, ...filter] : [...before, ...files, ...filter];
return appendScriptArgs(config.command, args, [...files, ...filter]);
}
function pytestArgs(base: string[], paths: string[][]): string[] | null {