Files
openidea/src/features/run/launchSettingsGutter.test.ts
T
l0ng-ai 7fe6f5f58d feat(run): run icons on the profiles of launchSettings.json (#3415)
A .NET project's Properties/launchSettings.json shows a run icon on each Project profile; Run / Debug launch the project's configuration for that profile, or a temporary copy for a profile added since detection ran. The package.json scripts gutter is generalised into entryGutter for this.
2026-11-15 01:04:59 +08:00

71 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { afterEach, describe, expect, it } from "vitest";
import type { RunConfig } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { profileConfig, projectProfiles } from "./launchSettingsGutter";
const SETTINGS = `{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"applicationUrl": "http://localhost:5170"
},
"IIS Express": {
"commandName": "IISExpress"
},
"https": {
"commandName": "Project"
}
}
}`;
const config = (id: string, name: string, launchProfile: string): RunConfig =>
({
id,
name,
kind: "dotnet",
command: "dotnet",
args: ["run", "--project", "src/Api/Api.csproj"],
params: { project: "src/Api/Api.csproj", framework: "net9.0", launchProfile },
}) as unknown as RunConfig;
afterEach(() => useProject.setState({ project: null }));
describe("launchSettings.json run icons", () => {
it("mark the profiles a run can use, on their lines", () => {
expect(projectProfiles(SETTINGS)).toEqual([
{ name: "http", line: 3 },
{ name: "https", line: 10 },
]);
// While the file doesn't parse, every profile keeps its icon.
expect(projectProfiles(SETTINGS.replace('"https": {', '"https": {,')).map((e) => e.name)).toEqual([
"http",
"IIS Express",
]);
});
it("run the project's configuration for the profile, or a temporary copy of it", () => {
useProject.setState({ project: { root: "/repo" } as never });
const path = "/repo/src/Api/Properties/launchSettings.json";
const configs = [
config("dotnet:src/Api/Api.csproj:run:", "Api (.NET Project)", ""),
config("dotnet:src/Api/Api.csproj:run:http", "Api: http", "http"),
];
expect(profileConfig(configs, path, "http")).toEqual({ config: configs[1], saved: true });
const added = profileConfig(configs, path, "https")!;
expect(added.saved).toBe(false);
expect(added.config.name).toBe("Api: https");
expect(added.config.params?.launchProfile).toBe("https");
expect(added.config.args).toEqual([
"run",
"--project",
"src/Api/Api.csproj",
"--framework",
"net9.0",
"--launch-profile",
"https",
]);
expect(profileConfig(configs, "/repo/src/Other/Properties/launchSettings.json", "http")).toBeNull();
});
});