Файли
openidea/src/features/libraries/libraries.test.ts
T
Jaw 55836e1b49 chore: Format the codebase with oxfmt and check formatting in CI (#135)
Run oxfmt once over the whole repository (formatting only, no logic changes) and add `pnpm format:check` to the frontend CI job so unformatted code no longer builds up. `.oxfmtrc.json` now skips the generated theme docs, test fixtures and code blocks inside Markdown.

Co-authored-by: jaw52 <[email protected]>
2026-10-28 19:35:16 +08:00

87 рядки
3.3 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { isLibraryPath, setLibraryRoots } from "@/editor/api";
import { librariesRoot, touchesManifest } from "./index";
describe("External Libraries", () => {
let dispose = () => {};
afterEach(() => dispose());
it("groups each SDK's folders under one read-only root", () => {
expect(librariesRoot([])).toBeNull();
const root = librariesRoot([
{
name: "Python 3.12 (.venv)",
kind: "python",
roots: [
{ name: "python3.12", path: "/py/lib/python3.12" },
{ name: "site-packages", path: "/p/.venv/lib/python3.12/site-packages" },
],
},
])!;
expect(root).toMatchObject({ id: "externalLibraries", label: "External Libraries", readOnly: true });
expect(root.children?.[0]).toMatchObject({ label: "< Python 3.12 (.venv) >", icon: "file-python" });
expect(root.children?.[0]?.children?.map((c) => [c.label, c.path, c.detail])).toEqual([
["python3.12", "/py/lib/python3.12", "library root"],
["site-packages", "/p/.venv/lib/python3.12/site-packages", "library root"],
]);
});
it("gives each ecosystem's groups their icon", () => {
const root = librariesRoot(
["jdk", "nodeCore", "nodeModules", "rust", "cargo", "go", "goModules", "maven", "gradle", "other"].map(
(kind) => ({
name: kind,
kind,
roots: [{ name: "r", path: `/libs/${kind}` }],
}),
),
)!;
expect(root.children?.map((g) => g.icon)).toEqual([
"file-java",
"file-js",
"file-npm",
"file-rust",
"file-cargo",
"file-go",
"file-gomod",
"maven-project",
"file-gradle",
"library",
]);
});
it("lists archives (src.zip, dependency jars) as browsable roots", () => {
const root = librariesRoot([
{
name: "temurin-21",
kind: "jdk",
roots: [
{ name: "temurin-21", path: "/jdk" },
{ name: "src.zip", path: "/jdk/lib/src.zip!" },
],
},
{ name: "Maven: g:a:1", kind: "maven", roots: [{ name: "a-1-sources.jar", path: "/m2/g/a/1/a-1-sources.jar!" }] },
])!;
expect(root.children?.[0]?.children?.map((c) => c.icon)).toEqual(["folder-library", "file-archive"]);
expect(root.children?.[1]).toMatchObject({ label: "< Maven: g:a:1 >", icon: "maven-project" });
dispose = setLibraryRoots("test", ["/jdk/lib/src.zip!"]);
expect(isLibraryPath("/jdk/lib/src.zip!/java.base/java/lang/String.java")).toBe(true);
});
it("refreshes on manifest changes outside node_modules", () => {
expect(touchesManifest(["/p/src/main.rs", "/p/Cargo.toml"])).toBe(true);
expect(touchesManifest(["C:\\p\\go.mod"])).toBe(true);
expect(touchesManifest(["/p/.venv/pyvenv.cfg"])).toBe(true);
expect(touchesManifest(["/p/node_modules/react/package.json"])).toBe(false);
expect(touchesManifest(["/p/src/package.json.bak", "/p/README.md"])).toBe(false);
});
it("marks files below library roots for read-only editors", () => {
dispose = setLibraryRoots("test", ["/py/lib/python3.12"]);
expect(isLibraryPath("/py/lib/python3.12/os.py")).toBe(true);
expect(isLibraryPath("/py/lib/python3.120/x.py")).toBe(false);
dispose();
expect(isLibraryPath("/py/lib/python3.12/os.py")).toBe(false);
});
});