Файли
openidea/e2e/dotnetFormat.spec.ts
T
LU XIANGRUIтаwildcatDownstairs 14ed7aa647 feat(csharp): format with CSharpier and run dotnet format (#7645)
In a project that uses CSharpier (a dotnet tool manifest entry, or a .csharpierrc* / .csharpierignore with CSharpier installed), Reformat Code and format on save of a whole .cs file run CSharpier; selections and other projects keep the language server. CSharpier 0.x uses its pipe protocol. Solutions and projects get Run dotnet format and Verify dotnet format (No Changes) in the Project view and Find Action, with output in the Build window. The real SDK tests are ignored by default.

Closes #7626

Co-authored-by: wildcatDownstairs <[email protected]>
2026-12-03 16:58:35 +08:00

87 рядки
3.3 KiB
TypeScript

/**
* Run dotnet format (#7626) from the Project view. The host is stubbed at the IPC layer (no
* `dotnet` runs; the `ide-build` test runs the real CLI): the spec checks the menu, the command
* the UI starts and what the Build window shows.
*/
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
const SHOTS = process.env.E2E_SHOTS;
const FILE = "/dev/acme-api/App/Program.cs";
test("a solution runs and verifies dotnet format in the Build window", async ({ workbench: page }) => {
await stubDesktop(page);
await page.evaluate(async (file) => {
window.__ipc.handlers.build_dotnet_format = (args) => {
const verify = args.verify as boolean;
const title = "dotnet format Acme.sln";
const messages = verify
? [
{
severity: "error",
text: "Fix whitespace formatting. Insert '\\s'.",
path: file,
range: { start: { line: 0, col: 7 }, end: { line: 0, col: 7 } },
code: "WHITESPACE",
},
]
: [];
window.__ipc.send(args.onEvent, { kind: "started", system: "dotnet", title });
window.__ipc.send(args.onEvent, {
kind: "step",
command: verify ? "dotnet format Acme.sln --verify-no-changes" : "dotnet format Acme.sln --verbosity normal",
cwd: "/dev/acme-api",
});
return {
system: "dotnet",
title,
success: !verify,
errors: messages.length,
warnings: 0,
durationMs: 1200,
messages,
};
};
const storeModule = "/src/features/dotnet/store.ts";
const { useDotnet } = await import(/* @vite-ignore */ storeModule);
const project = "/dev/acme-api/App/App.csproj";
useDotnet.setState({
model: {
projects: [
{
path: project,
name: "App",
frameworks: ["net9.0"],
configurations: ["Debug"],
references: [],
packages: [],
test: false,
runner: "vstest",
adapter: "mstest",
trx: false,
},
],
solutions: [{ path: "/dev/acme-api/Acme.sln", projects: [project] }],
},
});
}, FILE);
const solution = page.getByRole("treeitem", { name: /Solution 'Acme'/ });
await solution.click({ button: "right" });
await expect(page.getByRole("menuitem", { name: "Verify dotnet format (No Changes)" })).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/a4-solution-menu.png`, animations: "disabled" });
await page.getByRole("menuitem", { name: "Verify dotnet format (No Changes)" }).click();
await expect(page.getByText("Fix whitespace formatting.").first()).toBeVisible();
await expect(page.getByText("dotnet format failed")).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/a4-verify-build-window.png`, animations: "disabled" });
await solution.click({ button: "right" });
await page.getByRole("menuitem", { name: "Run dotnet format", exact: true }).click();
await expect(page.getByText("dotnet format completed")).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/a4-format-completed.png`, animations: "disabled" });
expect(await ipcCalls(page, "build_dotnet_format")).toMatchObject([
{ file: "/dev/acme-api/Acme.sln", verify: true },
{ file: "/dev/acme-api/Acme.sln", verify: false },
]);
});