fix: convert island filePath to valid variable name (#2984)

I only added a unit test, but maybe it's testing internals too much?
Should I add a more E2E test in `tests/` with real files?


Closes #2971
This commit is contained in:
Christian Svensson
2025-05-21 11:06:16 +02:00
committed by GitHub
parent b6c02b0668
commit bc8cdb9c7b
4 changed files with 66 additions and 4 deletions
+12 -1
View File
@@ -1,5 +1,5 @@
import { expect } from "@std/expect";
import { mergePaths } from "./utils.ts";
import { mergePaths, pathToExportName } from "./utils.ts";
Deno.test("mergePaths", () => {
expect(mergePaths("", "")).toEqual("");
@@ -9,3 +9,14 @@ Deno.test("mergePaths", () => {
expect(mergePaths("/foo/bar/", "/baz")).toEqual("/foo/bar/baz");
expect(mergePaths("/foo/bar", "baz")).toEqual("/foo/bar/baz");
});
Deno.test("filenameToExportName", () => {
expect(pathToExportName("/islands/foo.tsx")).toBe("foo");
expect(pathToExportName("/islands/foo.v2.tsx")).toBe("foo_v2");
expect(pathToExportName("/islands/nav-bar.tsx")).toBe("nav_bar");
expect(pathToExportName("/islands/_.$bar.tsx")).toBe("_$bar");
expect(pathToExportName("/islands/1.hello.tsx")).toBe("_hello");
expect(pathToExportName("/islands/collapse...repeat_-dash.tsx")).toBe(
"collapse_repeat_dash",
);
});