@@ -0,0 +1,176 @@
|
||||
import { App, staticFiles } from "@fresh/core";
|
||||
import {
|
||||
allIslandApp,
|
||||
assertNotSelector,
|
||||
assertSelector,
|
||||
buildProd,
|
||||
Doc,
|
||||
getIsland,
|
||||
parseHtml,
|
||||
withBrowserApp,
|
||||
} from "./test_utils.tsx";
|
||||
|
||||
import { SelfCounter } from "./fixtures_islands/SelfCounter.tsx";
|
||||
import { PartialInIsland } from "./fixtures_islands/PartialInIsland.tsx";
|
||||
import { JsonIsland } from "./fixtures_islands/JsonIsland.tsx";
|
||||
import { FakeServer } from "../src/test_utils.ts";
|
||||
import { Partial } from "@fresh/core/runtime";
|
||||
import { getBuildCache, setBuildCache } from "../src/app.ts";
|
||||
|
||||
await buildProd(allIslandApp);
|
||||
|
||||
function testApp<T>(): App<T> {
|
||||
const selfCounter = getIsland("SelfCounter.tsx");
|
||||
const partialInIsland = getIsland("PartialInIsland.tsx");
|
||||
const jsonIsland = getIsland("JsonIsland.tsx");
|
||||
|
||||
const app = new App<T>()
|
||||
.island(selfCounter, "SelfCounter", SelfCounter)
|
||||
.island(partialInIsland, "PartialInIsland", PartialInIsland)
|
||||
.island(jsonIsland, "JsonIsland", JsonIsland)
|
||||
.use(staticFiles());
|
||||
setBuildCache(app, getBuildCache(allIslandApp));
|
||||
return app;
|
||||
}
|
||||
|
||||
Deno.test("active links - without client nav", async () => {
|
||||
function View() {
|
||||
return (
|
||||
<Doc>
|
||||
<div>
|
||||
<h1>nav</h1>
|
||||
<p>
|
||||
<a href="/active_nav/foo/bar">/active_nav/foo/bar</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/active_nav/foo">/active_nav/foo</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/active_nav">/active_nav</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/">/</a>
|
||||
</p>
|
||||
</div>
|
||||
</Doc>
|
||||
);
|
||||
}
|
||||
|
||||
const app = testApp()
|
||||
.get("/active_nav/foo", (ctx) => {
|
||||
return ctx.render(<View />);
|
||||
})
|
||||
.get("/active_nav", (ctx) => {
|
||||
return ctx.render(<View />);
|
||||
});
|
||||
|
||||
const server = new FakeServer(await app.handler());
|
||||
let res = await server.get("/active_nav");
|
||||
let doc = parseHtml(await res.text());
|
||||
|
||||
assertSelector(doc, "a[href='/'][data-ancestor]");
|
||||
|
||||
// Current
|
||||
assertNotSelector(doc, "a[href='/active_nav'][data-ancestor]");
|
||||
assertSelector(doc, "a[href='/active_nav'][data-current]");
|
||||
assertSelector(doc, `a[href='/active_nav'][aria-current="page"]`);
|
||||
|
||||
// Unrelated links
|
||||
assertNotSelector(doc, "a[href='/active_nav/foo'][data-ancestor]");
|
||||
assertNotSelector(doc, "a[href='/active_nav/foo'][aria-current]");
|
||||
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][data-ancestor]");
|
||||
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][aria-current]");
|
||||
|
||||
res = await server.get(`/active_nav/foo`);
|
||||
doc = parseHtml(await res.text());
|
||||
assertSelector(doc, "a[href='/active_nav/foo'][data-current]");
|
||||
assertSelector(doc, `a[href='/active_nav/foo'][aria-current="page"]`);
|
||||
assertSelector(doc, "a[href='/active_nav'][data-ancestor]");
|
||||
assertSelector(doc, `a[href='/active_nav'][aria-current="true"]`);
|
||||
assertSelector(doc, "a[href='/'][data-ancestor]");
|
||||
assertSelector(doc, `a[href='/'][aria-current="true"]`);
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "active links - updates outside of vdom",
|
||||
fn: async () => {
|
||||
function PartialPage() {
|
||||
return (
|
||||
<div>
|
||||
<Partial name="content">
|
||||
<h1>/active_nav_partial</h1>
|
||||
</Partial>
|
||||
<p>
|
||||
<a href="/active_nav_partial/foo/bar">
|
||||
/active_nav_partial/foo/bar
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/active_nav_partial/foo">/active_nav_partial/foo</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/active_nav_partial">/active_nav_partial</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/">/</a>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const app = testApp()
|
||||
.get("/active_nav_partial/foo", (ctx) => {
|
||||
return ctx.render(<PartialPage />);
|
||||
})
|
||||
.get("/active_nav_partial", (ctx) => {
|
||||
return ctx.render(<PartialPage />);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(`${address}/active_nav_partial`);
|
||||
|
||||
let doc = parseHtml(await page.content());
|
||||
assertSelector(doc, "a[href='/'][data-ancestor]");
|
||||
|
||||
// Current
|
||||
assertNotSelector(doc, "a[href='/active_nav_partial'][data-ancestor]");
|
||||
assertSelector(doc, "a[href='/active_nav_partial'][data-current]");
|
||||
assertSelector(doc, `a[href='/active_nav_partial'][aria-current="page"]`);
|
||||
|
||||
// Unrelated links
|
||||
assertNotSelector(
|
||||
doc,
|
||||
"a[href='/active_nav_partial/foo'][data-ancestor]",
|
||||
);
|
||||
assertNotSelector(
|
||||
doc,
|
||||
"a[href='/active_nav_partial/foo'][aria-current]",
|
||||
);
|
||||
assertNotSelector(
|
||||
doc,
|
||||
"a[href='/active_nav_partial/foo/bar'][data-ancestor]",
|
||||
);
|
||||
assertNotSelector(
|
||||
doc,
|
||||
"a[href='/active_nav_partial/foo/bar'][aria-current]",
|
||||
);
|
||||
|
||||
await page.goto(`${address}/active_nav_partial/foo`);
|
||||
doc = parseHtml(await page.content());
|
||||
assertSelector(doc, "a[href='/active_nav_partial/foo'][data-current]");
|
||||
assertSelector(
|
||||
doc,
|
||||
`a[href='/active_nav_partial/foo'][aria-current="page"]`,
|
||||
);
|
||||
assertSelector(doc, "a[href='/active_nav_partial'][data-ancestor]");
|
||||
assertSelector(
|
||||
doc,
|
||||
`a[href='/active_nav_partial'][data-ancestor][aria-current="true"]`,
|
||||
);
|
||||
assertSelector(doc, "a[href='/'][data-ancestor]");
|
||||
assertSelector(doc, `a[href='/'][aria-current="true"]`);
|
||||
});
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
@@ -1,350 +0,0 @@
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertMatch,
|
||||
assertStringIncludes,
|
||||
delay,
|
||||
Page,
|
||||
Project,
|
||||
puppeteer,
|
||||
STATUS_CODE,
|
||||
} from "./deps.ts";
|
||||
import {
|
||||
clickWhenListenerReady,
|
||||
getErrorOverlay,
|
||||
runBuild,
|
||||
waitForText,
|
||||
withFakeServe,
|
||||
withFresh,
|
||||
withPageName,
|
||||
} from "./test_utils.ts";
|
||||
|
||||
Deno.test("redirects on incomplete base path in url", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
await delay(100);
|
||||
|
||||
const url = new URL(address);
|
||||
const res = await fetch(url.origin);
|
||||
assert(
|
||||
res.url.endsWith("/foo/bar"),
|
||||
`didn't redirect to base path: "${res.url}"`,
|
||||
);
|
||||
assert(res.redirected, "did not redirect");
|
||||
assertEquals(res.status, STATUS_CODE.OK);
|
||||
await res.body?.cancel();
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("shows full address with base path in cli", async () => {
|
||||
// deno-lint-ignore require-await
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
assertMatch(address, /^http:\/\/localhost:\d+\/foo\/bar$/);
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("rewrites middleware request", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
const res = await fetch(`${address}/api`);
|
||||
const body = await res.text();
|
||||
assertEquals(body, "middleware is working");
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("rewrites root relative middleware redirects", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
const res = await fetch(`${address}/api/rewrite`);
|
||||
assertEquals(res.status, STATUS_CODE.OK);
|
||||
assertEquals(res.url, address);
|
||||
await res.body?.cancel();
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("passes basePath to route handlers", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
const res = await fetch(`${address}/api/base-handler`);
|
||||
assertEquals(res.status, STATUS_CODE.OK);
|
||||
assertEquals(await res.text(), "/foo/bar");
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("works with relative urls", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||
const page = await browser.newPage();
|
||||
await page.goto(`${address}/a/b/relative`);
|
||||
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.click("a"),
|
||||
]);
|
||||
|
||||
const html = await page.content();
|
||||
assertMatch(html, /it works/);
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("rewrites root relative URLs in HTML", async () => {
|
||||
await withFresh("./tests/fixture_base_path/main.ts", async (address) => {
|
||||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||
const page = await browser.newPage();
|
||||
await page.goto(`${address}/html`);
|
||||
|
||||
const script = await page.$eval("#script-output", (el) => el.textContent);
|
||||
assertEquals(script, "it works");
|
||||
|
||||
const img = await page.$eval("img", (el) => ({
|
||||
src: el.src,
|
||||
}));
|
||||
assertMatch(img.src, /\/foo\/bar\/img\.png/);
|
||||
|
||||
const img2 = await page.$eval(".img-srcset", (el) => ({
|
||||
src: el.src,
|
||||
srcset: el.srcset,
|
||||
}));
|
||||
assertMatch(img2.src, /\/foo\/bar\/img\.png/);
|
||||
assertMatch(
|
||||
img2.srcset,
|
||||
/\/foo\/bar\/img\.png.* 480w,.*\/foo\/bar\/img\.png.* 800w/,
|
||||
);
|
||||
|
||||
const source = await page.$eval("picture source", (el) => ({
|
||||
srcset: el.srcset,
|
||||
}));
|
||||
assertMatch(
|
||||
source.srcset,
|
||||
/\/foo\/bar\/img\.png/,
|
||||
);
|
||||
|
||||
const style = await page.$eval(
|
||||
".foo",
|
||||
(el) => globalThis.getComputedStyle(el).color,
|
||||
);
|
||||
assertMatch(
|
||||
style,
|
||||
/rgb\(255,\s+0,\s+0\)/,
|
||||
);
|
||||
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("island tests", async (t) => {
|
||||
await withPageName(
|
||||
"./tests/fixture_base_path/main.ts",
|
||||
async (page, address) => {
|
||||
async function counterTest(counterId: string, originalValue: number) {
|
||||
const pElem = await page.waitForSelector(`#${counterId} > p`);
|
||||
|
||||
const value = await pElem?.evaluate((el) => el.textContent);
|
||||
assert(value === `${originalValue}`, `${counterId} first value`);
|
||||
|
||||
await clickWhenListenerReady(page, `#b-${counterId}`);
|
||||
await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
|
||||
}
|
||||
|
||||
await page.goto(`${address}/islands`);
|
||||
|
||||
await t.step("Ensure 1 islands on 1 page are revived", async () => {
|
||||
await counterTest("counter1", 3);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assets prefixed dev", async (t) => {
|
||||
await withPageName(
|
||||
"./tests/fixture_base_path/dev.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/islands`);
|
||||
|
||||
await t.step("ensure every preload link is prefixed", async () => {
|
||||
await checkPreloadLinks(page, "/foo/bar");
|
||||
});
|
||||
|
||||
await t.step("ensure every script link is prefixed", async () => {
|
||||
await checkScriptSrcs(page, "/foo/bar");
|
||||
});
|
||||
|
||||
await t.step("ensure inline content is prefixed", async () => {
|
||||
await checkInlineScripts(page, "/foo/bar");
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assets prefixed main", async (t) => {
|
||||
await withPageName(
|
||||
"./tests/fixture_base_path/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/islands`);
|
||||
|
||||
await t.step("ensure every preload link is prefixed", async () => {
|
||||
await checkPreloadLinks(page, "/foo/bar");
|
||||
});
|
||||
|
||||
// no script sent out, because dev sends out dev_client.js
|
||||
|
||||
await t.step("ensure inline content is prefixed", async () => {
|
||||
await checkInlineScripts(page, "/foo/bar");
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("renders error boundary", async () => {
|
||||
await withPageName(
|
||||
"./tests/fixture_base_path/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/error_boundary`);
|
||||
const text = await page.$eval("p", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("dev_command config: shows codeframe", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_base_path/dev.ts",
|
||||
async (server) => {
|
||||
const { codeFrame } = await getErrorOverlay(server, "/codeframe");
|
||||
assert(codeFrame);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - dev mode", async () => {
|
||||
await withFakeServe("./tests/fixture_base_path/dev.ts", async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-red-600");
|
||||
|
||||
const res2 = await server.get("/styles.css?foo=bar");
|
||||
const content2 = await res2.text();
|
||||
assert(!content2.includes("@tailwind"));
|
||||
}, { loadConfig: true });
|
||||
});
|
||||
|
||||
Deno.test("middleware test", async (t) => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_base_path/dev.ts",
|
||||
async (server) => {
|
||||
await t.step("expected root", async () => {
|
||||
const res = await server.get("/foo/bar");
|
||||
const content = await res.text();
|
||||
assertEquals(res.headers.get("server"), "fresh server");
|
||||
assertStringIncludes(content, "middleware is working");
|
||||
});
|
||||
|
||||
await t.step("redirect root", async () => {
|
||||
const res = await server.get("");
|
||||
const content = await res.text();
|
||||
assertEquals(res.headers.get("server"), "fresh server");
|
||||
assertStringIncludes(content, "middleware is working");
|
||||
});
|
||||
|
||||
await t.step("miiddleware before an invalid route", async () => {
|
||||
const res = await server.get("/asdfasdfasdfasdfasdfasdf");
|
||||
assertEquals(res.headers.get("server"), "fresh server");
|
||||
await res.body?.cancel();
|
||||
});
|
||||
},
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - build mode", async () => {
|
||||
await runBuild("./tests/fixture_base_path_build/dev.ts");
|
||||
await withFakeServe(
|
||||
"./tests/fixture_base_path_build/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-red-600{");
|
||||
},
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - config", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_base_path_config/dev.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-pp");
|
||||
},
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - middleware only css", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_base_path/dev.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/middleware-only.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".foo-bar");
|
||||
},
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
|
||||
function extractImportUrls(scriptContent: string): string[] {
|
||||
const project = new Project({
|
||||
useInMemoryFileSystem: true,
|
||||
});
|
||||
|
||||
const sourceFile = project.createSourceFile("script.js", scriptContent);
|
||||
|
||||
const importDeclarations = sourceFile.getImportDeclarations();
|
||||
|
||||
return importDeclarations.map((importDeclaration) =>
|
||||
importDeclaration.getModuleSpecifierValue()
|
||||
);
|
||||
}
|
||||
|
||||
async function checkPreloadLinks(page: Page, basePath: string) {
|
||||
const preloadLinks: string[] = await page.$$eval(
|
||||
'link[rel="modulepreload"]',
|
||||
(links) => links.map((link) => link.getAttribute("href")),
|
||||
);
|
||||
assert(preloadLinks.length > 0, "No preload links found");
|
||||
preloadLinks.forEach((href) => {
|
||||
assert(
|
||||
href.startsWith(basePath),
|
||||
`Preload link ${href} does not include the correct base path`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function checkScriptSrcs(page: Page, basePath: string) {
|
||||
const scriptSrcs: string[] = await page.$$eval(
|
||||
"script[src]",
|
||||
(scripts) => scripts.map((script) => script.getAttribute("src")),
|
||||
);
|
||||
assert(scriptSrcs.length > 0, "No script srcs found");
|
||||
scriptSrcs.forEach((src) => {
|
||||
assert(
|
||||
src.startsWith(basePath),
|
||||
`Script src ${src} does not include the correct base path`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function checkInlineScripts(page: Page, basePath: string) {
|
||||
const inlineScripts = await page.$$eval(
|
||||
"script:not([src])",
|
||||
(scripts) => scripts.map((script) => script.textContent),
|
||||
);
|
||||
assert(inlineScripts.length > 0, "No inline scripts found");
|
||||
inlineScripts.forEach((scriptContent) => {
|
||||
const importUrls = extractImportUrls(scriptContent);
|
||||
importUrls.forEach((url) => {
|
||||
assert(
|
||||
url.startsWith(basePath),
|
||||
`Import URL ${url} does not include the correct base path`,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
import * as path from "$std/path/mod.ts";
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertNotMatch,
|
||||
assertStringIncludes,
|
||||
puppeteer,
|
||||
} from "./deps.ts";
|
||||
import {
|
||||
getStdOutput,
|
||||
recreateFolder,
|
||||
startFreshServer,
|
||||
waitForText,
|
||||
withFakeServe,
|
||||
} from "./test_utils.ts";
|
||||
import { BuildSnapshotJson } from "../src/build/mod.ts";
|
||||
|
||||
function runBuild(fixture: string, subDirPath: string, outDir: string) {
|
||||
return new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
path.join(fixture, subDirPath, "dev.ts"),
|
||||
"build",
|
||||
],
|
||||
env: {
|
||||
GITHUB_SHA: "__BUILD_ID__",
|
||||
DENO_DEPLOYMENT_ID: "__BUILD_ID__",
|
||||
FRESH_TEST_OUTDIR: outDir,
|
||||
},
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
}).output();
|
||||
}
|
||||
|
||||
async function testBuild(
|
||||
t: Deno.TestContext,
|
||||
fixture: string,
|
||||
options: {
|
||||
subDirPath?: string;
|
||||
outDir?: string;
|
||||
} = {},
|
||||
) {
|
||||
const subDirPath = options.subDirPath ?? "";
|
||||
const outDir = options.outDir ?? path.join(fixture, subDirPath, "_fresh");
|
||||
|
||||
try {
|
||||
await t.step("build snapshot", async () => {
|
||||
const res = await runBuild(fixture, subDirPath, outDir);
|
||||
const { stdout } = getStdOutput(res);
|
||||
assert(
|
||||
!/Using snapshot found at/.test(stdout),
|
||||
"Using snapshot message was shown during build",
|
||||
);
|
||||
|
||||
assert((await Deno.stat(outDir)).isDirectory, "Missing output directory");
|
||||
});
|
||||
|
||||
const snapshot = JSON.parse(
|
||||
await Deno.readTextFile(path.join(outDir, "snapshot.json")),
|
||||
) as BuildSnapshotJson;
|
||||
|
||||
await t.step("check snapshot file", async () => {
|
||||
assert(
|
||||
Array.isArray(snapshot.files["island-counter.js"]),
|
||||
"Island output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
Array.isArray(snapshot.files["main.js"]),
|
||||
"main.js output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
Array.isArray(snapshot.files["signals.js"]),
|
||||
"signals.js output file not found in snapshot",
|
||||
);
|
||||
|
||||
// Should not include `preact/debug`
|
||||
const mainJs = await Deno.readTextFile(path.join(outDir, "main.js"));
|
||||
assertNotMatch(mainJs, /Undefined parent passed to render()/);
|
||||
});
|
||||
|
||||
await t.step("restore from snapshot", async () => {
|
||||
const { lines, serverProcess, address, output } = await startFreshServer({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
path.join(fixture, subDirPath, "main.ts"),
|
||||
],
|
||||
});
|
||||
|
||||
// Check if restore snapshot message was printed
|
||||
assert(
|
||||
output.find((line) => line.includes("Using snapshot found at")),
|
||||
"Did not print restoring from snapshot line",
|
||||
);
|
||||
|
||||
try {
|
||||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
await page.goto(address);
|
||||
|
||||
await page.waitForSelector("button:not([disabled])");
|
||||
await page.click("button");
|
||||
|
||||
await waitForText(page, "p", "1");
|
||||
|
||||
// Ensure that it uses the build id from the snapshot
|
||||
const assetUrls = await page.evaluate(() => {
|
||||
const links = Array.from(document.querySelectorAll("link")).map(
|
||||
(link) => link.href,
|
||||
);
|
||||
const scripts = Array.from(document.querySelectorAll("script"))
|
||||
.filter((script) =>
|
||||
script.src && !script.src.endsWith("refresh.js")
|
||||
).map((script) => script.src);
|
||||
|
||||
return [...links, ...scripts];
|
||||
});
|
||||
|
||||
for (let i = 0; i < assetUrls.length; i++) {
|
||||
assertStringIncludes(assetUrls[i], snapshot.build_id);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
} finally {
|
||||
serverProcess.kill("SIGTERM");
|
||||
await serverProcess.status;
|
||||
|
||||
// Drain the lines stream
|
||||
for await (const _ of lines) { /* noop */ }
|
||||
}
|
||||
});
|
||||
|
||||
await t.step("should not restore from snapshot in dev mode", async () => {
|
||||
const { lines, serverProcess, output } = await startFreshServer({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
path.join(fixture, subDirPath, "dev.ts"),
|
||||
],
|
||||
});
|
||||
|
||||
try {
|
||||
// Check that restore snapshot message was NOT printed
|
||||
assert(
|
||||
!output.find((line) => line.includes("Using snapshot found at")),
|
||||
"Restoring from snapshot message should not appear in dev mode",
|
||||
);
|
||||
} finally {
|
||||
serverProcess.kill("SIGTERM");
|
||||
await serverProcess.status;
|
||||
|
||||
// Drain the lines stream
|
||||
for await (const _ of lines) { /* noop */ }
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
await Deno.remove(path.join(fixture, subDirPath, "_fresh"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test("build snapshot and restore from it", async (t) => {
|
||||
// Note: If you change the fixture_build directory, you must also update fixture_build_sub_dir
|
||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build");
|
||||
await testBuild(t, fixture);
|
||||
});
|
||||
|
||||
Deno.test("build snapshot and restore from it when has sub dirs", async (t) => {
|
||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build_sub_dir");
|
||||
await testBuild(t, fixture, { subDirPath: "src" });
|
||||
});
|
||||
|
||||
Deno.test(
|
||||
"build snapshot with custom build.outDir",
|
||||
async (t) => {
|
||||
async function assertOutputDir(outDir: string, out: Deno.CommandOutput) {
|
||||
const { stdout, stderr } = getStdOutput(out);
|
||||
|
||||
const msg =
|
||||
`Missing output directory: ${outDir}\n\nCLI output:\n${stdout}\n${stderr}`;
|
||||
|
||||
const dir: string | URL = outDir.startsWith("file://")
|
||||
? new URL(outDir)
|
||||
: outDir;
|
||||
try {
|
||||
assert((await Deno.stat(dir)).isDirectory, msg);
|
||||
} catch (err) {
|
||||
throw new Error(msg, { cause: err });
|
||||
}
|
||||
}
|
||||
|
||||
await t.step("uses on relative outDir", async () => {
|
||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build_out_dir");
|
||||
const out = await runBuild(fixture, "", "./tmp/asdf");
|
||||
const outDir = path.join(fixture, "tmp", "asdf");
|
||||
|
||||
await assertOutputDir(outDir, out);
|
||||
});
|
||||
|
||||
await t.step("uses absolute outDir", async () => {
|
||||
const fixture = path.join(
|
||||
Deno.cwd(),
|
||||
"tests",
|
||||
"fixture_build_out_dir_sub",
|
||||
);
|
||||
|
||||
const outDir = path.join(fixture, "tmp");
|
||||
const out = await runBuild(fixture, "src", outDir);
|
||||
|
||||
await assertOutputDir(outDir, out);
|
||||
});
|
||||
|
||||
await t.step("uses file:// outDir", async () => {
|
||||
const fixture = path.join(
|
||||
Deno.cwd(),
|
||||
"tests",
|
||||
"fixture_build_out_dir_sub2",
|
||||
);
|
||||
|
||||
const outDirPath = path.join(fixture, "tmp");
|
||||
const outDir = path.toFileUrl(outDirPath).href;
|
||||
const out = await runBuild(fixture, "src", outDir);
|
||||
await assertOutputDir(outDir, out);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test("pass target options", async () => {
|
||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build_target");
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
path.join(fixture, "dev.ts"),
|
||||
"build",
|
||||
],
|
||||
env: {
|
||||
GITHUB_SHA: "__BUILD_ID__",
|
||||
DENO_DEPLOYMENT_ID: "__BUILD_ID__",
|
||||
FRESH_TEST_TARGET: "es2015",
|
||||
},
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout, stderr } = getStdOutput(out);
|
||||
const txt = await Deno.readTextFile(
|
||||
path.join(fixture, "_fresh", "island-counter.js"),
|
||||
);
|
||||
|
||||
assertNotMatch(
|
||||
txt,
|
||||
/\?\?/,
|
||||
`Asset contained ?? despite target es2015\n\n${stdout}\n${stderr}`,
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("serve static files from build dir", async () => {
|
||||
const filePath = path.join(
|
||||
path.dirname(path.fromFileUrl(import.meta.url)),
|
||||
"fixture_build_static",
|
||||
"_fresh",
|
||||
"static",
|
||||
"foo.txt",
|
||||
);
|
||||
|
||||
await recreateFolder(path.dirname(filePath));
|
||||
await Deno.writeTextFile(filePath, `it works`);
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_build_static/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/foo.txt");
|
||||
const text = await res.text();
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("prefer static files from build dir", async () => {
|
||||
const filePath = path.join(
|
||||
path.dirname(path.fromFileUrl(import.meta.url)),
|
||||
"fixture_build_static",
|
||||
"_fresh",
|
||||
"static",
|
||||
"duplicate.txt",
|
||||
);
|
||||
|
||||
await recreateFolder(path.dirname(filePath));
|
||||
await Deno.writeTextFile(filePath, "it works");
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_build_static/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/duplicate.txt");
|
||||
const text = await res.text();
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1,361 +0,0 @@
|
||||
import { join } from "../src/server/deps.ts";
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertMatch,
|
||||
assertNotEquals,
|
||||
assertNotMatch,
|
||||
} from "./deps.ts";
|
||||
import versions from "../versions.json" with { type: "json" };
|
||||
import { CheckFile } from "../src/dev/update_check.ts";
|
||||
import { WEEK } from "../src/dev/deps.ts";
|
||||
import { getStdOutput } from "../tests/test_utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "stores update check file in $HOME/fresh",
|
||||
async fn() {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
const filePath = join(tmpDirName, "latest.json");
|
||||
|
||||
await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
},
|
||||
}).output();
|
||||
|
||||
const text = JSON.parse(await Deno.readTextFile(filePath));
|
||||
assertEquals(text, {
|
||||
current_version: versions[0],
|
||||
latest_version: "99.99.999",
|
||||
last_checked: text.last_checked,
|
||||
last_shown: text.last_shown,
|
||||
});
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "skips update check on specific environment variables",
|
||||
async fn(t) {
|
||||
const envs = ["FRESH_NO_UPDATE_CHECK", "CI", "DENO_DEPLOYMENT_ID"];
|
||||
|
||||
for (const env of envs) {
|
||||
await t.step(`checking ${env}`, async () => {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
[env]: "true",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: "1.30.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertNotMatch(stdout, /Fresh 1\.30\.0 is available/);
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "shows update message on version mismatch",
|
||||
async fn() {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
const filePath = join(tmpDirName, "latest.json");
|
||||
|
||||
await Deno.writeTextFile(
|
||||
filePath,
|
||||
JSON.stringify({
|
||||
current_version: "1.1.0",
|
||||
latest_version: "1.1.0",
|
||||
last_checked: new Date(0).toISOString(),
|
||||
}),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: "999.999.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertMatch(stdout, /Fresh 999\.999\.0 is available/);
|
||||
|
||||
// Updates check file
|
||||
const text = JSON.parse(await Deno.readTextFile(filePath));
|
||||
assertEquals(text, {
|
||||
current_version: versions[0],
|
||||
latest_version: "999.999.0",
|
||||
last_checked: text.last_checked,
|
||||
last_shown: text.last_shown,
|
||||
});
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "only fetch new version defined by interval",
|
||||
async fn(t) {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
await t.step("fetches latest version initially", async () => {
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
UPDATE_INTERVAL: "100000",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: "1.30.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertMatch(stdout, /fetching latest version/);
|
||||
});
|
||||
|
||||
await t.step("should not fetch if interval has not passed", async () => {
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
UPDATE_INTERVAL: "100000",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: "1.30.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertNotMatch(stdout, /fetching latest version/);
|
||||
});
|
||||
|
||||
await t.step("fetches if interval has passed", async () => {
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
UPDATE_INTERVAL: "1 ",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: "1.30.0",
|
||||
},
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertMatch(stdout, /fetching latest version/);
|
||||
});
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "updates current version in cache file",
|
||||
async fn() {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
const checkFile: CheckFile = {
|
||||
current_version: "1.2.0",
|
||||
latest_version: "1.2.0",
|
||||
last_checked: new Date(Date.now() - WEEK).toISOString(),
|
||||
};
|
||||
|
||||
await Deno.writeTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
JSON.stringify(checkFile, null, 2),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: versions[0],
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertNotMatch(stdout, /Fresh .* is available/);
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "only shows update message when current < latest",
|
||||
async fn() {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
const checkFile: CheckFile = {
|
||||
current_version: "9999.999.0",
|
||||
latest_version: "1.2.0",
|
||||
last_checked: new Date().toISOString(),
|
||||
};
|
||||
|
||||
await Deno.writeTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
JSON.stringify(checkFile, null, 2),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
LATEST_VERSION: versions[0],
|
||||
CURRENT_VERSION: "99999.9999.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertNotMatch(stdout, /Fresh .* is available/);
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("migrates to last_shown property", async () => {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
const checkFile: CheckFile = {
|
||||
latest_version: "1.4.0",
|
||||
current_version: "1.2.0",
|
||||
last_checked: new Date().toISOString(),
|
||||
};
|
||||
|
||||
await Deno.writeTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
JSON.stringify(checkFile, null, 2),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
CURRENT_VERSION: "1.2.0",
|
||||
LATEST_VERSION: "99999.9999.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertMatch(stdout, /Fresh .* is available/);
|
||||
|
||||
const checkFileAfter = JSON.parse(
|
||||
await Deno.readTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
),
|
||||
);
|
||||
|
||||
assert(
|
||||
typeof checkFileAfter.last_shown === "string",
|
||||
"Did not write last_shown " + JSON.stringify(checkFileAfter, null, 2),
|
||||
);
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("doesn't show update if last_shown + interval >= today", async () => {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
const todayMinus1Hour = new Date();
|
||||
todayMinus1Hour.setHours(todayMinus1Hour.getHours() - 1);
|
||||
|
||||
const checkFile: CheckFile = {
|
||||
current_version: "1.2.0",
|
||||
latest_version: "1.6.0",
|
||||
last_checked: new Date().toISOString(),
|
||||
last_shown: todayMinus1Hour.toISOString(),
|
||||
};
|
||||
|
||||
await Deno.writeTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
JSON.stringify(checkFile, null, 2),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
CURRENT_VERSION: "1.2.0",
|
||||
LATEST_VERSION: "99999.9999.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertNotMatch(stdout, /Fresh .* is available/);
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test(
|
||||
"shows update if last_shown + interval < today",
|
||||
async () => {
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
const checkFile: CheckFile = {
|
||||
current_version: "1.2.0",
|
||||
latest_version: "1.8.0",
|
||||
last_checked: new Date().toISOString(),
|
||||
last_shown: yesterday.toISOString(),
|
||||
};
|
||||
|
||||
await Deno.writeTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
JSON.stringify(checkFile, null, 2),
|
||||
);
|
||||
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_update_check/mod.ts"],
|
||||
env: {
|
||||
CI: "false",
|
||||
TEST_HOME: tmpDirName,
|
||||
CURRENT_VERSION: versions[0],
|
||||
LATEST_VERSION: "99999.9999.0",
|
||||
},
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
const { stdout } = getStdOutput(out);
|
||||
assertMatch(stdout, /Fresh .* is available/);
|
||||
|
||||
const checkFileAfter = JSON.parse(
|
||||
await Deno.readTextFile(
|
||||
join(tmpDirName, "latest.json"),
|
||||
),
|
||||
);
|
||||
|
||||
assertNotEquals(checkFileAfter.last_shown, yesterday.toISOString());
|
||||
|
||||
await Deno.remove(tmpDirName, { recursive: true });
|
||||
},
|
||||
);
|
||||
@@ -1,52 +0,0 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
export {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertExists,
|
||||
AssertionError,
|
||||
assertMatch,
|
||||
assertNotEquals,
|
||||
assertNotMatch,
|
||||
assertRejects,
|
||||
assertStringIncludes,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.216.0/assert/mod.ts";
|
||||
export { assertSnapshot } from "https://deno.land/std@0.216.0/testing/snapshot.ts";
|
||||
export {
|
||||
TextLineStream,
|
||||
} from "https://deno.land/std@0.216.0/streams/text_line_stream.ts";
|
||||
export { delay } from "https://deno.land/std@0.216.0/async/delay.ts";
|
||||
export { retry } from "https://deno.land/std@0.216.0/async/retry.ts";
|
||||
export {
|
||||
default as puppeteer,
|
||||
Page,
|
||||
} from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
|
||||
export {
|
||||
Document,
|
||||
DOMParser,
|
||||
HTMLElement,
|
||||
HTMLMetaElement,
|
||||
} from "https://esm.sh/linkedom@0.16.8";
|
||||
export { defineConfig, type Preset } from "https://esm.sh/@twind/core@1.1.3";
|
||||
export { default as presetTailwind } from "https://esm.sh/@twind/preset-tailwind@1.1.4";
|
||||
export { copy } from "https://deno.land/std@0.216.0/fs/mod.ts";
|
||||
export {
|
||||
basename,
|
||||
dirname,
|
||||
extname,
|
||||
fromFileUrl,
|
||||
join,
|
||||
relative,
|
||||
SEPARATOR,
|
||||
toFileUrl,
|
||||
} from "https://deno.land/std@0.216.0/path/mod.ts";
|
||||
export * as JSONC from "https://deno.land/std@0.216.0/jsonc/mod.ts";
|
||||
export * as colors from "https://deno.land/std@0.216.0/fmt/colors.ts";
|
||||
export { STATUS_CODE } from "https://deno.land/std@0.216.0/http/status.ts";
|
||||
export { stripAnsiCode } from "https://deno.land/std@0.216.0/fmt/colors.ts";
|
||||
export { Project } from "https://deno.land/x/ts_morph@21.0.1/mod.ts";
|
||||
@@ -1,156 +0,0 @@
|
||||
import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
|
||||
import { STATUS_CODE } from "../server.ts";
|
||||
import {
|
||||
assertNotSelector,
|
||||
assertTextMany,
|
||||
assertTextMatch,
|
||||
fetchHtml,
|
||||
getErrorOverlay,
|
||||
waitForStyle,
|
||||
withFakeServe,
|
||||
withFresh,
|
||||
withPageName,
|
||||
} from "./test_utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "dev_command config",
|
||||
async fn() {
|
||||
await withPageName(
|
||||
"./tests/fixture_dev_config/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}`);
|
||||
await waitForStyle(page, "h1", "color", "rgb(220, 38, 38)");
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("dev_command config: shows codeframe", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_config/dev.ts",
|
||||
async (server) => {
|
||||
const { codeFrame } = await getErrorOverlay(server, "/codeframe");
|
||||
assert(codeFrame);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("dev_command legacy", async () => {
|
||||
await withPageName(
|
||||
"./tests/fixture_dev_legacy/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}`);
|
||||
await waitForStyle(page, "h1", "color", "rgb(220, 38, 38)");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("dev_command legacy: shows codeframe", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_legacy/dev.ts",
|
||||
async (server) => {
|
||||
const { codeFrame } = await getErrorOverlay(server, "/codeframe");
|
||||
assert(codeFrame);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("preact/debug is active in dev mode", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_render_error/dev.ts",
|
||||
async (server) => {
|
||||
// SSR error is shown
|
||||
const resp = await server.get("/");
|
||||
await resp.text(); // Consume
|
||||
assertEquals(resp.status, STATUS_CODE.InternalServerError);
|
||||
|
||||
const { title } = await getErrorOverlay(server, "/");
|
||||
assertStringIncludes(title, "Objects are not valid as a child");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("warns when using hooks in server components", async (t) => {
|
||||
await withFakeServe("./tests/fixture/main.ts", async (server) => {
|
||||
await t.step("useState", async () => {
|
||||
const doc = await server.getHtml(`/hooks-server/useState`);
|
||||
assertTextMatch(doc, "p", /Hook "useState" cannot be used/);
|
||||
// Check for hint
|
||||
assertTextMatch(doc, "p", /Instead, use the "useSignal" hook/);
|
||||
});
|
||||
|
||||
await t.step("useReducer", async () => {
|
||||
const doc = await server.getHtml(`/hooks-server/useReducer`);
|
||||
assertTextMatch(doc, "p", /Hook "useReducer" cannot be used/);
|
||||
});
|
||||
|
||||
// Valid
|
||||
await t.step("does not warn in island", async () => {
|
||||
const doc = await server.getHtml(`/hooks-server/island`);
|
||||
assertTextMany(doc, "p", ["0"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("shows custom 500 page for rendering errors when not in dev", async (t) => {
|
||||
await withFresh({
|
||||
name: "./tests/fixture/main.ts",
|
||||
options: {
|
||||
env: {
|
||||
DENO_DEPLOYMENT_ID: "foo",
|
||||
},
|
||||
},
|
||||
}, async (address) => {
|
||||
await t.step("useState", async () => {
|
||||
const doc = await fetchHtml(`${address}/hooks-server/useState`);
|
||||
assertNotSelector(doc, "pre");
|
||||
});
|
||||
|
||||
await t.step("useReducer", async () => {
|
||||
const doc = await fetchHtml(`${address}/hooks-server/useReducer`);
|
||||
assertNotSelector(doc, "pre");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("show codeframe in dev mode even with custom 500", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_codeframe/dev.ts",
|
||||
async (server) => {
|
||||
const { title } = await getErrorOverlay(server, "/");
|
||||
assertEquals(title, "fail");
|
||||
},
|
||||
);
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_dev_codeframe/main.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml("/");
|
||||
assertNotSelector(doc, "#fresh-error-overlay");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("serve client script source map", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture/dev.ts",
|
||||
async (server) => {
|
||||
const res = await server.get(`/_frsh/fresh_dev_client.js`);
|
||||
await res.text(); // Consume body
|
||||
assertEquals(res.status, 200);
|
||||
assertEquals(
|
||||
res.headers.get("Content-Type"),
|
||||
"application/javascript; charset=UTF-8",
|
||||
);
|
||||
|
||||
const res2 = await server.get(`/_frsh/fresh_dev_client.js.map`);
|
||||
const json = await res2.json();
|
||||
assertEquals(res2.status, 200);
|
||||
assertEquals(
|
||||
res2.headers.get("Content-Type"),
|
||||
"application/json; charset=UTF-8",
|
||||
);
|
||||
assert(typeof json.mappings, "string");
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1,46 +0,0 @@
|
||||
import { collect } from "../src/dev/mod.ts";
|
||||
import { assert, dirname, fromFileUrl, join } from "./deps.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "routes collect",
|
||||
fn: async () => {
|
||||
const { routes } = await collect(
|
||||
join(dirname(fromFileUrl(import.meta.url)), "fixture"),
|
||||
);
|
||||
|
||||
assert(
|
||||
!routes.includes("routes/not_found.test.ts") &&
|
||||
!routes.includes("routes\\not_found.test.ts"),
|
||||
);
|
||||
assert(
|
||||
!routes.includes("routes/_404_test.tsx") &&
|
||||
!routes.includes("routes\\_404_test.tsx"),
|
||||
);
|
||||
assert(
|
||||
!routes.includes("routes/islands/test_test.tsx") &&
|
||||
!routes.includes("routes\\islands\\test_test.tsx"),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "routes collect with custom pattern",
|
||||
fn: async () => {
|
||||
const { routes } = await collect(
|
||||
join(
|
||||
dirname(fromFileUrl(import.meta.url)),
|
||||
"fixture_router_ignore_files",
|
||||
),
|
||||
/[\.|_]cy\.[t|j]s(x)?$/,
|
||||
);
|
||||
|
||||
assert(
|
||||
!routes.includes("routes/index.cy.ts") &&
|
||||
!routes.includes("routes\\index.cy.ts"),
|
||||
);
|
||||
assert(
|
||||
routes.includes("routes/index.tsx") ||
|
||||
routes.includes("routes\\index.tsx"),
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
import { STATUS_CODE } from "../server.ts";
|
||||
import {
|
||||
assertEquals,
|
||||
AssertionError,
|
||||
assertRejects,
|
||||
assertStringIncludes,
|
||||
} from "./deps.ts";
|
||||
import { getErrorOverlay, withFakeServe } from "./test_utils.ts";
|
||||
|
||||
Deno.test("error page rendered", async () => {
|
||||
await withFakeServe("./tests/fixture_error/dev.ts", async (server) => {
|
||||
const resp = await server.get("/");
|
||||
assertEquals(resp.status, STATUS_CODE.InternalServerError);
|
||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(body, "<p>500 page</p>");
|
||||
|
||||
const { title, stack } = await getErrorOverlay(server, "/");
|
||||
assertStringIncludes(title, `boom!`);
|
||||
assertStringIncludes(stack, `at render`);
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("error page rendered without error overlay", async () => {
|
||||
await withFakeServe("./tests/fixture_error/main.ts", async (server) => {
|
||||
const resp = await server.get("/");
|
||||
assertEquals(resp.status, STATUS_CODE.InternalServerError);
|
||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(body, "<p>500 page</p>");
|
||||
|
||||
await assertRejects(
|
||||
() => getErrorOverlay(server, "/"),
|
||||
AssertionError,
|
||||
undefined,
|
||||
"Missing fresh error overlay",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,93 +0,0 @@
|
||||
import {
|
||||
assertNotSelector,
|
||||
assertSelector,
|
||||
assertTextMany,
|
||||
withFakeServe,
|
||||
} from "./test_utils.ts";
|
||||
import { assertNotMatch } from "./deps.ts";
|
||||
|
||||
Deno.test("doesn't apply internal app template", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_explicit_app/main.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml(`/`);
|
||||
|
||||
// Doesn't render internal app template
|
||||
assertNotSelector(doc, "body body");
|
||||
|
||||
assertSelector(doc, "html > head");
|
||||
assertSelector(doc, "html > body");
|
||||
assertSelector(doc, `meta[charset="utf-8"]`);
|
||||
assertSelector(
|
||||
doc,
|
||||
`meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
|
||||
);
|
||||
assertTextMany(doc, "title", ["fresh title"]);
|
||||
|
||||
// Still renders page
|
||||
assertSelector(doc, "body > .inner-body > .page");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("user _app works with <Head>", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_explicit_app/main.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml(`/head`);
|
||||
|
||||
// Doesn't render internal app template
|
||||
assertNotSelector(doc, "body body");
|
||||
|
||||
assertSelector(doc, "html > head");
|
||||
assertSelector(doc, "html > body");
|
||||
assertSelector(doc, `meta[charset="utf-8"]`);
|
||||
assertSelector(
|
||||
doc,
|
||||
`meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
|
||||
);
|
||||
assertSelector(
|
||||
doc,
|
||||
`meta[name="fresh"][content="test"]`,
|
||||
);
|
||||
|
||||
// Still renders page
|
||||
assertSelector(doc, "body > .inner-body > .page");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("don't duplicate <title>", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_explicit_app/main.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml(`/title`);
|
||||
assertTextMany(doc, "title", ["foo bar"]);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("sets <html> + <head> + <body> classes", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_explicit_app/main.ts",
|
||||
async (server) => {
|
||||
const doc = await server.getHtml(``);
|
||||
assertSelector(doc, "html.html");
|
||||
assertSelector(doc, "head.head");
|
||||
assertSelector(doc, "body.body");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// Issue: https://github.com/denoland/fresh/issues/1666
|
||||
Deno.test("renders valid html document", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_explicit_app/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/");
|
||||
const text = await res.text();
|
||||
|
||||
assertNotMatch(text, /<\/body><\/head>/);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
dir
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.22.0",
|
||||
"preact/": "https://esm.sh/preact@10.22.0/",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.5",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.3.1"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -1,11 +0,0 @@
|
||||
import { FreshConfig } from "$fresh/server.ts";
|
||||
|
||||
export default {
|
||||
async render(_ctx, render) {
|
||||
await new Promise<void>((r) => r());
|
||||
const body = render();
|
||||
if (typeof body !== "string") {
|
||||
throw new Error("body is missing");
|
||||
}
|
||||
},
|
||||
} as FreshConfig;
|
||||
@@ -1,238 +0,0 @@
|
||||
// DO NOT EDIT. This file is generated by Fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $_404_from_middleware_throw_middleware from "./routes/404-from-middleware-throw/_middleware.ts";
|
||||
import * as $_404_from_middleware_throw_index from "./routes/404-from-middleware-throw/index.tsx";
|
||||
import * as $_404_from_middleware_middleware from "./routes/404-from-middleware/_middleware.ts";
|
||||
import * as $_404_from_middleware_index from "./routes/404-from-middleware/index.tsx";
|
||||
import * as $_404_from_throw from "./routes/404_from_throw.tsx";
|
||||
import * as $_name_ from "./routes/[name].tsx";
|
||||
import * as $_404 from "./routes/_404.tsx";
|
||||
import * as $_500 from "./routes/_500.tsx";
|
||||
import * as $_app from "./routes/_app.tsx";
|
||||
import * as $_middleware from "./routes/_middleware.ts";
|
||||
import * as $admin_site_ from "./routes/admin/[site].tsx";
|
||||
import * as $api_get_only from "./routes/api/get_only.ts";
|
||||
import * as $api_head_override from "./routes/api/head_override.ts";
|
||||
import * as $assetsCaching_index from "./routes/assetsCaching/index.tsx";
|
||||
import * as $books_id_ from "./routes/books/[id].tsx";
|
||||
import * as $connInfo from "./routes/connInfo.ts";
|
||||
import * as $ctx_config from "./routes/ctx_config.tsx";
|
||||
import * as $ctx_config_props from "./routes/ctx_config_props.tsx";
|
||||
import * as $error_boundary from "./routes/error_boundary.tsx";
|
||||
import * as $event_handler_string from "./routes/event_handler_string.tsx";
|
||||
import * as $event_handler_string_island from "./routes/event_handler_string_island.tsx";
|
||||
import * as $evil from "./routes/evil.tsx";
|
||||
import * as $failure from "./routes/failure.ts";
|
||||
import * as $foo_bar_baz from "./routes/foo.bar.baz.tsx";
|
||||
import * as $foo_bar from "./routes/foo.bar.tsx";
|
||||
import * as $head_deduplicate from "./routes/head_deduplicate.tsx";
|
||||
import * as $hooks_server_island from "./routes/hooks-server/island.tsx";
|
||||
import * as $hooks_server_useReducer from "./routes/hooks-server/useReducer.tsx";
|
||||
import * as $hooks_server_useState from "./routes/hooks-server/useState.tsx";
|
||||
import * as $i18n_lang_lang from "./routes/i18n/[[lang]]/lang.tsx";
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $intercept from "./routes/intercept.tsx";
|
||||
import * as $intercept_args from "./routes/intercept_args.tsx";
|
||||
import * as $island_json from "./routes/island_json.tsx";
|
||||
import * as $islands_index from "./routes/islands/index.tsx";
|
||||
import * as $islands_multiple_island_exports from "./routes/islands/multiple_island_exports.tsx";
|
||||
import * as $islands_returning_null from "./routes/islands/returning_null.tsx";
|
||||
import * as $islands_root_fragment from "./routes/islands/root_fragment.tsx";
|
||||
import * as $islands_root_fragment_conditional_first from "./routes/islands/root_fragment_conditional_first.tsx";
|
||||
import * as $layeredMdw_middleware from "./routes/layeredMdw/_middleware.ts";
|
||||
import * as $layeredMdw_layer2_no_mw_without_mw from "./routes/layeredMdw/layer2-no-mw/without_mw.ts";
|
||||
import * as $layeredMdw_layer2_with_params_tenantId_id_ from "./routes/layeredMdw/layer2-with-params/[tenantId]/[id].ts";
|
||||
import * as $layeredMdw_layer2_with_params_tenantId_middleware from "./routes/layeredMdw/layer2-with-params/[tenantId]/_middleware.ts";
|
||||
import * as $layeredMdw_layer2_with_params_middleware from "./routes/layeredMdw/layer2-with-params/_middleware.ts";
|
||||
import * as $layeredMdw_layer2_middleware from "./routes/layeredMdw/layer2/_middleware.ts";
|
||||
import * as $layeredMdw_layer2_abc from "./routes/layeredMdw/layer2/abc.ts";
|
||||
import * as $layeredMdw_layer2_index from "./routes/layeredMdw/layer2/index.ts";
|
||||
import * as $layeredMdw_layer2_layer3_id_ from "./routes/layeredMdw/layer2/layer3/[id].ts";
|
||||
import * as $layeredMdw_layer2_layer3_middleware from "./routes/layeredMdw/layer2/layer3/_middleware.ts";
|
||||
import * as $layeredMdw_nesting_tenant_environment_id_ from "./routes/layeredMdw/nesting/[tenant]/[environment]/[id].tsx";
|
||||
import * as $layeredMdw_nesting_tenant_environment_middleware from "./routes/layeredMdw/nesting/[tenant]/[environment]/_middleware.ts";
|
||||
import * as $layeredMdw_nesting_tenant_middleware from "./routes/layeredMdw/nesting/[tenant]/_middleware.ts";
|
||||
import * as $layeredMdw_nesting_middleware from "./routes/layeredMdw/nesting/_middleware.ts";
|
||||
import * as $middleware_error_handler_middleware from "./routes/middleware-error-handler/_middleware.ts";
|
||||
import * as $middleware_error_handler_index from "./routes/middleware-error-handler/index.tsx";
|
||||
import * as $middleware_root from "./routes/middleware_root.ts";
|
||||
import * as $movies_foo_json from "./routes/movies/[foo].json.ts";
|
||||
import * as $movies_foo_bar_ from "./routes/movies/[foo]@[bar].ts";
|
||||
import * as $nonce_inline from "./routes/nonce_inline.tsx";
|
||||
import * as $not_found from "./routes/not_found.ts";
|
||||
import * as $params from "./routes/params.tsx";
|
||||
import * as $preact_boolean_attrs from "./routes/preact/boolean_attrs.tsx";
|
||||
import * as $props_id_ from "./routes/props/[id].tsx";
|
||||
import * as $route_groups_islands_index from "./routes/route-groups-islands/index.tsx";
|
||||
import * as $route_groups_bar_baz_layout from "./routes/route-groups/(bar)/(baz)/_layout.tsx";
|
||||
import * as $route_groups_bar_baz_baz from "./routes/route-groups/(bar)/(baz)/baz.tsx";
|
||||
import * as $route_groups_bar_layout from "./routes/route-groups/(bar)/_layout.tsx";
|
||||
import * as $route_groups_bar_bar from "./routes/route-groups/(bar)/bar.tsx";
|
||||
import * as $route_groups_bar_boof_index from "./routes/route-groups/(bar)/boof/index.tsx";
|
||||
import * as $route_groups_foo_layout from "./routes/route-groups/(foo)/_layout.tsx";
|
||||
import * as $route_groups_foo_index from "./routes/route-groups/(foo)/index.tsx";
|
||||
import * as $signal_shared from "./routes/signal_shared.tsx";
|
||||
import * as $spoof_state from "./routes/spoof_state.tsx";
|
||||
import * as $state_in_props_middleware from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $state_in_props_index from "./routes/state-in-props/index.tsx";
|
||||
import * as $state_middleware_middleware from "./routes/state-middleware/_middleware.ts";
|
||||
import * as $state_middleware_foo_middleware from "./routes/state-middleware/foo/_middleware.ts";
|
||||
import * as $state_middleware_foo_index from "./routes/state-middleware/foo/index.tsx";
|
||||
import * as $static from "./routes/static.tsx";
|
||||
import * as $status_overwrite from "./routes/status_overwrite.tsx";
|
||||
import * as $std from "./routes/std.tsx";
|
||||
import * as $umlaut_äöüß from "./routes/umlaut-äöüß.tsx";
|
||||
import * as $wildcard from "./routes/wildcard.tsx";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import * as $DangerousIsland from "./islands/DangerousIsland.tsx";
|
||||
import * as $Foo_Bar from "./islands/Foo.Bar.tsx";
|
||||
import * as $FormIsland from "./islands/FormIsland.tsx";
|
||||
import * as $Greeter from "./islands/Greeter.tsx";
|
||||
import * as $HookIsland from "./islands/HookIsland.tsx";
|
||||
import * as $JsonIsland from "./islands/JsonIsland.tsx";
|
||||
import * as $MultipleCounters from "./islands/MultipleCounters.tsx";
|
||||
import * as $ReturningNull from "./islands/ReturningNull.tsx";
|
||||
import * as $RootFragment from "./islands/RootFragment.tsx";
|
||||
import * as $RootFragmentWithConditionalFirst from "./islands/RootFragmentWithConditionalFirst.tsx";
|
||||
import * as $StringEventIsland from "./islands/StringEventIsland.tsx";
|
||||
import * as $Test from "./islands/Test.tsx";
|
||||
import * as $folder_Counter from "./islands/folder/Counter.tsx";
|
||||
import * as $folder_subfolder_Counter from "./islands/folder/subfolder/Counter.tsx";
|
||||
import * as $kebab_case_counter_test from "./islands/kebab-case-counter-test.tsx";
|
||||
import * as $route_groups_islands_islands_Counter from "./routes/route-groups-islands/(_islands)/Counter.tsx";
|
||||
import * as $route_groups_islands_islands_invalid from "./routes/route-groups-islands/(_islands)/invalid.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/404-from-middleware-throw/_middleware.ts":
|
||||
$_404_from_middleware_throw_middleware,
|
||||
"./routes/404-from-middleware-throw/index.tsx":
|
||||
$_404_from_middleware_throw_index,
|
||||
"./routes/404-from-middleware/_middleware.ts":
|
||||
$_404_from_middleware_middleware,
|
||||
"./routes/404-from-middleware/index.tsx": $_404_from_middleware_index,
|
||||
"./routes/404_from_throw.tsx": $_404_from_throw,
|
||||
"./routes/[name].tsx": $_name_,
|
||||
"./routes/_404.tsx": $_404,
|
||||
"./routes/_500.tsx": $_500,
|
||||
"./routes/_app.tsx": $_app,
|
||||
"./routes/_middleware.ts": $_middleware,
|
||||
"./routes/admin/[site].tsx": $admin_site_,
|
||||
"./routes/api/get_only.ts": $api_get_only,
|
||||
"./routes/api/head_override.ts": $api_head_override,
|
||||
"./routes/assetsCaching/index.tsx": $assetsCaching_index,
|
||||
"./routes/books/[id].tsx": $books_id_,
|
||||
"./routes/connInfo.ts": $connInfo,
|
||||
"./routes/ctx_config.tsx": $ctx_config,
|
||||
"./routes/ctx_config_props.tsx": $ctx_config_props,
|
||||
"./routes/error_boundary.tsx": $error_boundary,
|
||||
"./routes/event_handler_string.tsx": $event_handler_string,
|
||||
"./routes/event_handler_string_island.tsx": $event_handler_string_island,
|
||||
"./routes/evil.tsx": $evil,
|
||||
"./routes/failure.ts": $failure,
|
||||
"./routes/foo.bar.baz.tsx": $foo_bar_baz,
|
||||
"./routes/foo.bar.tsx": $foo_bar,
|
||||
"./routes/head_deduplicate.tsx": $head_deduplicate,
|
||||
"./routes/hooks-server/island.tsx": $hooks_server_island,
|
||||
"./routes/hooks-server/useReducer.tsx": $hooks_server_useReducer,
|
||||
"./routes/hooks-server/useState.tsx": $hooks_server_useState,
|
||||
"./routes/i18n/[[lang]]/lang.tsx": $i18n_lang_lang,
|
||||
"./routes/index.tsx": $index,
|
||||
"./routes/intercept.tsx": $intercept,
|
||||
"./routes/intercept_args.tsx": $intercept_args,
|
||||
"./routes/island_json.tsx": $island_json,
|
||||
"./routes/islands/index.tsx": $islands_index,
|
||||
"./routes/islands/multiple_island_exports.tsx":
|
||||
$islands_multiple_island_exports,
|
||||
"./routes/islands/returning_null.tsx": $islands_returning_null,
|
||||
"./routes/islands/root_fragment.tsx": $islands_root_fragment,
|
||||
"./routes/islands/root_fragment_conditional_first.tsx":
|
||||
$islands_root_fragment_conditional_first,
|
||||
"./routes/layeredMdw/_middleware.ts": $layeredMdw_middleware,
|
||||
"./routes/layeredMdw/layer2-no-mw/without_mw.ts":
|
||||
$layeredMdw_layer2_no_mw_without_mw,
|
||||
"./routes/layeredMdw/layer2-with-params/[tenantId]/[id].ts":
|
||||
$layeredMdw_layer2_with_params_tenantId_id_,
|
||||
"./routes/layeredMdw/layer2-with-params/[tenantId]/_middleware.ts":
|
||||
$layeredMdw_layer2_with_params_tenantId_middleware,
|
||||
"./routes/layeredMdw/layer2-with-params/_middleware.ts":
|
||||
$layeredMdw_layer2_with_params_middleware,
|
||||
"./routes/layeredMdw/layer2/_middleware.ts": $layeredMdw_layer2_middleware,
|
||||
"./routes/layeredMdw/layer2/abc.ts": $layeredMdw_layer2_abc,
|
||||
"./routes/layeredMdw/layer2/index.ts": $layeredMdw_layer2_index,
|
||||
"./routes/layeredMdw/layer2/layer3/[id].ts": $layeredMdw_layer2_layer3_id_,
|
||||
"./routes/layeredMdw/layer2/layer3/_middleware.ts":
|
||||
$layeredMdw_layer2_layer3_middleware,
|
||||
"./routes/layeredMdw/nesting/[tenant]/[environment]/[id].tsx":
|
||||
$layeredMdw_nesting_tenant_environment_id_,
|
||||
"./routes/layeredMdw/nesting/[tenant]/[environment]/_middleware.ts":
|
||||
$layeredMdw_nesting_tenant_environment_middleware,
|
||||
"./routes/layeredMdw/nesting/[tenant]/_middleware.ts":
|
||||
$layeredMdw_nesting_tenant_middleware,
|
||||
"./routes/layeredMdw/nesting/_middleware.ts":
|
||||
$layeredMdw_nesting_middleware,
|
||||
"./routes/middleware-error-handler/_middleware.ts":
|
||||
$middleware_error_handler_middleware,
|
||||
"./routes/middleware-error-handler/index.tsx":
|
||||
$middleware_error_handler_index,
|
||||
"./routes/middleware_root.ts": $middleware_root,
|
||||
"./routes/movies/[foo].json.ts": $movies_foo_json,
|
||||
"./routes/movies/[foo]@[bar].ts": $movies_foo_bar_,
|
||||
"./routes/nonce_inline.tsx": $nonce_inline,
|
||||
"./routes/not_found.ts": $not_found,
|
||||
"./routes/params.tsx": $params,
|
||||
"./routes/preact/boolean_attrs.tsx": $preact_boolean_attrs,
|
||||
"./routes/props/[id].tsx": $props_id_,
|
||||
"./routes/route-groups-islands/index.tsx": $route_groups_islands_index,
|
||||
"./routes/route-groups/(bar)/(baz)/_layout.tsx":
|
||||
$route_groups_bar_baz_layout,
|
||||
"./routes/route-groups/(bar)/(baz)/baz.tsx": $route_groups_bar_baz_baz,
|
||||
"./routes/route-groups/(bar)/_layout.tsx": $route_groups_bar_layout,
|
||||
"./routes/route-groups/(bar)/bar.tsx": $route_groups_bar_bar,
|
||||
"./routes/route-groups/(bar)/boof/index.tsx": $route_groups_bar_boof_index,
|
||||
"./routes/route-groups/(foo)/_layout.tsx": $route_groups_foo_layout,
|
||||
"./routes/route-groups/(foo)/index.tsx": $route_groups_foo_index,
|
||||
"./routes/signal_shared.tsx": $signal_shared,
|
||||
"./routes/spoof_state.tsx": $spoof_state,
|
||||
"./routes/state-in-props/_middleware.ts": $state_in_props_middleware,
|
||||
"./routes/state-in-props/index.tsx": $state_in_props_index,
|
||||
"./routes/state-middleware/_middleware.ts": $state_middleware_middleware,
|
||||
"./routes/state-middleware/foo/_middleware.ts":
|
||||
$state_middleware_foo_middleware,
|
||||
"./routes/state-middleware/foo/index.tsx": $state_middleware_foo_index,
|
||||
"./routes/static.tsx": $static,
|
||||
"./routes/status_overwrite.tsx": $status_overwrite,
|
||||
"./routes/std.tsx": $std,
|
||||
"./routes/umlaut-äöüß.tsx": $umlaut_äöüß,
|
||||
"./routes/wildcard.tsx": $wildcard,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
"./islands/DangerousIsland.tsx": $DangerousIsland,
|
||||
"./islands/Foo.Bar.tsx": $Foo_Bar,
|
||||
"./islands/FormIsland.tsx": $FormIsland,
|
||||
"./islands/Greeter.tsx": $Greeter,
|
||||
"./islands/HookIsland.tsx": $HookIsland,
|
||||
"./islands/JsonIsland.tsx": $JsonIsland,
|
||||
"./islands/MultipleCounters.tsx": $MultipleCounters,
|
||||
"./islands/ReturningNull.tsx": $ReturningNull,
|
||||
"./islands/RootFragment.tsx": $RootFragment,
|
||||
"./islands/RootFragmentWithConditionalFirst.tsx":
|
||||
$RootFragmentWithConditionalFirst,
|
||||
"./islands/StringEventIsland.tsx": $StringEventIsland,
|
||||
"./islands/Test.tsx": $Test,
|
||||
"./islands/folder/Counter.tsx": $folder_Counter,
|
||||
"./islands/folder/subfolder/Counter.tsx": $folder_subfolder_Counter,
|
||||
"./islands/kebab-case-counter-test.tsx": $kebab_case_counter_test,
|
||||
"./routes/route-groups-islands/(_islands)/Counter.tsx":
|
||||
$route_groups_islands_islands_Counter,
|
||||
"./routes/route-groups-islands/(_islands)/invalid.tsx":
|
||||
$route_groups_islands_islands_invalid,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
export default manifest;
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface CounterProps {
|
||||
count: Signal<number>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
return (
|
||||
<div id={props.id}>
|
||||
<p>{props.count}</p>
|
||||
<button
|
||||
id={`b-${props.id}`}
|
||||
onClick={() => props.count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export default function RawIsland(props: { raw: string }) {
|
||||
const [css, set] = useState("");
|
||||
useEffect(() => {
|
||||
set("raw_ready");
|
||||
}, []);
|
||||
|
||||
return <div class={css} dangerouslySetInnerHTML={{ __html: props.raw }} />;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export default function FooBar() {
|
||||
const [css, setCss] = useState("");
|
||||
useEffect(() => {
|
||||
setCss("ready");
|
||||
}, []);
|
||||
return <h1 class={css}>FooBar island</h1>;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
import { ComponentChildren } from "preact";
|
||||
|
||||
export function FormIsland({ children }: { children: ComponentChildren }) {
|
||||
const ref = useRef<HTMLParagraphElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
ref.current.textContent = "Revived: true";
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<form onSubmit={(e) => e.preventDefault()}>
|
||||
<p class="form-revived" ref={ref}>Revived: false</p>
|
||||
{children}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function Greeter(props: { site: string }) {
|
||||
return <h1>{props.site}</h1>;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
export function HookIsland() {
|
||||
const [v, set] = useState(0);
|
||||
return (
|
||||
<div>
|
||||
<p>{v}</p>
|
||||
<button onClick={() => set((v) => v + 1)}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import json from "./data.json" with { type: "json" };
|
||||
|
||||
export default function JsonIsland() {
|
||||
return <pre>{JSON.stringify(json,null, 2)}</pre>;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import type { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface CounterProps {
|
||||
count: Signal<number>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const thisShouldNotCauseProblems = 42;
|
||||
|
||||
export default function CounterZero(props: CounterProps) {
|
||||
return (
|
||||
<div id={props.id}>
|
||||
<p>{props.count}</p>
|
||||
<button
|
||||
id={`b-${props.id}`}
|
||||
onClick={() => props.count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CounterOne(props: CounterProps) {
|
||||
return CounterZero(props);
|
||||
}
|
||||
|
||||
export function CounterTwo(props: CounterProps) {
|
||||
return CounterZero(props);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export default function ReturningNull() {
|
||||
useEffect(() => {
|
||||
const p = document.createElement("p");
|
||||
p.textContent = "Hello, null!";
|
||||
p.className = "added-by-use-effect";
|
||||
|
||||
document.body.appendChild(p);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export default function RootFragment() {
|
||||
const shown = useSignal(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
Hello
|
||||
<div onClick={() => shown.value = true} id="root-fragment-click-me">
|
||||
World
|
||||
</div>
|
||||
{shown.value && <div>I'm rendered now</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export default function RootFragmentWithConditionalFirst() {
|
||||
const shown = useSignal(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
{shown.value && <div>I'm rendered on top</div>}
|
||||
Hello
|
||||
<div
|
||||
onClick={() => shown.value = true}
|
||||
id="root-fragment-conditional-first-click-me"
|
||||
>
|
||||
World
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export default function StringEventIsland() {
|
||||
return (
|
||||
<button // @ts-ignore - we don't officially recommend this, but lots of
|
||||
// apps pre Fresh 1.2 use string based click handlers.
|
||||
onClick="document.querySelector('p').textContent = 'it works'">
|
||||
click me
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
export default function Test(props: { message: string }) {
|
||||
return (
|
||||
<div>
|
||||
<p>{props.message}</p>
|
||||
<img
|
||||
id="img-in-island"
|
||||
src="/image.png"
|
||||
srcset="/image.png 1x"
|
||||
height={130}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"foo": "it works"
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface CounterProps {
|
||||
count: Signal<number>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
return (
|
||||
<div id={props.id}>
|
||||
<p>{props.count}</p>
|
||||
<button
|
||||
id={`b-${props.id}`}
|
||||
onClick={() => props.count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface CounterProps {
|
||||
count: Signal<number>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
return (
|
||||
<div id={props.id}>
|
||||
<p>{props.count}</p>
|
||||
<button
|
||||
id={`b-${props.id}`}
|
||||
onClick={() => props.count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import type { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface KebabCaseFileNameTestProps {
|
||||
count: Signal<number>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default function KebabCaseFileNameTest(
|
||||
props: KebabCaseFileNameTestProps,
|
||||
) {
|
||||
return (
|
||||
<div id={props.id}>
|
||||
<p>{props.count}</p>
|
||||
<button
|
||||
id={`b-${props.id}`}
|
||||
onClick={() => props.count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await start(manifest, config);
|
||||
@@ -1,12 +0,0 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
// this just exists to function as a type check to assert that we can actually pass a key and cert in
|
||||
await start(manifest, { ...config, key: "test", cert: "test" });
|
||||
@@ -1,14 +0,0 @@
|
||||
// Simulate Deno Deploy environment
|
||||
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import "./polyfill_deno_deploy.ts";
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await start(manifest, config);
|
||||
@@ -1,5 +0,0 @@
|
||||
// Simulate Deno Deploy environment
|
||||
|
||||
//@ts-ignore: Remove Deno.run for simulating deno deploy env
|
||||
// deno-lint-ignore no-deprecated-deno-api
|
||||
delete Deno.run;
|
||||
@@ -1,10 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
// handlers are supposed to return something, so in order to make type checker on the manifest happy, we'll use any to escape it
|
||||
export function handler(
|
||||
_req: Request,
|
||||
_ctx: FreshContext,
|
||||
// deno-lint-ignore no-explicit-any
|
||||
): any {
|
||||
throw new Deno.errors.NotFound();
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { defineRoute } from "$fresh/server.ts";
|
||||
|
||||
export default defineRoute((req, ctx) => {
|
||||
return "This never gets shown, because the middleware throws an error.";
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
return await ctx.renderNotFound();
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { defineRoute } from "$fresh/server.ts";
|
||||
|
||||
export default defineRoute((req, ctx) => {
|
||||
return "This never gets shown, because the middleware calls ctx.renderNotFound.";
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(_req, _ctx) {
|
||||
throw new Deno.errors.NotFound();
|
||||
},
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
interface Props {
|
||||
params: Record<string, string | string[]>;
|
||||
}
|
||||
|
||||
export default function Greet(props: Props) {
|
||||
return <div>Hello {props.params.name}</div>;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
|
||||
type Data = { hello: string };
|
||||
type State = { root: string };
|
||||
|
||||
export default function NotFoundPage(
|
||||
{ data, state, url }: PageProps<Data | undefined, State>,
|
||||
) {
|
||||
// Checks that we have the correct type for state
|
||||
state.root satisfies string;
|
||||
|
||||
return (
|
||||
<>
|
||||
<p>404 not found: {url.pathname}</p>
|
||||
{data?.hello && <p>Hello {data.hello}</p>}
|
||||
<p>State root: {state.root}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
|
||||
export default function Error500Page({ error }: PageProps) {
|
||||
return <p>500 internal error: {(error as Error).message}</p>;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
|
||||
export type TestState = {
|
||||
root: string;
|
||||
stateInProps: string;
|
||||
};
|
||||
|
||||
export default function App(props: PageProps<unknown, TestState>) {
|
||||
const statefulValue = props.state?.root === "root_mw"
|
||||
? "The freshest framework!"
|
||||
: "";
|
||||
const specialCase = props.state?.stateInProps;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta name="description" content="Hello world!" />
|
||||
<meta name="generator" content={statefulValue} />
|
||||
{specialCase && <meta name="specialTag" content={specialCase} />}
|
||||
</Head>
|
||||
<props.Component />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import { FreshContext, MiddlewareHandler } from "$fresh/server.ts";
|
||||
|
||||
// cors middleware
|
||||
async function corsHandler(req: Request, ctx: FreshContext) {
|
||||
if (req.method == "OPTIONS") {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
});
|
||||
}
|
||||
const origin = req.headers.get("Origin") || "*";
|
||||
const resp = await ctx.next();
|
||||
const headers = resp.headers;
|
||||
|
||||
headers.set("Access-Control-Allow-Origin", origin);
|
||||
headers.set("Access-Control-Allow-Credentials", "true");
|
||||
headers.set(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With",
|
||||
);
|
||||
headers.set(
|
||||
"Access-Control-Allow-Methods",
|
||||
"POST, OPTIONS, GET, PUT, DELETE",
|
||||
);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
// log middleware
|
||||
async function logHandler(_req: Request, ctx: FreshContext) {
|
||||
const since = new Date();
|
||||
const resp = await ctx.next();
|
||||
const latency = (+new Date()) - (+since);
|
||||
resp.headers.set("latency", `${latency}`);
|
||||
return resp;
|
||||
}
|
||||
|
||||
async function rootHandler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.root = "root_mw";
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("server", "fresh test server");
|
||||
return resp;
|
||||
}
|
||||
|
||||
async function kindHandler(_req: Request, ctx: FreshContext) {
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("destination", ctx.destination);
|
||||
return resp;
|
||||
}
|
||||
|
||||
export const handler: MiddlewareHandler | MiddlewareHandler[] = [
|
||||
rootHandler,
|
||||
logHandler,
|
||||
kindHandler,
|
||||
corsHandler,
|
||||
];
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Handler, PageProps } from "$fresh/server.ts";
|
||||
import Greeter from "../../islands/Greeter.tsx";
|
||||
|
||||
export const handler: Handler = (_req, ctx) =>
|
||||
ctx.render({ site: ctx.params.site });
|
||||
|
||||
export default function Component(props: PageProps<{ site: string }>) {
|
||||
return <Greeter site={props.data?.site ?? "not working"} />;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export const handler = {
|
||||
GET() {
|
||||
return new Response("Get fresh!", {
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
});
|
||||
},
|
||||
NOTAMETHOD() {
|
||||
throw new Error("unreachable");
|
||||
},
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
export const handler = {
|
||||
HEAD() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: {
|
||||
"Content-Type": "text/html; charset=utf-8",
|
||||
},
|
||||
});
|
||||
},
|
||||
GET() {
|
||||
return new Response("Get fresh!", {
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
import Test from "../../islands/Test.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<div style={{ marginTop: 20 }}>img-with-hashing</div>
|
||||
<img id="img-with-hashing" src="/image.png" height={130} />
|
||||
|
||||
<div style={{ marginTop: 20 }}>img-without-hashing</div>
|
||||
<img
|
||||
id="img-without-hashing"
|
||||
src="/image.png"
|
||||
data-fresh-disable-lock
|
||||
height={130}
|
||||
/>
|
||||
|
||||
<Test message="In island" />
|
||||
|
||||
<div style={{ marginTop: 20 }}>img-external</div>
|
||||
<img
|
||||
id="img-missing"
|
||||
src="https://fresh.deno.dev/favicon.ico"
|
||||
height={130}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { PageProps, RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export default function Page(props: PageProps) {
|
||||
return <div>Book {props.params.id}</div>;
|
||||
}
|
||||
|
||||
export const config: RouteConfig = {
|
||||
routeOverride: "/books/:id(\\d+)",
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(_req, ctx) {
|
||||
return new Response((ctx.remoteAddr as Deno.NetAddr).hostname);
|
||||
},
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
import { defineRoute } from "$fresh/server.ts";
|
||||
import { relative, SEPARATOR } from "$fresh/tests/deps.ts";
|
||||
|
||||
export default defineRoute((_req, ctx) => {
|
||||
const value = JSON.stringify(ctx, (key, value) => {
|
||||
if (key === "outDir" || key == "staticDir") {
|
||||
return relative(Deno.cwd(), value).split(SEPARATOR).join("/");
|
||||
}
|
||||
if (typeof value === "function") return value.constructor.name;
|
||||
if (value === undefined) return "<undefined>";
|
||||
return value;
|
||||
}, 2);
|
||||
|
||||
return (
|
||||
<pre>
|
||||
{value}
|
||||
</pre>
|
||||
);
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
import { relative, SEPARATOR } from "../../deps.ts";
|
||||
|
||||
export default function Page(props: PageProps) {
|
||||
const value = JSON.stringify(props, (key, value) => {
|
||||
if (key === "outDir" || key == "staticDir") {
|
||||
return relative(Deno.cwd(), value).split(SEPARATOR).join("/");
|
||||
}
|
||||
if (typeof value === "function") return value.constructor.name;
|
||||
if (value === undefined) return "<undefined>";
|
||||
return value;
|
||||
}, 2);
|
||||
|
||||
return <pre>{value}</pre>;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Component } from "preact";
|
||||
|
||||
class ErrorBoundary extends Component {
|
||||
state = { error: null } as { error: Error | null };
|
||||
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return { error };
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.error
|
||||
? <p>{this.state.error.message}</p>
|
||||
: <>{this.props.children}</>;
|
||||
}
|
||||
}
|
||||
|
||||
function Thrower(): preact.JSX.Element {
|
||||
throw new Error("it works");
|
||||
}
|
||||
|
||||
export default function ErrorBoundaryPage() {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<Thrower />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export default function Page() {
|
||||
return (
|
||||
<div>
|
||||
<p>it doesn't work</p>
|
||||
<button // @ts-ignore - we don't officially recommend this, but lots of
|
||||
// apps pre Fresh 1.2 use string based click handlers.
|
||||
onClick="document.querySelector('p').textContent = 'it works'">
|
||||
click me
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import StringEventIsland from "$fresh/tests/fixture/islands/StringEventIsland.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<div>
|
||||
<p>it doesn't work</p>
|
||||
<StringEventIsland />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import Test from "../islands/Test.tsx";
|
||||
|
||||
export default function EvilPage() {
|
||||
return (
|
||||
<div>
|
||||
<Test message={`</script><script>alert('test')</script>`} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export const handler = {
|
||||
GET() {
|
||||
throw Error("it errored!");
|
||||
},
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function Page() {
|
||||
return <p>it works</p>;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import FooBar from "../islands/Foo.Bar.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return <FooBar />;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<>
|
||||
<h1>Card head css deduplication</h1>
|
||||
<Head>
|
||||
<title>foo</title>
|
||||
<link rel="stylesheet" href="/card.css" key="card.css" />
|
||||
<meta property="og:title" content="My page title" key="title" />
|
||||
</Head>
|
||||
<Head>
|
||||
<title>bar</title>
|
||||
<link rel="stylesheet" href="/card.css" key="card.css" />
|
||||
<meta property="og:title" content="Other title" key="title" />
|
||||
</Head>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { HookIsland } from "../../islands/HookIsland.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return <HookIsland />;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { useReducer } from "preact/hooks";
|
||||
|
||||
export default function Page() {
|
||||
useReducer(() => {}, undefined);
|
||||
return <h1>useReducer</h1>;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
export default function Page() {
|
||||
useState();
|
||||
return <h1>useState</h1>;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
interface Props {
|
||||
params: Record<string, string | string[]>;
|
||||
}
|
||||
|
||||
export default function Lang(props: Props) {
|
||||
return props.params.lang
|
||||
? <div>Hello {props.params.lang}</div>
|
||||
: <div>Hello</div>;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
import Test from "../islands/Test.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<Test message="Hello!" />
|
||||
<p>{IS_BROWSER ? "Viewing browser render." : "Viewing JIT render."}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export default function Page() {
|
||||
return <div>This is HTML</div>;
|
||||
}
|
||||
|
||||
export const handler = {
|
||||
GET(req: Request, { render }: FreshContext) {
|
||||
if (req.headers.get("accept")?.includes("text/html")) {
|
||||
return render();
|
||||
} else {
|
||||
return new Response("This is plain text");
|
||||
}
|
||||
},
|
||||
POST() {
|
||||
return new Response("POST response");
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
interface Data extends Record<string, unknown> {
|
||||
info: string;
|
||||
}
|
||||
|
||||
export default function Page({ data }: PageProps<Data>) {
|
||||
return <div>{data.info}</div>;
|
||||
}
|
||||
|
||||
export const handler: Handlers<Data> = {
|
||||
GET(req, { render }) {
|
||||
if (req.headers.get("accept")?.includes("text/html")) {
|
||||
return render({
|
||||
info: "intercepted",
|
||||
});
|
||||
} else {
|
||||
return new Response("This is plain text");
|
||||
}
|
||||
},
|
||||
POST() {
|
||||
return new Response("POST response");
|
||||
},
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import JsonIsland from "../islands/JsonIsland.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return <JsonIsland />;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Counter from "../../islands/Counter.tsx";
|
||||
import FolderCounter from "../../islands/folder/Counter.tsx";
|
||||
import SubfolderCounter from "../../islands/folder/subfolder/Counter.tsx";
|
||||
import KebabCaseFileNameTest from "../../islands/kebab-case-counter-test.tsx";
|
||||
import Test from "../../islands/Test.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<Counter id="counter1" count={useSignal(3)} />
|
||||
<Counter id="counter2" count={useSignal(10)} />
|
||||
<FolderCounter id="folder-counter" count={useSignal(3)} />
|
||||
<SubfolderCounter id="subfolder-counter" count={useSignal(3)} />
|
||||
<KebabCaseFileNameTest
|
||||
id="kebab-case-file-counter"
|
||||
count={useSignal(5)}
|
||||
/>
|
||||
<Test message="" />
|
||||
<Test message={`</script><script>alert('test')</script>`} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import CounterZero from "../../islands/MultipleCounters.tsx";
|
||||
import { CounterOne, CounterTwo } from "../../islands/MultipleCounters.tsx";
|
||||
import SubfolderCounter from "../../islands/folder/subfolder/Counter.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<CounterZero id="counter0" count={useSignal(4)} />
|
||||
<CounterOne id="counter1" count={useSignal(3)} />
|
||||
<CounterTwo id="counter2" count={useSignal(10)} />
|
||||
<SubfolderCounter id="counter3" count={useSignal(4)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import ReturningNull from "$fresh/tests/fixture/islands/ReturningNull.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return <ReturningNull />;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import RootFragment from "../../islands/RootFragment.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="island-parent">
|
||||
<RootFragment />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import RootFragmentWithConditionalFirst from "../../islands/RootFragmentWithConditionalFirst.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="island-parent">
|
||||
<RootFragmentWithConditionalFirst />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.layer1 = "layer1_mw";
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("server", "fresh test server layer1");
|
||||
return resp;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
layer1: string;
|
||||
layer3: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers<undefined> = {
|
||||
GET(_req: Request, _ctx) {
|
||||
return new Response(JSON.stringify({}));
|
||||
},
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("middlewareParams_inner", JSON.stringify(ctx.params));
|
||||
return resp;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("middlewareParams_outer", JSON.stringify(ctx.params));
|
||||
return resp;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
layer1: string;
|
||||
layer2: string;
|
||||
}
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: FreshContext<State>,
|
||||
) {
|
||||
ctx.state.layer2 = "layer2_mw";
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
layer1: string;
|
||||
layer2: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
layer1: string;
|
||||
layer2: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Handlers } from "../../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
layer1: string;
|
||||
layer2: string;
|
||||
layer3: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.layer3 = "layer3_mw";
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("server", "fresh test server layer3");
|
||||
resp.headers.set("layer3", "fresh test server layer3");
|
||||
return resp;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_req: Request, ctx) {
|
||||
const order = ctx.state.middlewareNestingOrder as string;
|
||||
const resp = await ctx.render(order + "4");
|
||||
return resp;
|
||||
},
|
||||
};
|
||||
|
||||
export default function Page(props: PageProps) {
|
||||
return <div>{props.data}</div>;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.middlewareNestingOrder += "3";
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.middlewareNestingOrder += "2";
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(_req: Request, ctx: FreshContext) {
|
||||
ctx.state.middlewareNestingOrder = "1";
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: FreshContext,
|
||||
) {
|
||||
try {
|
||||
ctx.state.flag = true;
|
||||
return await ctx.next();
|
||||
} catch (error) {
|
||||
console.log("we're very thoroughly dealing with this error here: " + error);
|
||||
throw Error("don't show the full error for security purposes");
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, ctx) {
|
||||
return ctx.render(ctx.state.flag);
|
||||
},
|
||||
};
|
||||
|
||||
export default function Home(props: PageProps<boolean>) {
|
||||
if (props.data) {
|
||||
throw Error("i'm erroring on purpose");
|
||||
}
|
||||
return <div>this won't get shown</div>;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
import { Handler } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handler = () => new Response("it works");
|
||||
@@ -1,3 +0,0 @@
|
||||
import { Handler } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handler = () => new Response("it works");
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
|
||||
export default function Page() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div>
|
||||
<script
|
||||
id="inline-script"
|
||||
dangerouslySetInnerHTML={{ __html: "console.log('hey')" }}
|
||||
/>
|
||||
<Counter id="foo" count={sig} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
Deno.test("not really", () => {
|
||||
return;
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(_req, ctx) {
|
||||
return ctx.renderNotFound({
|
||||
hello: "Dino",
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
import { FreshContext, RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const handler = {
|
||||
GET(_req: Request, { params }: FreshContext) {
|
||||
return new Response(params.path);
|
||||
},
|
||||
};
|
||||
|
||||
export const config: RouteConfig = {
|
||||
routeOverride: "/params/:path*",
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user