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
+31
View File
@@ -501,3 +501,34 @@ Deno.test("FreshApp - throw when middleware returns no response", async () => {
expect(res.status).toEqual(500);
expect(text).toContain("Internal server error");
});
Deno.test("FreshApp - adding Island should convert to valid export names", () => {
const app = new App();
const islands = getIslandRegistry(app);
const component1 = () => <>OK</>;
const component2 = () => <>OK</>;
const component3 = () => <>OK</>;
app.island("/islands/foo.v2.tsx", "default", component1);
app.island("/islands/_bar-baz-...-$.tsx", "default", component2);
app.island("/islands/1_hello.tsx", "default", component3);
expect(islands.get(component1)!).toEqual({
file: "/islands/foo.v2.tsx",
name: "foo_v2",
exportName: "default",
fn: component1,
});
expect(islands.get(component2)!).toEqual({
file: "/islands/_bar-baz-...-$.tsx",
name: "_bar_baz_$",
exportName: "default",
fn: component2,
});
expect(islands.get(component3)!).toEqual({
file: "/islands/1_hello.tsx",
name: "_hello",
exportName: "default",
fn: component3,
});
});