/** * 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 }, ]); });