дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
feat(run): Track Running Test in Test Runner Options (#6285)
Test Runner Options gets Track Running Test (also in Find Action as run.toggleTrackRunningTest), remembered with the other test tree options and on by default. While a run is in progress, each test that starts is selected, its collapsed suites opened and its output shown; when several start together the last in tree order wins. A test finishing doesn't move the selection, so a test picked by hand stays selected until the next one starts, and focus doesn't move. Co-authored-by: mansur-akhmadi <[email protected]>
Цей коміт міститься в:
1 джерело
a5e0c41663
коміт
57094bc285
9 files changed
+187
-1
No files matched your search
@@ -55,6 +55,7 @@ A test run opens a tab in the **Run** tool window with the test tree next to the
|
||||
- Double-click, `Enter` or `F4` jumps to the test's source (**Jump to Source**).
|
||||
- **Show Passed** and **Show Ignored** filter the tree. Passed tests are hidden by default; the filters are remembered.
|
||||
- **⋯ › Test Runner Options › Select First Failed Test When Finished** selects the first failed test, with its output, when a run ends. It is off by default.
|
||||
- **⋯ › Test Runner Options › Track Running Test** selects each test, with its output, as it starts while the run is in progress. It is on by default.
|
||||
- Right-click a test or a selection for **Run '…'**, **Debug '…'** and **Jump to Source**.
|
||||
- For an assertion failure with expected and actual values, **Show Diff** opens them side by side.
|
||||
- For a Jest or Vitest snapshot mismatch, **Update Snapshot** (on the test or its file or suite, above the failure output, and in the gutter run menu) reruns just those tests with `-u`, so only their snapshots are rewritten.
|
||||
|
||||
@@ -51,6 +51,7 @@ RSpec 有自己的配置类型(**RSpec 测试**)和检测到的 `rspec` 配
|
||||
- 双击、按 `Enter` 或 `F4` 跳到测试源码(**跳转到源代码**)。
|
||||
- **显示已通过** 和 **显示已忽略** 用于筛选测试树。默认隐藏已通过的测试,筛选状态会被记住。
|
||||
- **⋯ › 测试运行器选项 › 完成后选中第一个失败的测试** 会在运行结束时选中第一个失败的测试并显示它的输出。默认关闭。
|
||||
- **⋯ › 测试运行器选项 › 跟踪正在运行的测试** 会在运行过程中,每个测试开始时选中它并显示它的输出。默认开启。
|
||||
- 右键单个测试或多选后,可以 **运行 '…'**、**调试 '…'** 或 **跳转到源代码**。
|
||||
- 对于带有期望值和实际值的断言失败,**显示差异** 会把两者并排对比。
|
||||
- 对于 Jest 或 Vitest 的快照不匹配,**更新快照**(在测试或其文件、套件上,失败输出上方,以及边栏运行菜单中)只用 `-u` 重新运行这些测试,只改写它们的快照。
|
||||
|
||||
@@ -680,3 +680,125 @@ describe("Select First Failed Test When Finished", () => {
|
||||
expect(testTree.selectFirstFailed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Track Running Test", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
onSelect.mockClear();
|
||||
});
|
||||
afterEach(() => localStorage.clear());
|
||||
|
||||
const onSelect = vi.fn();
|
||||
function Host({ results, version, running }: { results: TestResults; version: number; running: boolean }) {
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
return (
|
||||
<TestTreeView
|
||||
results={results}
|
||||
version={version}
|
||||
cwd="/p"
|
||||
selected={selected}
|
||||
onSelect={(id) => {
|
||||
onSelect(id);
|
||||
setSelected(id);
|
||||
}}
|
||||
running={running}
|
||||
/>
|
||||
);
|
||||
}
|
||||
const selectedRows = () => screen.queryAllByRole("treeitem", { selected: true }).map((r) => r.textContent);
|
||||
const enable = (on = true) =>
|
||||
localStorage.setItem("openidea.run.testFilters", JSON.stringify({ showPassed: true, trackRunning: on }));
|
||||
|
||||
it("selects each test as it starts, opening its collapsed suites", () => {
|
||||
enable();
|
||||
const results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["ApiTest", "lists()"] }]);
|
||||
const { rerender } = render(<Host results={results} version={1} running />);
|
||||
expect(selectedRows()).toEqual(["lists()"]);
|
||||
expect(results.get(onSelect.mock.lastCall![0])!.name).toBe("lists()");
|
||||
|
||||
act(() => testTree.collapseAll!());
|
||||
results.apply([
|
||||
{ type: "result", path: ["ApiTest", "lists()"], status: "passed" },
|
||||
{ type: "start", path: ["ApiTest", "Auth", "Tokens", "refreshes()"] },
|
||||
]);
|
||||
rerender(<Host results={results} version={2} running />);
|
||||
expect(selectedRows()).toEqual(["refreshes()"]);
|
||||
});
|
||||
|
||||
it("selects the latest of several tests that start together and keeps the selection while they finish", () => {
|
||||
enable();
|
||||
const results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["pkg", "TestA"] }]);
|
||||
const { rerender } = render(<Host results={results} version={1} running />);
|
||||
results.apply([
|
||||
{ type: "start", path: ["pkg", "TestB"] },
|
||||
{ type: "start", path: ["pkg", "TestC"] },
|
||||
]);
|
||||
rerender(<Host results={results} version={2} running />);
|
||||
expect(selectedRows()).toEqual(["TestC"]);
|
||||
|
||||
// A test finishing, or one that was already running, doesn't move the selection.
|
||||
results.apply([{ type: "result", path: ["pkg", "TestC"], status: "passed" }]);
|
||||
rerender(<Host results={results} version={3} running />);
|
||||
expect(selectedRows()).toEqual(["TestC"]);
|
||||
fireEvent.mouseDown(screen.getByText("TestA"));
|
||||
results.apply([{ type: "result", path: ["pkg", "TestB"], status: "passed" }]);
|
||||
rerender(<Host results={results} version={4} running />);
|
||||
expect(selectedRows()).toEqual(["TestA"]);
|
||||
|
||||
// The next test to start takes the selection again.
|
||||
results.apply([{ type: "start", path: ["pkg", "TestD"] }]);
|
||||
rerender(<Host results={results} version={5} running />);
|
||||
expect(selectedRows()).toEqual(["TestD"]);
|
||||
});
|
||||
|
||||
it("switched on mid-run, waits for the next test to start", () => {
|
||||
enable(false);
|
||||
const results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["pkg", "TestA"] }]);
|
||||
const { rerender } = render(<Host results={results} version={1} running />);
|
||||
act(() => testTree.toggleTrackRunning!());
|
||||
rerender(<Host results={results} version={2} running />);
|
||||
expect(selectedRows()).toEqual([]);
|
||||
results.apply([{ type: "start", path: ["pkg", "TestB"] }]);
|
||||
rerender(<Host results={results} version={3} running />);
|
||||
expect(selectedRows()).toEqual(["TestB"]);
|
||||
});
|
||||
|
||||
it("is on by default, as in IDEA, and follows nothing once the run has finished", () => {
|
||||
let results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["ApiTest", "lists()"] }]);
|
||||
const { unmount } = render(<Host results={results} version={1} running />);
|
||||
expect(selectedRows()).toEqual(["lists()"]);
|
||||
unmount();
|
||||
onSelect.mockClear();
|
||||
|
||||
enable(false);
|
||||
results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["ApiTest", "lists()"] }]);
|
||||
const off = render(<Host results={results} version={1} running />);
|
||||
expect(selectedRows()).toEqual([]);
|
||||
off.unmount();
|
||||
|
||||
enable();
|
||||
results = new TestResults();
|
||||
results.apply([{ type: "start", path: ["ApiTest", "lists()"] }]);
|
||||
render(<Host results={results} version={1} running={false} />);
|
||||
expect(selectedRows()).toEqual([]);
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("the Test Runner Options toggle is remembered across sessions", () => {
|
||||
const results = new TestResults();
|
||||
const view = <Host results={results} version={1} running={false} />;
|
||||
const { unmount } = render(view);
|
||||
expect(testTree.trackRunning).toBe(true);
|
||||
act(() => testTree.toggleTrackRunning!());
|
||||
expect(testTree.trackRunning).toBe(false);
|
||||
unmount();
|
||||
expect(testTree.toggleTrackRunning).toBeNull();
|
||||
render(view);
|
||||
expect(testTree.trackRunning).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -41,6 +41,7 @@ interface TestFilters {
|
||||
showIgnored: boolean;
|
||||
showDurations: boolean;
|
||||
selectFirstFailed: boolean;
|
||||
trackRunning: boolean;
|
||||
sortAlphabetically: boolean;
|
||||
sortByDuration: boolean;
|
||||
}
|
||||
@@ -54,6 +55,7 @@ export function loadTestFilters(): TestFilters {
|
||||
showIgnored: v.showIgnored !== false,
|
||||
showDurations: v.showDurations !== false,
|
||||
selectFirstFailed: v.selectFirstFailed === true,
|
||||
trackRunning: v.trackRunning !== false,
|
||||
sortAlphabetically: v.sortAlphabetically === true && v.sortByDuration !== true,
|
||||
sortByDuration: v.sortByDuration === true,
|
||||
};
|
||||
@@ -63,6 +65,7 @@ export function loadTestFilters(): TestFilters {
|
||||
showIgnored: true,
|
||||
showDurations: true,
|
||||
selectFirstFailed: false,
|
||||
trackRunning: true,
|
||||
sortAlphabetically: false,
|
||||
sortByDuration: false,
|
||||
};
|
||||
@@ -155,6 +158,19 @@ function suiteIds(nodes: readonly TestNode[], out: Set<string> = new Set()): Set
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Tests still running, in tree order, with the suites above them. */
|
||||
function runningTests(
|
||||
nodes: readonly TestNode[],
|
||||
ancestors: TestNode[] = [],
|
||||
out: Array<{ node: TestNode; ancestors: TestNode[] }> = [],
|
||||
) {
|
||||
for (const n of nodes) {
|
||||
if (n.children.length > 0) runningTests(n.children, [...ancestors, n], out);
|
||||
else if (nodeStatus(n) === "running") out.push({ node: n, ancestors });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function filterTree(nodes: readonly TestNode[], keep: (n: TestNode) => boolean): TestNode[] {
|
||||
const out: TestNode[] = [];
|
||||
for (const n of nodes) {
|
||||
@@ -213,7 +229,15 @@ export function TestTreeView({
|
||||
rerunAutomatically,
|
||||
}: TestTreeViewProps) {
|
||||
const [filters, setFilters] = useState(loadTestFilters);
|
||||
const { showPassed, showIgnored, showDurations, selectFirstFailed, sortAlphabetically, sortByDuration } = filters;
|
||||
const {
|
||||
showPassed,
|
||||
showIgnored,
|
||||
showDurations,
|
||||
selectFirstFailed,
|
||||
trackRunning,
|
||||
sortAlphabetically,
|
||||
sortByDuration,
|
||||
} = filters;
|
||||
const toggle = (key: keyof TestFilters) =>
|
||||
setFilters((f) => {
|
||||
const next = { ...f, [key]: !f[key] };
|
||||
@@ -345,6 +369,8 @@ export function TestTreeView({
|
||||
testTree.toggleDurations = () => toggle("showDurations");
|
||||
testTree.selectFirstFailed = selectFirstFailed;
|
||||
testTree.toggleSelectFirstFailed = () => toggle("selectFirstFailed");
|
||||
testTree.trackRunning = trackRunning;
|
||||
testTree.toggleTrackRunning = () => toggle("trackRunning");
|
||||
return () => {
|
||||
testTree.expandAll = null;
|
||||
testTree.collapseAll = null;
|
||||
@@ -353,6 +379,8 @@ export function TestTreeView({
|
||||
testTree.toggleDurations = null;
|
||||
testTree.selectFirstFailed = null;
|
||||
testTree.toggleSelectFirstFailed = null;
|
||||
testTree.trackRunning = null;
|
||||
testTree.toggleTrackRunning = null;
|
||||
};
|
||||
});
|
||||
|
||||
@@ -372,6 +400,23 @@ export function TestTreeView({
|
||||
useEffect(() => {
|
||||
if (firstFailed) tree.current?.reveal(firstFailed.key);
|
||||
}, [firstFailed]);
|
||||
|
||||
// Track Running Test: while the run is in progress, select each test as it starts, as IDEA does.
|
||||
const started = useMemo(() => (running ? runningTests(roots) : []), [roots, running]);
|
||||
const [startedIds, setStartedIds] = useState<ReadonlySet<string>>(new Set());
|
||||
const [tracked, setTracked] = useState<{ key: string } | null>(null);
|
||||
if (started.length !== startedIds.size || started.some((t) => !startedIds.has(t.node.id))) {
|
||||
setStartedIds(new Set(started.map((t) => t.node.id)));
|
||||
const latest = trackRunning ? started.findLast((t) => !startedIds.has(t.node.id)) : undefined;
|
||||
if (latest) {
|
||||
if (latest.ancestors.some((a) => !effectiveExpanded.has(a.id)))
|
||||
setExpanded(new Set([...effectiveExpanded, ...latest.ancestors.map((a) => a.id)]));
|
||||
setTracked({ key: latest.node.id });
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
if (tracked) tree.current?.reveal(tracked.key);
|
||||
}, [tracked]);
|
||||
const hasSuites = roots.some((n) => n.children.length > 0);
|
||||
|
||||
// Previous / Next Failed Test (⌘⌥↑ / ⌘⌥↓): like IDEA, stops at the first / last failure instead of wrapping.
|
||||
@@ -494,6 +539,7 @@ export function TestTreeView({
|
||||
icon: "settings",
|
||||
submenu: [
|
||||
{ kind: "action", action: "run.toggleTestDurations" },
|
||||
{ kind: "action", action: "run.toggleTrackRunningTest" },
|
||||
{ kind: "action", action: "run.toggleSelectFirstFailedTest" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -823,6 +823,15 @@ export function activate(): () => void {
|
||||
toggled: () => testTree.showDurations === true,
|
||||
run: () => testTree.toggleDurations?.(),
|
||||
},
|
||||
{
|
||||
id: "run.toggleTrackRunningTest",
|
||||
title: "Track Running Test",
|
||||
category: "Run",
|
||||
when: "projectOpen",
|
||||
enabled: () => testTree.toggleTrackRunning !== null,
|
||||
toggled: () => testTree.trackRunning === true,
|
||||
run: () => testTree.toggleTrackRunning?.(),
|
||||
},
|
||||
{
|
||||
id: "run.toggleSelectFirstFailedTest",
|
||||
title: "Select First Failed Test When Finished",
|
||||
|
||||
@@ -11,6 +11,8 @@ export const testTree: {
|
||||
toggleDurations: (() => void) | null;
|
||||
selectFirstFailed: boolean | null;
|
||||
toggleSelectFirstFailed: (() => void) | null;
|
||||
trackRunning: boolean | null;
|
||||
toggleTrackRunning: (() => void) | null;
|
||||
} = {
|
||||
expandAll: null,
|
||||
collapseAll: null,
|
||||
@@ -19,4 +21,6 @@ export const testTree: {
|
||||
toggleDurations: null,
|
||||
selectFirstFailed: null,
|
||||
toggleSelectFirstFailed: null,
|
||||
trackRunning: null,
|
||||
toggleTrackRunning: null,
|
||||
};
|
||||
@@ -9041,6 +9041,7 @@
|
||||
"Next Failed Test": "Следующий непройденный тест",
|
||||
"Show Test Durations": "Показать длительность тестов",
|
||||
"Select First Failed Test When Finished": "Выбирать первый непройденный тест по завершении",
|
||||
"Track Running Test": "Отслеживать выполняемый тест",
|
||||
"Test Runner Options": "Параметры запуска тестов",
|
||||
"Run '{name}' with Fuzzing": "Запустить '{name}' с фаззингом",
|
||||
"Reading…": "Чтение…",
|
||||
|
||||
@@ -8511,6 +8511,7 @@
|
||||
"Previous Failed Test": "上一個失敗的測試",
|
||||
"Next Failed Test": "下一個失敗的測試",
|
||||
"Select First Failed Test When Finished": "完成後選取第一個失敗的測試",
|
||||
"Track Running Test": "追蹤正在執行的測試",
|
||||
"Run '{name}' with Fuzzing": "使用模糊測試執行 '{name}'",
|
||||
"Reading…": "正在讀取…",
|
||||
"Editing…": "正在編輯…",
|
||||
|
||||
@@ -9263,6 +9263,7 @@
|
||||
"Next Failed Test": "下一个失败的测试",
|
||||
"Show Test Durations": "显示测试耗时",
|
||||
"Select First Failed Test When Finished": "完成后选中第一个失败的测试",
|
||||
"Track Running Test": "跟踪正在运行的测试",
|
||||
"Test Runner Options": "测试运行器选项",
|
||||
"Run '{name}' with Fuzzing": "使用模糊测试运行 '{name}'",
|
||||
"Reading…": "正在读取…",
|
||||
|
||||
Reference in new issue
Заблокувати користувача