Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai f514d165f7 Merge remote-tracking branch 'origin/main' into fix/test-results-layout 2026-11-20 04:06:50 +08:00
l0ng-ai 898c1119b3 fix(run): keep test results readable in narrow panes 2026-11-20 02:10:27 +08:00
5 змінених файлів з 239 додано та 57 видалено

No files matched your search

+76 -3
Переглянути файл
@@ -3,15 +3,21 @@
* the process. Processes are stubbed at the IPC layer; `crates/ide-run` covers spawning them.
*/
import type { Page } from "@playwright/test";
import type { RunConfig } from "../src/bindings";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
const RUN_ID = 7;
/** One saved `npm run dev` configuration; `run_start` prints `output` and exits with `exit` unless null. */
async function stubRun(page: Page, output: { kind: string; text: string }[], exit: number | null) {
async function stubRun(
page: Page,
output: { kind: string; text: string }[],
exit: number | null,
overrides: Partial<RunConfig> = {},
) {
await stubDesktop(page);
await page.evaluate(
async ({ output, exit, runId }) => {
async ({ output, exit, runId, overrides }) => {
const config = {
id: "npm:dev",
name: "dev",
@@ -23,6 +29,7 @@ async function stubRun(page: Page, output: { kind: string; text: string }[], exi
detected: false,
isTest: false,
debugAdapter: null,
...overrides,
};
const h = window.__ipc.handlers;
h.run_configs = () => [config];
@@ -43,7 +50,7 @@ async function stubRun(page: Page, output: { kind: string; text: string }[], exi
await loadConfigs();
selectConfig(config.id);
},
{ output, exit, runId: RUN_ID },
{ output, exit, runId: RUN_ID, overrides },
);
}
@@ -177,6 +184,72 @@ test("Go reruns keep each package's exact failures and the original configuratio
]);
});
test("test results keep counts, actions and selected output visible as the pane narrows", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1060, height: 740 });
const goPackage = "example.com/checkout";
const name = "TestCheckoutTotalsWithDiscountsAndPendingInventoryReservations";
const message = "expected subtotal 42, got 37";
const records = [
{ Action: "run", Test: name },
{ Action: "output", Test: name, Output: message + "\n" },
{ Action: "fail", Test: name, Elapsed: 0.125 },
{ Action: "pass", Test: "TestPayment", Elapsed: 0.02 },
{ Action: "skip", Test: "TestDelayedShipping" },
{ Action: "fail", Elapsed: 0.17 },
];
await stubRun(
page,
records.map((record) => ({ kind: "stdout", text: JSON.stringify({ Package: goPackage, ...record }) + "\n" })),
1,
{
id: "go:checkout-tests",
name: "Checkout tests",
kind: "go",
command: "go",
args: ["test", "-json"],
isTest: true,
},
);
await page.keyboard.press("Control+r");
const run = page.getByRole("region", { name: "Run", exact: true });
const tree = run.getByRole("tree", { name: "Test results" });
const row = tree.getByRole("treeitem", { name: new RegExp(name) });
await row.click();
const output = run.getByRole("log");
await expect(output).toContainText(message);
await expect.poll(async () => (await output.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true);
await page.setViewportSize({ width: 540, height: 740 });
await expect
.poll(async () => {
const [list, console] = await Promise.all([tree.boundingBox(), output.boundingBox()]);
return !!list && !!console && console.y >= list.y + list.height - 1;
})
.toBe(true);
const summary = run.getByRole("status").filter({ hasText: "1 failing" });
for (const count of ["1 failing", "1 passed", "1 ignored"]) await expect(summary.getByText(count)).toBeVisible();
await expect(row).toHaveAttribute("aria-selected", "true");
await expect(row.getByText("125 ms")).toBeVisible();
await expect(output).toContainText(message);
const toolbar = run.getByRole("toolbar", { name: "Test results" });
await toolbar.getByRole("button", { name: "More Actions" }).click();
await expect(page.getByRole("menuitem", { name: "Collapse All" })).toBeVisible();
await expect(page.getByRole("menuitem", { name: "Export Test Results…" })).toBeVisible();
await page.keyboard.press("Escape");
const divider = run.getByRole("separator");
const treeHeight = async () => (await tree.boundingBox())!.height;
const beforeResize = await treeHeight();
await divider.press("ArrowDown");
await expect.poll(treeHeight).toBeGreaterThan(beforeResize + 1);
const customizedHeight = await treeHeight();
await page.setViewportSize({ width: 1060, height: 740 });
await expect.poll(async () => (await output.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true);
await page.setViewportSize({ width: 540, height: 740 });
await expect.poll(async () => Math.abs((await treeHeight()) - customizedHeight)).toBeLessThan(2);
await expect(output).toContainText(message);
});
test("CMake builds the selected target in Build before starting only the application in Run", async ({
workbench: page,
}) => {
+29 -8
Переглянути файл
@@ -253,26 +253,44 @@
flex-direction: column;
height: 100%;
min-width: 0;
border-right: 1px solid var(--border);
}
.testHeader {
.testToolbar,
.testStatusBar {
flex: none;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
height: 28px;
padding: 0 4px 0 10px;
min-height: 28px;
border-bottom: 1px solid var(--border);
}
.testToolbar {
gap: var(--space-0-5);
padding: var(--space-0-5) var(--space-1);
}
.testStatusBar {
gap: var(--space-0-5) var(--space-2);
padding: var(--space-0-5) var(--space-2);
font-size: var(--fs-ui);
color: var(--fg-secondary);
}
.testCounts {
flex: 1 1 auto;
display: flex;
gap: 10px;
flex-wrap: wrap;
gap: var(--space-0-5) var(--space-2);
min-width: 0;
overflow: hidden;
white-space: nowrap;
}
.testStatus,
.testTotalDuration {
flex: none;
}
.testTotalDuration {
margin-left: auto;
color: var(--fg-subtle);
font-size: var(--fs-small);
font-variant-numeric: tabular-nums;
}
.testTree {
flex: 1;
min-height: 0;
@@ -299,8 +317,11 @@
flex: none;
padding-right: 8px;
color: var(--fg-subtle);
font-family: var(--font-mono);
font-size: var(--fs-small);
font-variant-numeric: tabular-nums;
}
.testTree [aria-selected="true"] .testDuration {
color: var(--fg);
}
.testEmpty {
padding: 12px;
+41 -6
Переглянути файл
@@ -1,5 +1,6 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import clsx from "clsx";
import type { GroupImperativeHandle, Layout } from "react-resizable-panels";
import type { RunConfig } from "@/platform/ipc";
import type { RunTargetValid } from "@/platform/remoteSettings";
import { useAgentRunSettings, useWorkflowSettings } from "@/platform/workflowSettings";
@@ -47,7 +48,7 @@ import {
} from "./store";
import { rerunFailedConfigs } from "./testing/rerun";
import { formatDuration, nodeOutput } from "./testing";
import { TestTreeView } from "./TestTreeView";
import { TestStatusBar, TestTreeView } from "./TestTreeView";
import { StackTracePanel, useStackTraces, type StackTraceTab } from "./stackTrace";
import { closeRunTab, runTabMenu } from "./runTabs";
import { showApplicationUpdate, useApplicationUpdates } from "./applicationUpdate";
@@ -59,6 +60,11 @@ import { archivedAgentSessions, closeAgentArchive } from "./agentRuns";
import styles from "./Run.module.css";
import { tx } from "@/platform/i18n";
const TEST_SPLIT_DEFAULTS = {
horizontal: { tests: 34, console: 66 },
vertical: { tests: 48, console: 52 },
};
function failed(s: RunSession): boolean {
return s.status === "failed" || (s.status === "finished" && s.exitCode !== 0 && !s.stopped);
}
@@ -93,6 +99,25 @@ export function SessionPanel({
const softWrap = wrapOverride ?? defaultWrap;
const [selectedTest, setSelectedTest] = useState<string | null>(null);
const [findOpen, setFindOpen] = useState(false);
const body = useRef<HTMLDivElement>(null);
const [stackedTests, setStackedTests] = useState(false);
const testSplit = useRef<GroupImperativeHandle>(null);
const testLayouts = useRef<Record<keyof typeof TEST_SPLIT_DEFAULTS, Layout>>({ ...TEST_SPLIT_DEFAULTS });
const testOrientation = stackedTests ? "vertical" : "horizontal";
const hasTests = !!rt?.tests;
useLayoutEffect(() => {
const pane = body.current;
if (!hasTests || !pane) return;
const measure = () => setStackedTests(pane.clientWidth < 560);
measure();
if (typeof ResizeObserver === "undefined") return;
const resize = new ResizeObserver(measure);
resize.observe(pane);
return () => resize.disconnect();
}, [hasTests]);
useLayoutEffect(() => {
if (hasTests) testSplit.current?.setLayout(testLayouts.current[testOrientation]);
}, [hasTests, testOrientation]);
const running = isLive(session);
const cwd = runDirectory(session.config.cwd);
const baseConfig = useRun(() => baseConfigOf(session));
@@ -136,6 +161,7 @@ export function SessionPanel({
const consoleColumn = (
<div className={styles.consoleColumn}>
{rt.tests && <TestStatusBar results={rt.tests} version={version} running={running} />}
{rt.console.dropped > 0 && !testModel && (
<div className={styles.notice}>{tx`${rt.console.dropped.toLocaleString()} earlier lines were discarded`}</div>
)}
@@ -279,10 +305,19 @@ export function SessionPanel({
/>
</div>
</div>
<div className={styles.sessionBody}>
<div ref={body} className={styles.sessionBody}>
{rt.tests ? (
<SplitGroup orientation="horizontal" id={`run-tests-${session.id}`} className={styles.testSplit}>
<SplitPanel id="tests" defaultSize="32%" minSize="140px">
<SplitGroup
orientation={testOrientation}
id={`run-tests-${session.id}`}
className={styles.testSplit}
groupRef={testSplit}
defaultLayout={TEST_SPLIT_DEFAULTS[testOrientation]}
onLayoutChanged={(layout, meta) => {
if (meta.isUserInteraction) testLayouts.current[testOrientation] = meta.requestedLayout ?? layout;
}}
>
<SplitPanel id="tests" minSize={stackedTests ? "28%" : "140px"}>
<TestTreeView
results={rt.tests}
version={version}
@@ -296,7 +331,7 @@ export function SessionPanel({
/>
</SplitPanel>
<SplitHandle />
<SplitPanel id="console" minSize="200px">
<SplitPanel id="console" minSize={stackedTests ? "28%" : "200px"}>
{consoleColumn}
</SplitPanel>
</SplitGroup>
+18 -12
Переглянути файл
@@ -49,6 +49,12 @@ function Host(props: {
);
}
function moreItem(name: string) {
const trigger = screen.getByRole("button", { name: "More Actions" });
if (trigger.getAttribute("aria-expanded") !== "true") fireEvent.click(trigger);
return screen.getByRole("menuitem", { name });
}
describe("TestTreeView", () => {
beforeEach(() => localStorage.clear());
afterEach(() => vi.clearAllMocks());
@@ -264,17 +270,17 @@ describe("Expand All / Collapse All", () => {
expect(rows()).toContain("reuses()");
});
it("the buttons run the actions, and are unavailable without suites", () => {
it("the menu runs the actions, and they are unavailable without suites", () => {
const dispose = registerActions([
{ id: "run.expandAllTests", title: "Expand All", run: () => {} },
{ id: "run.collapseAllTests", title: "Collapse All", run: () => {} },
]);
onTestFinished(dispose);
const { unmount } = render(view(nested()));
fireEvent.click(screen.getByRole("button", { name: "Expand All" }));
expect(actions.executeAction).toHaveBeenCalledWith("run.expandAllTests", undefined);
fireEvent.click(screen.getByRole("button", { name: "Collapse All" }));
expect(actions.executeAction).toHaveBeenCalledWith("run.collapseAllTests", undefined);
fireEvent.click(moreItem("Expand All"));
expect(actions.executeAction).toHaveBeenCalledWith("run.expandAllTests");
fireEvent.click(moreItem("Collapse All"));
expect(actions.executeAction).toHaveBeenCalledWith("run.collapseAllTests");
unmount();
expect(testTree.expandAll).toBeNull();
@@ -282,8 +288,8 @@ describe("Expand All / Collapse All", () => {
flat.apply([{ type: "result", path: ["main_test"], status: "failed" }]);
flat.finish(1);
render(view(flat));
expect(screen.getByRole("button", { name: "Expand All" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Collapse All" })).toBeDisabled();
expect(moreItem("Expand All")).toHaveAttribute("aria-disabled", "true");
expect(moreItem("Collapse All")).toHaveAttribute("aria-disabled", "true");
});
});
@@ -306,9 +312,9 @@ describe("Export Test Results", () => {
/>
);
it("the button and the action open the dialog for the finished run", () => {
it("the menu and the action open the dialog for the finished run", () => {
const { unmount } = render(view(finished(), false));
fireEvent.click(screen.getByRole("button", { name: "Export Test Results…" }));
fireEvent.click(moreItem("Export Test Results…"));
expect(screen.getByRole("dialog", { name: "Export Test Results" })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
act(() => testTree.exportResults!());
@@ -322,13 +328,13 @@ describe("Export Test Results", () => {
it("is unavailable while the tests run and without results", () => {
const { rerender } = render(view(finished(), true));
expect(screen.getByRole("button", { name: "Export Test Results…" })).toBeDisabled();
expect(moreItem("Export Test Results…")).toHaveAttribute("aria-disabled", "true");
expect(testTree.exportResults).toBeNull();
rerender(view(new TestResults(), false));
expect(screen.getByRole("button", { name: "Export Test Results…" })).toBeDisabled();
expect(moreItem("Export Test Results…")).toHaveAttribute("aria-disabled", "true");
expect(testTree.exportResults).toBeNull();
rerender(view(finished(), false));
expect(screen.getByRole("button", { name: "Export Test Results…" })).toBeEnabled();
expect(moreItem("Export Test Results…")).not.toHaveAttribute("aria-disabled", "true");
expect(testTree.exportResults).not.toBeNull();
});
});
+75 -28
Переглянути файл
@@ -9,6 +9,7 @@ import {
showContextMenu,
useContextMenuStore,
Spinner,
Toolbar,
Tree,
type MenuItem,
type TreeHandle,
@@ -83,6 +84,41 @@ export function StatusIcon({ status }: { status: TestStatus | null }) {
}
}
export function TestStatusBar({
results,
version,
running,
}: {
results: TestResults;
version: number;
running: boolean;
}) {
const counts = useMemo(() => results.counts(), [results, version]); // eslint-disable-line react-hooks/exhaustive-deps
const status = running
? "running"
: counts.failed
? "failed"
: counts.passed
? "passed"
: counts.skipped
? "skipped"
: null;
const duration = results.summary.durationMs;
return (
<div className={styles.testStatusBar} role="status">
<StatusIcon status={status} />
<span className={styles.testCounts}>
{counts.failed > 0 && <span className={styles.failed}>{tx`${counts.failed} failing`}</span>}
{counts.passed > 0 && <span>{tx`${counts.passed} passed`}</span>}
{counts.skipped > 0 && <span className={styles.skipped}>{tx`${counts.skipped} ignored`}</span>}
{counts.total === 0 && <span className={styles.skipped}>{running ? tx("Running…") : tx("No tests")}</span>}
</span>
{duration !== undefined && <span className={styles.testTotalDuration}>{formatDuration(duration)}</span>}
</div>
);
}
const isFailedTest = (n: TestNode) => n.children.length === 0 && nodeStatus(n) === "failed";
const treeModel = {
@@ -163,6 +199,8 @@ export function TestTreeView({
});
const sortButton = useRef<HTMLButtonElement>(null);
const [sortMenu, setSortMenu] = useState(false);
const moreButton = useRef<HTMLButtonElement>(null);
const [moreMenu, setMoreMenu] = useState(false);
const [expanded, setExpanded] = useState<Set<string> | null>(null);
const [exporting, setExporting] = useState(false);
const [selection, setSelection] = useState<Set<string>>(new Set());
@@ -226,7 +264,6 @@ export function TestTreeView({
}
};
const counts = useMemo(() => results.counts(), [results, version]); // eslint-disable-line react-hooks/exhaustive-deps
// Like IDEA, Sort by Duration applies once the run has finished, so rows don't jump while tests report.
const byDuration = sortByDuration && !running;
const roots = useMemo(() => {
@@ -276,21 +313,9 @@ export function TestTreeView({
const hasPrevFailed = findOccurrence(roots, selected, -1, treeModel) !== null;
const hasNextFailed = findOccurrence(roots, selected, 1, treeModel) !== null;
const status = running ? "running" : counts.failed > 0 ? "failed" : counts.total > 0 ? "passed" : null;
const duration = results.summary.durationMs;
return (
<div className={styles.testPane}>
<div className={styles.testHeader}>
<StatusIcon status={status} />
<span className={styles.testCounts}>
{counts.failed > 0 && <span className={styles.failed}>{tx`${counts.failed} failing`}</span>}
{counts.passed > 0 && <span>{tx`${counts.passed} passed`}</span>}
{counts.skipped > 0 && <span className={styles.skipped}>{tx`${counts.skipped} ignored`}</span>}
{counts.total === 0 && <span className={styles.skipped}>{running ? tx("Running…") : tx("No tests")}</span>}
{duration !== undefined && <span className={styles.skipped}>{formatDuration(duration)}</span>}
</span>
<span className={styles.spacer} />
<Toolbar className={styles.testToolbar} aria-label="Test results">
<IconButton
icon="test-show-passed"
size="small"
@@ -332,14 +357,6 @@ export function TestTreeView({
]}
onClose={() => setSortMenu(false)}
/>
<IconButton icon="expand-all" action="run.expandAllTests" size="small" iconSize={16} disabled={!hasSuites} />
<IconButton
icon="collapse-all"
action="run.collapseAllTests"
size="small"
iconSize={16}
disabled={!hasSuites}
/>
<IconButton
icon="arrow-up"
action="navigate.prevOccurrence"
@@ -357,14 +374,42 @@ export function TestTreeView({
disabled={!hasNextFailed}
/>
<IconButton
icon="export"
ref={moreButton}
icon="more-horizontal"
size="small"
iconSize={16}
title="Export Test Results…"
disabled={!canExport}
onClick={() => setExporting(true)}
title="More Actions"
aria-haspopup="menu"
aria-expanded={moreMenu}
onClick={() => setMoreMenu((open) => !open)}
/>
</div>
<Menu
open={moreMenu}
anchor={moreButton}
onClose={() => setMoreMenu(false)}
items={[
{
icon: "expand-all",
label: "Expand All",
disabled: !hasSuites,
run: () => void executeAction("run.expandAllTests"),
},
{
icon: "collapse-all",
label: "Collapse All",
disabled: !hasSuites,
run: () => void executeAction("run.collapseAllTests"),
},
{ kind: "separator" },
{
icon: "export",
label: "Export Test Results…",
disabled: !canExport,
run: () => setExporting(true),
},
]}
/>
</Toolbar>
{exporting && (
<ExportTestResultsDialog results={results} name={name} cwd={cwd} onClose={() => setExporting(false)} />
)}
@@ -396,7 +441,9 @@ export function TestTreeView({
return (
<span className={styles.testRow}>
<StatusIcon status={s} />
<span className={clsx(styles.testName, s === "skipped" && styles.skipped)}>{n.name}</span>
<span className={clsx(styles.testName, s === "skipped" && styles.skipped)} title={n.name}>
{n.name}
</span>
{d !== undefined && <span className={styles.testDuration}>{formatDuration(d)}</span>}
</span>
);