Files
openidea/src/features/services/dockerGutter.test.ts
T
Deng Liuanddengliu 8cd121ed62 feat(docker): Compose detection, banner, gutter run and Services grouping (#2429)
Only compose.yml / docker-compose.yml were recognised as Compose files, so custom-named or content-only Compose YAML had no Docker icon, no gutter run markers and no Compose support, and running a docker-compose configuration from the gutter added a duplicate top-level Docker Compose group in Services. Compose files are now detected by filename (*compose*.yml/yaml) and by a bounded content scan that excludes Kubernetes, OpenAPI, GitHub Actions, Helm values and mkdocs files; content-detected files show a banner to confirm or reject, and the choice is stored in project settings and follows IDE renames. Detected files get the Docker icon in the tree and tabs, run markers on services: (whole stack) and on each service, and docker runs stay under the Docker node in Services.

Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com>
2026-11-10 09:20:33 +08:00

44 lines
1.9 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { EditorView } from "@codemirror/view";
import * as ui from "@/ui";
import { dockerGutter } from "./dockerGutter";
import { useComposeFiles } from "./compose";
afterEach(() => {
vi.restoreAllMocks();
useComposeFiles.setState({ overrides: {}, contentDetected: {} });
});
it("refreshes markers and menus after edits, removes non-service keys and respects exclusions", async () => {
const menu = vi.spyOn(ui, "showContextMenu").mockImplementation(() => {});
const view = new EditorView({
doc: "services:\n web:\n image: nginx\n x-defaults:\n image: nginx\nvolumes:\n data:\n",
parent: document.body,
extensions: dockerGutter({ doc: 1, path: "/p/stack.yml", language: "yaml", uiMode: null, readOnly: false }),
});
const markers = () => [...view.dom.querySelectorAll<HTMLButtonElement>(".cm-gutterElement button")];
try {
await vi.waitFor(() => expect(markers().map((m) => m.title)).toContain("Compose Up 'web'"));
expect(markers().some((m) => m.title.includes("x-defaults") || m.title.includes("data"))).toBe(false);
view.dispatch({
changes: { from: 0, to: view.state.doc.length, insert: "# moved\nservices:\n db:\n image: postgres\n" },
});
await vi.waitFor(() => expect(markers().some((m) => m.title === "Compose Up 'db'")).toBe(true));
expect(markers().some((m) => m.title === "Compose Up 'web'")).toBe(false);
markers()
.find((m) => m.title === "Compose Up 'db'")!
.click();
expect(menu).toHaveBeenCalledWith(
expect.anything(),
expect.arrayContaining([
expect.objectContaining({ label: "Compose Up 'db'" }),
expect.objectContaining({ label: "Modify Run Configuration…" }),
]),
);
useComposeFiles.setState({ overrides: { "/p/stack.yml": "excluded" } });
await vi.waitFor(() => expect(markers()).toHaveLength(0));
} finally {
view.destroy();
}
});