Файли
openidea/src/features/run/buildUpdate.test.ts
T
Onur Ugur 8b267c6307 fix(run): stream Tomcat build progress and recognise localized startup lines (#7521)
The Tomcat run's build step ran silently with a dummy cancellation token. It now streams compile and packaging progress to the run console, can be cancelled while the build starts, recognises localized Tomcat startup lines, and ignores error-level lines when detecting readiness. Normal Maven and Gradle WAR packaging is kept so generated and transformed files reach the deployment.

Fixes #7458

Co-authored-by: OnurrUgur <[email protected]>
2026-12-02 21:14:44 +08:00

78 рядки
3.4 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import type { RunConfig } from "@/platform/ipc";
import { cancelTask, useTasks } from "@/workbench/tasks";
const mocks = vi.hoisted(() => ({
startRun: vi.fn(),
stopSession: vi.fn(),
}));
vi.mock("./store", () => ({ startRun: mocks.startRun, stopSession: mocks.stopSession }));
import { compileErrorCollector, runUpdateBuild } from "./buildUpdate";
describe("compileErrorCollector", () => {
it("keeps the compiler errors of Maven, javac and Kotlin output without colour codes", () => {
const errors = compileErrorCollector();
errors.add("[INFO] Compiling 3 source files with javac [debug release 17] to target/classes");
errors.add("\u001b[1;31m[ERROR] /p/src/main/java/a/XxxServiceImpl.java:[1,1] 非法字符: '\\ufeff'\u001b[m");
errors.add("[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile");
// Maven's failure summary repeats the error.
errors.add("[ERROR] /p/src/main/java/a/XxxServiceImpl.java:[1,1] 非法字符: '\\ufeff'");
errors.add("/p/src/main/java/a/B.java:12: error: ';' expected\n int x = 1\n");
errors.add("e: file:///p/src/main/kotlin/a/C.kt:3:5 Unresolved reference: foo");
expect(errors.lines()).toEqual([
"[ERROR] /p/src/main/java/a/XxxServiceImpl.java:[1,1] 非法字符: '\\ufeff'",
"/p/src/main/java/a/B.java:12: error: ';' expected",
"e: file:///p/src/main/kotlin/a/C.kt:3:5 Unresolved reference: foo",
]);
});
it("keeps the first ten and counts the rest", () => {
const errors = compileErrorCollector();
for (let i = 1; i <= 13; i++) errors.add(`[ERROR] /p/A.java:[${i},1] cannot find symbol`);
const lines = errors.lines();
expect(lines).toHaveLength(11);
expect(lines[9]).toBe("[ERROR] /p/A.java:[10,1] cannot find symbol");
expect(lines[10]).toBe("… and 3 more");
});
});
describe("runUpdateBuild", () => {
const build: RunConfig = {
id: "tomcat-build:demo",
name: "Build Tomcat",
kind: "maven",
command: "mvn",
args: ["package"],
cwd: null,
env: {},
detected: false,
isTest: false,
debugAdapter: null,
};
it("reports build progress in background tasks while running and marks done on exit", async () => {
useTasks.setState({ tasks: [] });
mocks.startRun.mockImplementationOnce(async (_build, _reuse, _base, opts) => {
opts.onLine("[INFO] Compiling 5 source files with javac\n");
expect(useTasks.getState().tasks.some((t) => t.message === "Compiling 5 source files with javac")).toBe(true);
queueMicrotask(() => opts.onExit(0, false));
return { id: "run1", status: "running" };
});
await runUpdateBuild(build);
expect(useTasks.getState().tasks.find((t) => t.id === "update-build:tomcat-build:demo")?.done).toBe(true);
});
it("stops a build cancelled while its run session is starting", async () => {
useTasks.setState({ tasks: [] });
mocks.startRun.mockImplementationOnce(async (_build, _reuse, _base, opts) => {
cancelTask("update-build:tomcat-build:demo");
mocks.stopSession.mockImplementationOnce(async () => opts.onExit(null, true));
return { id: "pending-build", status: "running" };
});
await expect(runUpdateBuild(build)).rejects.toThrow();
expect(mocks.stopSession).toHaveBeenCalledWith("pending-build");
expect(useTasks.getState().tasks).toEqual([]);
});
});