/** * A stubbed `dotnet` process host for the NuGet window specs. No CLI runs: `window.__dotnetOut` * (set by the spec) answers each argument list, and a thrown message becomes a non-zero exit. * The real-CLI vitest tests (`src/features/dotnet/*.cli.test.ts`) are the evidence for what * `dotnet` actually does; these specs check the UI and the exact commands it starts. */ import type { Locator, Page } from "@playwright/test"; import { stubDesktop } from "./fixtures"; declare global { interface Window { __runs: string[][]; __dotnetOut: (args: string[]) => string; } } /** One project, `/dev/acme/src/App/App.csproj`, in the workspace rooted at `/dev/acme`. */ export const PROJECT = "/dev/acme/src/App/App.csproj"; export async function installDotnetHost(page: Page) { await stubDesktop(page); await page.evaluate( async ({ project }) => { window.__runs = []; window.__dotnetOut = () => ""; let id = 100; window.__ipc.handlers.run_start = (args) => { const config = args.config as { args: string[] }; window.__runs.push(config.args); const run = ++id; setTimeout(() => { let text: string; let code = 0; try { text = window.__dotnetOut(config.args); } catch (e) { text = (e as Error).message; code = 1; } window.__ipc.send(args.onOutput, { kind: "stdout", text }); window.__ipc.emit({ type: "runExited", run, code }); }, 20); return { id: run, configId: "x", name: "dotnet", pid: 1, running: true, pty: false }; }; const dotnetStore = "/src/features/dotnet/store.ts"; const projectStore = "/src/platform/project.ts"; const { useDotnet } = await import(/* @vite-ignore */ dotnetStore); const { useProject } = await import(/* @vite-ignore */ projectStore); useProject.setState({ project: { ...useProject.getState().project, root: "/dev/acme" } }); useDotnet.setState({ model: { projects: [ { path: project, name: "App", frameworks: ["net9.0"], configurations: ["Debug"], references: [], packages: [], test: false, runner: "vstest", adapter: "mstest", trx: false, }, ], solutions: [], }, selected: project, framework: "net9.0", }); }, { project: PROJECT }, ); } export const dotnetRuns = (page: Page) => page.evaluate(() => window.__runs); /** Opens the NuGet Packages tool window through its action. */ export async function openNuget(page: Page) { await page.evaluate(async () => { const actions = "/src/platform/actions.ts"; const { executeAction } = await import(/* @vite-ignore */ actions); await executeAction("dotnet.packages"); }); } const SHOTS = process.env.E2E_SHOTS; /** With `E2E_SHOTS` set: a screenshot of the NuGet Packages window scrolled to `focus` (fixture data only). */ export async function shot(page: Page, name: string, focus: Locator) { if (!SHOTS) return; await focus.scrollIntoViewIfNeeded(); await page .locator('section[aria-label="NuGet Packages"]') .screenshot({ path: `${SHOTS}/${name}.png`, animations: "disabled" }); }