This PR extracts the functionality from the `fs_routes` plugin and exposes it onto `App`. These are the new APIs: - `app.layout(pattern, route)` - `app.onError(pattern, route)` - `app.notFound(pattern, route)` - `app.route(pattern, route)` This also removes the need for `.use(staticFiles())`. This line can be safely removed. Fixes https://github.com/denoland/fresh/issues/3040 Fixes https://github.com/denoland/fresh/issues/3033 Fixes https://github.com/denoland/fresh/issues/2591 Fixes https://github.com/denoland/fresh/issues/950 Fixes https://github.com/denoland/fresh/issues/1918
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { expect } from "@std/expect";
|
|
import { escapeScript, pathToExportName } from "./utils.ts";
|
|
|
|
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",
|
|
);
|
|
});
|
|
|
|
Deno.test("escapeScriptContent - closing </script> + </style>", () => {
|
|
expect(
|
|
escapeScript(
|
|
"foo</script>bar</style>baz</script>foobar",
|
|
),
|
|
).toEqual(
|
|
"foo<\\/script>bar<\\/style>baz<\\/script>foobar",
|
|
);
|
|
expect(
|
|
escapeScript(
|
|
"foo</ScRIpT>bar</StYLe>baz</SCRIPT>foobar",
|
|
),
|
|
).toEqual(
|
|
"foo<\\/ScRIpT>bar<\\/StYLe>baz<\\/SCRIPT>foobar",
|
|
);
|
|
});
|
|
|
|
Deno.test("escapeScript - legacy <!--", () => {
|
|
expect(escapeScript("<!--<script>")).toEqual("\\x3C!--<script>");
|
|
expect(escapeScript("<!--</script>")).toEqual("\\x3C!--<\\/script>");
|
|
});
|
|
|
|
Deno.test("escapeScript - script combined", () => {
|
|
expect(escapeScript(`// This is a comment containing <!--
|
|
let foo = x <!--y; // That's valid JS operators
|
|
const s = "This is a string containing <!--";`)).toEqual(
|
|
`// This is a comment containing \\x3C!--
|
|
let foo = x \\x3C!--y; // That's valid JS operators
|
|
const s = "This is a string containing \\x3C!--";`,
|
|
);
|
|
});
|
|
|
|
Deno.test("escapeScript - json", () => {
|
|
expect(escapeScript("<!--<script>", { json: true })).toEqual(
|
|
"\\u003C!--<script>",
|
|
);
|
|
expect(escapeScript("<!--</ScRIpt>", { json: true })).toEqual(
|
|
"\\u003C!--<\\/ScRIpt>",
|
|
);
|
|
});
|