fix(run): clear a selected test's output with Clear All (#6982)

A selected test node shows the output captured on that node, which Clear All did not touch. Clear All now drops captured test output as well; statuses and the tree stay.

Closes #6975

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-30 17:42:00 +08:00
1 джерело 8301326289
коміт acc48a4816
3 files changed
+90 -2

No files matched your search

+79
Переглянути файл
@@ -0,0 +1,79 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import type { RunConfig } from "@/platform/ipc";
const ipc = vi.hoisted(() => ({
runStart: vi.fn(async (_config: RunConfig) => ({ status: "ok", data: 1 })),
runStop: vi.fn(async () => ({ status: "ok", data: null })),
}));
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
return { ...real, isTauri: () => true, commands: { ...real.commands, ...ipc } };
});
vi.mock("@tauri-apps/api/core", async (importOriginal) => ({
...(await importOriginal<typeof import("@tauri-apps/api/core")>()),
Channel: class {
onmessage: ((m: unknown) => void) | null = null;
},
}));
import { provideToolWindowService, type ToolWindowService } from "@/workbench/contributions";
import { nodeDuration, nodeOutput, nodeStatus } from "./testing";
import { clearConsole, resetRuns, runtime, startRun } from "./store";
const SEP = "\u0000";
const config: RunConfig = {
id: "junit:CartTest",
name: "CartTest",
kind: "shell",
command: "true",
args: [],
cwd: null,
env: {},
detected: false,
isTest: true,
debugAdapter: null,
};
const cls = ["CartTest"];
const total = ["CartTest", "total"];
beforeEach(() => provideToolWindowService({ show: vi.fn(), hide: vi.fn() } as unknown as ToolWindowService));
afterEach(() => resetRuns());
async function testRun() {
const session = (await startRun(config, undefined, undefined, { prepared: true }))!;
const rt = runtime(session.id)!;
rt.console.append({ kind: "stdout", text: "before all\nprinted by total\n" });
rt.tests!.apply([
{ type: "output", path: cls, line: "before all" },
{ type: "output", path: total, line: "printed by total" },
{ type: "result", path: total, status: "failed", durationMs: 12 },
]);
return { id: session.id, rt, tests: rt.tests! };
}
it("Clear All empties the full console and every test node's output, keeping the results (#6975)", async () => {
const { id, rt, tests } = await testRun();
const leaf = tests.get(total.join(SEP))!;
const group = tests.get(cls.join(SEP))!;
expect(nodeOutput(group)).toEqual(["before all", "printed by total"]);
clearConsole(id);
expect(rt.console.text()).toBe("");
expect(nodeOutput(leaf)).toEqual([]);
expect(nodeOutput(group)).toEqual([]);
expect(nodeStatus(leaf)).toBe("failed");
expect(nodeDuration(group)).toBe(12);
expect(tests.roots.map((r) => r.children.map((c) => c.name))).toEqual([["total"]]);
});
it("output printed after Clear All shows in the console and on its test", async () => {
const { id, rt, tests } = await testRun();
clearConsole(id);
rt.console.append({ kind: "stdout", text: "after clear\n" });
tests.apply([{ type: "output", path: total, line: "after clear" }]);
expect(rt.console.text()).toBe("after clear");
expect(nodeOutput(tests.get(total.join(SEP))!)).toEqual(["after clear"]);
expect(nodeOutput(tests.get(cls.join(SEP))!)).toEqual(["after clear"]);
});
+5 -2
Переглянути файл
@@ -1940,8 +1940,11 @@ export async function closeStdin(sessionId: string): Promise<void> {
}
export function clearConsole(sessionId: string) {
runtimes.get(sessionId)?.console.clear();
runtimes.get(sessionId)?.terminal?.clear();
const rt = runtimes.get(sessionId);
rt?.console.clear();
rt?.terminal?.clear();
// A selected test shows its own captured output, so that goes too (as in IDEA).
rt?.tests?.clearOutput();
bump(sessionId);
}
+6
Переглянути файл
@@ -101,6 +101,12 @@ export class TestResults {
this.version++;
}
/** Console Clear All: drops every node's captured output; statuses, durations and the tree stay. */
clearOutput() {
for (const n of this.byId.values()) n.output = [];
this.version++;
}
/** Finds a test by a suffix of its path (pytest failure headers name `Class.test`). */
findBySuffix(suffix: string[]): TestNode | undefined {
let best: TestNode | undefined;