chore: bump std to 208 and deal with deprecations (#2081)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Reed von Redwitz
2023-11-28 16:35:26 +00:00
committed by GitHub
co-authored by Marvin Hagemeister
parent 6a90fdbf1b
commit b902205feb
20 changed files with 137 additions and 131 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.5.0", "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.5.0",
"@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3", "@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3",
"@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0", "@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0",
"$std/": "https://deno.land/std@0.205.0/", "$std/": "https://deno.land/std@0.208.0/",
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts", "$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts",
"$marked-mangle": "https://esm.sh/marked-mangle@1.0.1", "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1",
"$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.11.1/mod.ts", "$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.11.1/mod.ts",
+3 -3
View File
@@ -4,7 +4,7 @@ export {
join, join,
relative, relative,
toFileUrl, toFileUrl,
} from "https://deno.land/std@0.205.0/path/mod.ts"; } from "https://deno.land/std@0.208.0/path/mod.ts";
export { escape as regexpEscape } from "https://deno.land/std@0.205.0/regexp/escape.ts"; export { escape as regexpEscape } from "https://deno.land/std@0.208.0/regexp/escape.ts";
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.2/mod.ts"; export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.2/mod.ts";
export { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts"; export { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
+10 -10
View File
@@ -9,24 +9,24 @@ export {
resolve, resolve,
SEP, SEP,
toFileUrl, toFileUrl,
} from "https://deno.land/std@0.205.0/path/mod.ts"; } from "https://deno.land/std@0.208.0/path/mod.ts";
export { normalize } from "https://deno.land/std@0.205.0/path/posix/mod.ts"; export { normalize } from "https://deno.land/std@0.208.0/path/posix/mod.ts";
export { DAY, WEEK } from "https://deno.land/std@0.205.0/datetime/constants.ts"; export { DAY, WEEK } from "https://deno.land/std@0.208.0/datetime/constants.ts";
export * as colors from "https://deno.land/std@0.205.0/fmt/colors.ts"; export * as colors from "https://deno.land/std@0.208.0/fmt/colors.ts";
export { export {
walk, walk,
type WalkEntry, type WalkEntry,
WalkError, WalkError,
} from "https://deno.land/std@0.205.0/fs/walk.ts"; } from "https://deno.land/std@0.208.0/fs/walk.ts";
export { parse } from "https://deno.land/std@0.205.0/flags/mod.ts"; export { parse } from "https://deno.land/std@0.208.0/flags/mod.ts";
export { export {
gte, gte,
lt, lt,
parse as semverParse, parse as semverParse,
} from "https://deno.land/std@0.205.0/semver/mod.ts"; } from "https://deno.land/std@0.208.0/semver/mod.ts";
export { emptyDir, existsSync } from "https://deno.land/std@0.205.0/fs/mod.ts"; export { emptyDir, existsSync } from "https://deno.land/std@0.208.0/fs/mod.ts";
export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; export * as JSONC from "https://deno.land/std@0.208.0/jsonc/mod.ts";
export { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts"; export { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
// ts-morph // ts-morph
export { Node, Project } from "https://deno.land/x/ts_morph@20.0.0/mod.ts"; export { Node, Project } from "https://deno.land/x/ts_morph@20.0.0/mod.ts";
+1 -1
View File
@@ -2,7 +2,7 @@ export const RECOMMENDED_PREACT_VERSION = "10.19.2";
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.2.1"; export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.2.1";
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.5.0"; export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.5.0";
export const RECOMMENDED_TWIND_VERSION = "0.16.19"; export const RECOMMENDED_TWIND_VERSION = "0.16.19";
export const RECOMMENDED_STD_VERSION = "0.205.0"; export const RECOMMENDED_STD_VERSION = "0.208.0";
export const RECOMMENDED_TAILIWIND_VERSION = "3.3.5"; export const RECOMMENDED_TAILIWIND_VERSION = "3.3.5";
export function freshImports(imports: Record<string, string>) { export function freshImports(imports: Record<string, string>) {
+1 -2
View File
@@ -1,6 +1,5 @@
import { assertSnapshot } from "$std/testing/snapshot.ts";
import { createCodeFrame, getFirstUserFile } from "./code_frame.ts"; import { createCodeFrame, getFirstUserFile } from "./code_frame.ts";
import { assertEquals, colors } from "./deps.ts"; import { assertEquals, assertSnapshot, colors } from "./deps.ts";
function testCodeFrame(text: string, line: number, column: number) { function testCodeFrame(text: string, line: number, column: number) {
const codeFrame = createCodeFrame(text, line, column); const codeFrame = createCodeFrame(text, line, column);
+9 -9
View File
@@ -1,4 +1,4 @@
import { extname, Status, typeByExtension } from "./deps.ts"; import { contentType, extname, STATUS_CODE } from "./deps.ts";
import * as router from "./router.ts"; import * as router from "./router.ts";
import { FreshConfig, Manifest, UnknownHandlerContext } from "./mod.ts"; import { FreshConfig, Manifest, UnknownHandlerContext } from "./mod.ts";
import { ALIVE_URL, DEV_CLIENT_URL, JS_PREFIX } from "./constants.ts"; import { ALIVE_URL, DEV_CLIENT_URL, JS_PREFIX } from "./constants.ts";
@@ -220,7 +220,7 @@ export class ServerContext {
const path = url.pathname.replace(/\/+$/, ""); const path = url.pathname.replace(/\/+$/, "");
const location = `${path}${url.search}`; const location = `${path}${url.search}`;
return new Response(null, { return new Response(null, {
status: Status.TemporaryRedirect, status: STATUS_CODE.TemporaryRedirect,
headers: { location }, headers: { location },
}); });
} else if (trailingSlashEnabled && !url.pathname.endsWith("/")) { } else if (trailingSlashEnabled && !url.pathname.endsWith("/")) {
@@ -232,7 +232,7 @@ export class ServerContext {
if (!isFile && !isInternal) { if (!isFile && !isInternal) {
url.pathname += "/"; url.pathname += "/";
return Response.redirect(url, Status.PermanentRedirect); return Response.redirect(url, STATUS_CODE.PermanentRedirect);
} }
} }
@@ -390,7 +390,7 @@ export class ServerContext {
) { ) {
route.pattern += "/"; route.pattern += "/";
} }
const createRender = genRender(route, Status.OK); const createRender = genRender(route, STATUS_CODE.OK);
if (typeof route.handler === "function") { if (typeof route.handler === "function") {
routes[route.pattern] = { routes[route.pattern] = {
baseRoute: route.baseRoute, baseRoute: route.baseRoute,
@@ -445,7 +445,7 @@ export class ServerContext {
const errorHandlerRender = genRender( const errorHandlerRender = genRender(
this.#extractResult.error, this.#extractResult.error,
Status.InternalServerError, STATUS_CODE.InternalServerError,
); );
const errorHandler: router.ErrorHandler<RouterState> = async ( const errorHandler: router.ErrorHandler<RouterState> = async (
req, req,
@@ -595,8 +595,8 @@ export class ServerContext {
: "public, max-age=604800, immutable", : "public, max-age=604800, immutable",
}; };
const contentType = typeByExtension(extname(params.path)); const type = contentType(extname(params.path));
if (contentType) headers["Content-Type"] = contentType; if (type) headers["Content-Type"] = type;
return new Response(contents, { return new Response(contents, {
status: 200, status: 200,
@@ -625,7 +625,7 @@ const createRenderNotFound = (
const notFound = extractResult.notFound; const notFound = extractResult.notFound;
if (!notFound.component) { if (!notFound.component) {
return sendResponse(["Not found.", undefined], { return sendResponse(["Not found.", undefined], {
status: Status.NotFound, status: STATUS_CODE.NotFound,
isDev: dev, isDev: dev,
statusText: undefined, statusText: undefined,
headers: undefined, headers: undefined,
@@ -660,7 +660,7 @@ const createRenderNotFound = (
} }
return sendResponse(resp, { return sendResponse(resp, {
status: Status.NotFound, status: STATUS_CODE.NotFound,
isDev: dev, isDev: dev,
statusText: undefined, statusText: undefined,
headers: undefined, headers: undefined,
+12 -11
View File
@@ -7,22 +7,23 @@ export {
isAbsolute, isAbsolute,
join, join,
toFileUrl, toFileUrl,
} from "https://deno.land/std@0.205.0/path/mod.ts"; } from "https://deno.land/std@0.208.0/path/mod.ts";
export { walk } from "https://deno.land/std@0.205.0/fs/walk.ts"; export { walk } from "https://deno.land/std@0.208.0/fs/walk.ts";
export * as colors from "https://deno.land/std@0.205.0/fmt/colors.ts"; export * as colors from "https://deno.land/std@0.208.0/fmt/colors.ts";
export { export {
type Handler as ServeHandler, type Handler as ServeHandler,
serve, serve,
} from "https://deno.land/std@0.205.0/http/server.ts"; } from "https://deno.land/std@0.208.0/http/server.ts";
export { Status } from "https://deno.land/std@0.205.0/http/http_status.ts"; export { STATUS_CODE } from "https://deno.land/std@0.208.0/http/status.ts";
export { export {
typeByExtension, contentType,
} from "https://deno.land/std@0.205.0/media_types/mod.ts"; } from "https://deno.land/std@0.208.0/media_types/content_type.ts";
export { toHashString } from "https://deno.land/std@0.205.0/crypto/to_hash_string.ts"; export { toHashString } from "https://deno.land/std@0.208.0/crypto/to_hash_string.ts";
export { escape } from "https://deno.land/std@0.205.0/regexp/escape.ts"; export { escape } from "https://deno.land/std@0.208.0/regexp/escape.ts";
export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; export * as JSONC from "https://deno.land/std@0.208.0/jsonc/mod.ts";
export { renderToString } from "https://esm.sh/*preact-render-to-string@6.3.1"; export { renderToString } from "https://esm.sh/*preact-render-to-string@6.3.1";
export { export {
assertEquals, assertEquals,
assertThrows, assertThrows,
} from "https://deno.land/std@0.205.0/assert/mod.ts"; } from "https://deno.land/std@0.208.0/assert/mod.ts";
export { assertSnapshot } from "https://deno.land/std@0.208.0/testing/snapshot.ts";
+3 -3
View File
@@ -22,11 +22,11 @@ import * as router from "./router.ts";
import DefaultErrorHandler from "./default_error_page.tsx"; import DefaultErrorHandler from "./default_error_page.tsx";
import { import {
basename, basename,
contentType,
dirname, dirname,
extname, extname,
join, join,
toFileUrl, toFileUrl,
typeByExtension,
walk, walk,
} from "./deps.ts"; } from "./deps.ts";
import { BUILD_ID } from "./build_id.ts"; import { BUILD_ID } from "./build_id.ts";
@@ -316,7 +316,7 @@ export async function extractRoutes(
const localUrl = toFileUrl(entry.path); const localUrl = toFileUrl(entry.path);
const path = localUrl.href.substring(staticDirUrl.href.length); const path = localUrl.href.substring(staticDirUrl.href.length);
const stat = await Deno.stat(localUrl); const stat = await Deno.stat(localUrl);
const contentType = typeByExtension(extname(path)) ?? const type = contentType(extname(path)) ??
"application/octet-stream"; "application/octet-stream";
const etag = await crypto.subtle.digest( const etag = await crypto.subtle.digest(
"SHA-1", "SHA-1",
@@ -330,7 +330,7 @@ export async function extractRoutes(
localUrl, localUrl,
path, path,
size: stat.size, size: stat.size,
contentType, contentType: type,
etag, etag,
}; };
staticFiles.push(staticFile); staticFiles.push(staticFile);
+1 -1
View File
@@ -1,6 +1,6 @@
import { ServerContext } from "./context.ts"; import { ServerContext } from "./context.ts";
export type { FromManifestConfig, FromManifestOptions } from "./context.ts"; export type { FromManifestConfig, FromManifestOptions } from "./context.ts";
export { Status } from "./deps.ts"; export { STATUS_CODE } from "./deps.ts";
import { import {
ErrorHandler, ErrorHandler,
FreshConfig, FreshConfig,
+8 -8
View File
@@ -13,13 +13,13 @@ export {
assertNotMatch, assertNotMatch,
assertRejects, assertRejects,
assertStringIncludes, assertStringIncludes,
} from "https://deno.land/std@0.205.0/assert/mod.ts"; } from "https://deno.land/std@0.208.0/assert/mod.ts";
export { assertSnapshot } from "https://deno.land/std@0.205.0/testing/snapshot.ts"; export { assertSnapshot } from "https://deno.land/std@0.208.0/testing/snapshot.ts";
export { export {
TextLineStream, TextLineStream,
} from "https://deno.land/std@0.205.0/streams/text_line_stream.ts"; } from "https://deno.land/std@0.208.0/streams/text_line_stream.ts";
export { delay } from "https://deno.land/std@0.205.0/async/delay.ts"; export { delay } from "https://deno.land/std@0.208.0/async/delay.ts";
export { retry } from "https://deno.land/std@0.205.0/async/retry.ts"; export { retry } from "https://deno.land/std@0.208.0/async/retry.ts";
export { export {
default as puppeteer, default as puppeteer,
Page, Page,
@@ -32,7 +32,7 @@ export {
} from "https://esm.sh/linkedom@0.15.1"; } from "https://esm.sh/linkedom@0.15.1";
export { defineConfig, type Preset } from "https://esm.sh/@twind/core@1.1.3"; 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 { default as presetTailwind } from "https://esm.sh/@twind/preset-tailwind@1.1.4";
export { copy } from "https://deno.land/std@0.205.0/fs/mod.ts"; export { copy } from "https://deno.land/std@0.208.0/fs/mod.ts";
export { export {
basename, basename,
dirname, dirname,
@@ -40,5 +40,5 @@ export {
fromFileUrl, fromFileUrl,
join, join,
relative, relative,
} from "https://deno.land/std@0.205.0/path/mod.ts"; } from "https://deno.land/std@0.208.0/path/mod.ts";
export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; export * as JSONC from "https://deno.land/std@0.208.0/jsonc/mod.ts";
+10 -4
View File
@@ -1,5 +1,5 @@
import { assert, assertEquals, assertStringIncludes } from "./deps.ts"; import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
import { Status } from "../server.ts"; import { STATUS_CODE } from "../server.ts";
import { import {
assertNotSelector, assertNotSelector,
assertSelector, assertSelector,
@@ -66,7 +66,7 @@ Deno.test("preact/debug is active in dev mode", async () => {
// SSR error is shown // SSR error is shown
const resp = await server.get("/"); const resp = await server.get("/");
await resp.text(); // Consume await resp.text(); // Consume
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, STATUS_CODE.InternalServerError);
const { title } = await getErrorOverlay(server, "/"); const { title } = await getErrorOverlay(server, "/");
assertStringIncludes(title, "Objects are not valid as a child"); assertStringIncludes(title, "Objects are not valid as a child");
@@ -143,12 +143,18 @@ Deno.test("serve client script source map", async () => {
const res = await server.get(`/_frsh/fresh_dev_client.js`); const res = await server.get(`/_frsh/fresh_dev_client.js`);
await res.text(); // Consume body await res.text(); // Consume body
assertEquals(res.status, 200); assertEquals(res.status, 200);
assertEquals(res.headers.get("Content-Type"), "application/javascript"); assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
);
const res2 = await server.get(`/_frsh/fresh_dev_client.js.map`); const res2 = await server.get(`/_frsh/fresh_dev_client.js.map`);
const json = await res2.json(); const json = await res2.json();
assertEquals(res2.status, 200); assertEquals(res2.status, 200);
assertEquals(res2.headers.get("Content-Type"), "application/json"); assertEquals(
res2.headers.get("Content-Type"),
"application/json; charset=UTF-8",
);
assert(typeof json.mappings, "string"); assert(typeof json.mappings, "string");
}, },
); );
+2 -2
View File
@@ -1,11 +1,11 @@
import { Status } from "../server.ts"; import { STATUS_CODE } from "../server.ts";
import { assertEquals, assertStringIncludes } from "./deps.ts"; import { assertEquals, assertStringIncludes } from "./deps.ts";
import { getErrorOverlay, withFakeServe } from "./test_utils.ts"; import { getErrorOverlay, withFakeServe } from "./test_utils.ts";
Deno.test("error page rendered", async () => { Deno.test("error page rendered", async () => {
await withFakeServe("./tests/fixture_error/dev.ts", async (server) => { await withFakeServe("./tests/fixture_error/dev.ts", async (server) => {
const resp = await server.get("/"); const resp = await server.get("/");
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, STATUS_CODE.InternalServerError);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
await resp.text(); // Consume await resp.text(); // Consume
+1 -1
View File
@@ -10,7 +10,7 @@
"preact/": "https://esm.sh/preact@10.15.1/", "preact/": "https://esm.sh/preact@10.15.1/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.2.3", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.2.3",
"$std/": "https://deno.land/std@0.205.0/" "$std/": "https://deno.land/std@0.208.0/"
}, },
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
+3 -3
View File
@@ -1,5 +1,5 @@
import * as path from "$std/path/mod.ts"; import * as path from "$std/path/mod.ts";
import { Status } from "../src/server/deps.ts"; import { STATUS_CODE } from "../src/server/deps.ts";
import { import {
assert, assert,
assertEquals, assertEquals,
@@ -110,7 +110,7 @@ Deno.test({
// Access the root page // Access the root page
const res = await fetch(address); const res = await fetch(address);
await res.body?.cancel(); await res.body?.cancel();
assertEquals(res.status, Status.OK); assertEquals(res.status, STATUS_CODE.OK);
// verify the island is revived. // verify the island is revived.
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@@ -201,7 +201,7 @@ Deno.test({
// Access the root page // Access the root page
const res = await fetch(address); const res = await fetch(address);
await res.body?.cancel(); await res.body?.cancel();
assertEquals(res.status, Status.OK); assertEquals(res.status, STATUS_CODE.OK);
// verify the island is revived. // verify the island is revived.
const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
+57 -57
View File
@@ -1,4 +1,4 @@
import { ServerContext, Status } from "../server.ts"; import { ServerContext, STATUS_CODE } from "../server.ts";
import { import {
assert, assert,
assertEquals, assertEquals,
@@ -28,7 +28,7 @@ const handler = ctx.handler();
Deno.test("/ page prerender", async () => { Deno.test("/ page prerender", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/")); const resp = await handler(new Request("https://fresh.deno.dev/"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
assertEquals(resp.headers.get("server"), "fresh test server"); assertEquals(resp.headers.get("server"), "fresh test server");
const body = await resp.text(); const body = await resp.text();
@@ -55,7 +55,7 @@ Deno.test("/ page prerender", async () => {
Deno.test("/props/123 page prerender", async () => { Deno.test("/props/123 page prerender", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/props/123")); const resp = await handler(new Request("https://fresh.deno.dev/props/123"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
const doc = parseHtml(body); const doc = parseHtml(body);
@@ -72,7 +72,7 @@ Deno.test("/props/123 page prerender", async () => {
Deno.test("/greet/[name] page prerender", async () => { Deno.test("/greet/[name] page prerender", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/bar")); const resp = await handler(new Request("https://fresh.deno.dev/bar"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>Hello bar</div>"); assertStringIncludes(body, "<div>Hello bar</div>");
@@ -84,7 +84,7 @@ Deno.test("/api/head_override - HEAD", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.NoContent); assertEquals(resp.status, STATUS_CODE.NoContent);
assertEquals(resp.body, null); assertEquals(resp.body, null);
assertEquals( assertEquals(
resp.headers.get("content-type"), resp.headers.get("content-type"),
@@ -98,7 +98,7 @@ Deno.test("/api/get_only - HEAD fallback", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.body, null); assertEquals(resp.body, null);
assertEquals( assertEquals(
resp.headers.get("content-type"), resp.headers.get("content-type"),
@@ -112,7 +112,7 @@ Deno.test("/intercept - GET html", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>This is HTML</div>"); assertStringIncludes(body, "<div>This is HTML</div>");
}); });
@@ -123,7 +123,7 @@ Deno.test("/intercept - GET text", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertEquals(body, "This is plain text"); assertEquals(body, "This is plain text");
}); });
@@ -134,7 +134,7 @@ Deno.test("/intercept - POST", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertEquals(body, "POST response"); assertEquals(body, "POST response");
}); });
@@ -145,7 +145,7 @@ Deno.test("/intercept - DELETE", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.MethodNotAllowed); assertEquals(resp.status, STATUS_CODE.MethodNotAllowed);
}); });
Deno.test("/intercept_args - GET html", async () => { Deno.test("/intercept_args - GET html", async () => {
@@ -154,7 +154,7 @@ Deno.test("/intercept_args - GET html", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>intercepted</div>"); assertStringIncludes(body, "<div>intercepted</div>");
}); });
@@ -165,7 +165,7 @@ Deno.test("/status_overwrite", async () => {
}); });
const resp = await handler(req); const resp = await handler(req);
assert(resp); assert(resp);
assertEquals(resp.status, Status.Unauthorized); assertEquals(resp.status, STATUS_CODE.Unauthorized);
assertEquals(resp.headers.get("x-some-header"), "foo"); assertEquals(resp.headers.get("x-some-header"), "foo");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>This is HTML</div>"); assertStringIncludes(body, "<div>This is HTML</div>");
@@ -178,13 +178,13 @@ Deno.test("/api/get_only - NOTAMETHOD", async () => {
}), }),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.MethodNotAllowed); assertEquals(resp.status, STATUS_CODE.MethodNotAllowed);
}); });
Deno.test("/api/xyz not found", async () => { Deno.test("/api/xyz not found", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/api/xyz")); const resp = await handler(new Request("https://fresh.deno.dev/api/xyz"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "404 not found: /api/xyz"); assertStringIncludes(body, "404 not found: /api/xyz");
}); });
@@ -192,7 +192,7 @@ Deno.test("/api/xyz not found", async () => {
Deno.test("/static page prerender", async () => { Deno.test("/static page prerender", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/static")); const resp = await handler(new Request("https://fresh.deno.dev/static"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assert(!body.includes(`main.js`)); assert(!body.includes(`main.js`));
@@ -205,7 +205,7 @@ Deno.test("/static page prerender", async () => {
Deno.test("/books/:id page - /books/123", async () => { Deno.test("/books/:id page - /books/123", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/books/123")); const resp = await handler(new Request("https://fresh.deno.dev/books/123"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>Book 123</div>"); assertStringIncludes(body, "<div>Book 123</div>");
@@ -214,13 +214,13 @@ Deno.test("/books/:id page - /books/123", async () => {
Deno.test("/books/:id page - /books/abc", async () => { Deno.test("/books/:id page - /books/abc", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/books/abc")); const resp = await handler(new Request("https://fresh.deno.dev/books/abc"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
}); });
Deno.test("/i18n{/:lang}?/lang page - /i18n/lang", async () => { Deno.test("/i18n{/:lang}?/lang page - /i18n/lang", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/i18n/lang")); const resp = await handler(new Request("https://fresh.deno.dev/i18n/lang"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>Hello</div>"); assertStringIncludes(body, "<div>Hello</div>");
@@ -231,7 +231,7 @@ Deno.test("/i18n{/:lang}?/lang page - /i18n/en/lang", async () => {
new Request("https://fresh.deno.dev/i18n/en/lang"), new Request("https://fresh.deno.dev/i18n/en/lang"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>Hello en</div>"); assertStringIncludes(body, "<div>Hello en</div>");
@@ -242,7 +242,7 @@ Deno.test("redirect /pages/fresh/ to /pages/fresh", async () => {
new Request("https://fresh.deno.dev/pages/fresh/"), new Request("https://fresh.deno.dev/pages/fresh/"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.TemporaryRedirect); assertEquals(resp.status, STATUS_CODE.TemporaryRedirect);
assertEquals( assertEquals(
resp.headers.get("location"), resp.headers.get("location"),
"/pages/fresh", "/pages/fresh",
@@ -254,7 +254,7 @@ Deno.test("redirect /pages/////fresh///// to /pages/////fresh", async () => {
new Request("https://fresh.deno.dev/pages/////fresh/////"), new Request("https://fresh.deno.dev/pages/////fresh/////"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.TemporaryRedirect); assertEquals(resp.status, STATUS_CODE.TemporaryRedirect);
assertEquals( assertEquals(
resp.headers.get("location"), resp.headers.get("location"),
"/pages/////fresh", "/pages/////fresh",
@@ -266,7 +266,7 @@ Deno.test("redirect /pages/////fresh/ to /pages/////fresh", async () => {
new Request("https://fresh.deno.dev/pages/////fresh/"), new Request("https://fresh.deno.dev/pages/////fresh/"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.TemporaryRedirect); assertEquals(resp.status, STATUS_CODE.TemporaryRedirect);
assertEquals( assertEquals(
resp.headers.get("location"), resp.headers.get("location"),
"/pages/////fresh", "/pages/////fresh",
@@ -278,13 +278,13 @@ Deno.test("no redirect for /pages/////fresh", async () => {
new Request("https://fresh.deno.dev/pages/////fresh"), new Request("https://fresh.deno.dev/pages/////fresh"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
}); });
Deno.test("/failure", async () => { Deno.test("/failure", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/failure")); const resp = await handler(new Request("https://fresh.deno.dev/failure"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, STATUS_CODE.InternalServerError);
const body = await resp.text(); const body = await resp.text();
assert(body.includes("500 internal error: it errored!")); assert(body.includes("500 internal error: it errored!"));
assertStringIncludes( assertStringIncludes(
@@ -296,7 +296,7 @@ Deno.test("/failure", async () => {
Deno.test("/foo/:path*", async () => { Deno.test("/foo/:path*", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/foo/bar/baz")); const resp = await handler(new Request("https://fresh.deno.dev/foo/bar/baz"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assert(body.includes("bar/baz")); assert(body.includes("bar/baz"));
}); });
@@ -319,14 +319,14 @@ Deno.test("static files in custom directory", async () => {
const resp = await newRouter( const resp = await newRouter(
new Request("https://fresh.deno.dev/custom.txt"), new Request("https://fresh.deno.dev/custom.txt"),
); );
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assert(body.startsWith("dir")); assert(body.startsWith("dir"));
}); });
Deno.test("static file - by file path", async () => { Deno.test("static file - by file path", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/foo.txt")); const resp = await handler(new Request("https://fresh.deno.dev/foo.txt"));
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assert(body.startsWith("bar")); assert(body.startsWith("bar"));
const etag = resp.headers.get("etag"); const etag = resp.headers.get("etag");
@@ -334,7 +334,7 @@ Deno.test("static file - by file path", async () => {
// The etag is not weak, because this did not go through content encoding, so // The etag is not weak, because this did not go through content encoding, so
// this is not a real server. // this is not a real server.
assert(!etag.startsWith("W/"), "etag should be weak"); assert(!etag.startsWith("W/"), "etag should be weak");
assertEquals(resp.headers.get("content-type"), "text/plain"); assertEquals(resp.headers.get("content-type"), "text/plain; charset=UTF-8");
const resp2 = await handler( const resp2 = await handler(
new Request("https://fresh.deno.dev/foo.txt", { new Request("https://fresh.deno.dev/foo.txt", {
@@ -343,9 +343,9 @@ Deno.test("static file - by file path", async () => {
}, },
}), }),
); );
assertEquals(resp2.status, Status.NotModified); assertEquals(resp2.status, STATUS_CODE.NotModified);
assertEquals(resp2.headers.get("etag"), etag); assertEquals(resp2.headers.get("etag"), etag);
assertEquals(resp2.headers.get("content-type"), "text/plain"); assertEquals(resp2.headers.get("content-type"), "text/plain; charset=UTF-8");
const resp3 = await handler( const resp3 = await handler(
new Request("https://fresh.deno.dev/foo.txt", { new Request("https://fresh.deno.dev/foo.txt", {
@@ -354,9 +354,9 @@ Deno.test("static file - by file path", async () => {
}, },
}), }),
); );
assertEquals(resp3.status, Status.NotModified); assertEquals(resp3.status, STATUS_CODE.NotModified);
assertEquals(resp3.headers.get("etag"), etag); assertEquals(resp3.headers.get("etag"), etag);
assertEquals(resp3.headers.get("content-type"), "text/plain"); assertEquals(resp3.headers.get("content-type"), "text/plain; charset=UTF-8");
}); });
Deno.test("static file - spaces or other characters in name", async () => { Deno.test("static file - spaces or other characters in name", async () => {
@@ -376,7 +376,7 @@ Deno.test("HEAD request", async () => {
method: "HEAD", method: "HEAD",
}), }),
); );
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertEquals(body, ""); assertEquals(body, "");
@@ -387,7 +387,7 @@ Deno.test("HEAD request", async () => {
}), }),
); );
assert(resp2); assert(resp2);
assertEquals(resp2.status, Status.OK); assertEquals(resp2.status, STATUS_CODE.OK);
const body2 = await resp2.text(); const body2 = await resp2.text();
assertEquals(body2, ""); assertEquals(body2, "");
}); });
@@ -407,7 +407,7 @@ Deno.test("static file - by 'hashed' path", async () => {
new Request(`https://fresh.deno.dev${imgFilePath}`), new Request(`https://fresh.deno.dev${imgFilePath}`),
); );
const _ = await resp2.text(); const _ = await resp2.text();
assertEquals(resp2.status, Status.OK); assertEquals(resp2.status, STATUS_CODE.OK);
assertEquals( assertEquals(
resp2.headers.get("cache-control"), resp2.headers.get("cache-control"),
"public, max-age=31536000, immutable", "public, max-age=31536000, immutable",
@@ -420,7 +420,7 @@ Deno.test("static file - by 'hashed' path", async () => {
}, },
}), }),
); );
assertEquals(resp3.status, Status.NotModified); assertEquals(resp3.status, STATUS_CODE.NotModified);
// ensure asset hook is not applied on file explicitly excluded with attribute // ensure asset hook is not applied on file explicitly excluded with attribute
const imgFilePathWithNoCache = body.match( const imgFilePathWithNoCache = body.match(
@@ -459,7 +459,7 @@ Deno.test("/params/:path*", async () => {
new Request("https://fresh.deno.dev/params/bar/baz"), new Request("https://fresh.deno.dev/params/bar/baz"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertEquals(body, "bar/baz"); assertEquals(body, "bar/baz");
}); });
@@ -467,7 +467,7 @@ Deno.test("/params/:path*", async () => {
Deno.test("/connInfo", async () => { Deno.test("/connInfo", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/connInfo")); const resp = await handler(new Request("https://fresh.deno.dev/connInfo"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertEquals(body, "localhost"); assertEquals(body, "localhost");
}); });
@@ -477,7 +477,7 @@ Deno.test("state in page props", async () => {
new Request("https://fresh.deno.dev/state-in-props"), new Request("https://fresh.deno.dev/state-in-props"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
@@ -495,7 +495,7 @@ Deno.test({
new Request("https://fresh.deno.dev/middleware_root"), new Request("https://fresh.deno.dev/middleware_root"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "root_mw");
assert(!body.includes("layer1_mw")); assert(!body.includes("layer1_mw"));
@@ -513,7 +513,7 @@ Deno.test({
assert(resp); assert(resp);
// test cors handler // test cors handler
assertEquals(resp.status, Status.NoContent); assertEquals(resp.status, STATUS_CODE.NoContent);
}, },
}); });
@@ -524,7 +524,7 @@ Deno.test({
new Request("https://fresh.deno.dev/middleware_root"), new Request("https://fresh.deno.dev/middleware_root"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
// test log handler // test log handler
const latency = resp.headers.get("latency"); const latency = resp.headers.get("latency");
@@ -540,7 +540,7 @@ Deno.test({
new Request("https://fresh.deno.dev/layeredMdw/layer2/abc"), new Request("https://fresh.deno.dev/layeredMdw/layer2/abc"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "root_mw");
assertStringIncludes(body, "layer1_mw"); assertStringIncludes(body, "layer1_mw");
@@ -552,7 +552,7 @@ Deno.test({
new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"), new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"),
); );
assert(resp1); assert(resp1);
assertEquals(resp1.status, Status.OK); assertEquals(resp1.status, STATUS_CODE.OK);
const body1 = await resp1.text(); const body1 = await resp1.text();
assertStringIncludes(body1, "root_mw"); assertStringIncludes(body1, "root_mw");
assertStringIncludes(body1, "layer1_mw"); assertStringIncludes(body1, "layer1_mw");
@@ -569,7 +569,7 @@ Deno.test({
new Request("https://fresh.deno.dev/layeredMdw/layer2"), new Request("https://fresh.deno.dev/layeredMdw/layer2"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "root_mw");
assertStringIncludes(body, "layer1_mw"); assertStringIncludes(body, "layer1_mw");
@@ -581,7 +581,7 @@ Deno.test({
new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"), new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"),
); );
assert(resp1); assert(resp1);
assertEquals(resp1.status, Status.OK); assertEquals(resp1.status, STATUS_CODE.OK);
const body1 = await resp1.text(); const body1 = await resp1.text();
assertStringIncludes(body1, "root_mw"); assertStringIncludes(body1, "root_mw");
assertStringIncludes(body1, "layer1_mw"); assertStringIncludes(body1, "layer1_mw");
@@ -599,7 +599,7 @@ Deno.test({
new Request("https://fresh.deno.dev/layeredMdw/layer2/layer3/abc"), new Request("https://fresh.deno.dev/layeredMdw/layer2/layer3/abc"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "root_mw");
assertStringIncludes(body, "layer1_mw"); assertStringIncludes(body, "layer1_mw");
@@ -619,7 +619,7 @@ Deno.test({
new Request("https://fresh.deno.dev/state-middleware/foo"), new Request("https://fresh.deno.dev/state-middleware/foo"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
const doc = parseHtml(body); const doc = parseHtml(body);
@@ -640,7 +640,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const _body = await resp.text(); const _body = await resp.text();
// assert that outer has access to all params // assert that outer has access to all params
assertEquals( assertEquals(
@@ -665,7 +665,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, "<div>1234</div>"); assertStringIncludes(body, "<div>1234</div>");
}, },
@@ -716,7 +716,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, STATUS_CODE.InternalServerError);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -734,7 +734,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -752,7 +752,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -770,7 +770,7 @@ Deno.test({
), ),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -789,7 +789,7 @@ Deno.test("jsx pragma works", async (t) => {
await t.step("ssr", async () => { await t.step("ssr", async () => {
const resp = await fetch(address); const resp = await fetch(address);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const text = await resp.text(); const text = await resp.text();
assertStringIncludes(text, "Hello World"); assertStringIncludes(text, "Hello World");
assertStringIncludes(text, "ssr"); assertStringIncludes(text, "ssr");
@@ -877,7 +877,7 @@ Deno.test("PORT environment variable", async () => {
const resp = await fetch("http://localhost:" + PORT); const resp = await fetch("http://localhost:" + PORT);
await resp.body?.cancel(); await resp.body?.cancel();
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
await resp.body!.cancel(); await resp.body!.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
@@ -907,7 +907,7 @@ Deno.test("rendering custom _500.tsx page for default handlers", async (t) => {
await withFakeServe("./tests/fixture_custom_500/main.ts", async (server) => { await withFakeServe("./tests/fixture_custom_500/main.ts", async (server) => {
await t.step("SSR error is shown", async () => { await t.step("SSR error is shown", async () => {
const resp = await server.get("/"); const resp = await server.get("/");
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, STATUS_CODE.InternalServerError);
const text = await resp.text(); const text = await resp.text();
assertStringIncludes(text, "Custom 500: Pickle Rick!"); assertStringIncludes(text, "Custom 500: Pickle Rick!");
}); });
+6 -6
View File
@@ -1,4 +1,4 @@
import { ServerContext, Status } from "../server.ts"; import { ServerContext, STATUS_CODE } from "../server.ts";
import { import {
assert, assert,
assertEquals, assertEquals,
@@ -33,7 +33,7 @@ const router = (req: Request) => {
Deno.test("/static page prerender", async () => { Deno.test("/static page prerender", async () => {
const resp = await router(new Request("https://fresh.deno.dev/static")); const resp = await router(new Request("https://fresh.deno.dev/static"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, '<style id="abc">body { color: red; }</style>'); assertStringIncludes(body, '<style id="abc">body { color: red; }</style>');
assert(!body.includes(`>{"v":[[],[]]}</script>`)); assert(!body.includes(`>{"v":[[],[]]}</script>`));
@@ -52,7 +52,7 @@ Deno.test("/static page prerender", async () => {
Deno.test("/with-island prerender", async () => { Deno.test("/with-island prerender", async () => {
const resp = await router(new Request("https://fresh.deno.dev/with-island")); const resp = await router(new Request("https://fresh.deno.dev/with-island"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -69,7 +69,7 @@ Deno.test("/with-island prerender", async () => {
Deno.test("plugin routes and middleware", async () => { Deno.test("plugin routes and middleware", async () => {
const resp = await router(new Request("https://fresh.deno.dev/test")); const resp = await router(new Request("https://fresh.deno.dev/test"));
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -86,7 +86,7 @@ Deno.test("plugin middleware multiple handlers", async () => {
new Request("https://fresh.deno.dev/lots-of-middleware"), new Request("https://fresh.deno.dev/lots-of-middleware"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
@@ -99,7 +99,7 @@ Deno.test("plugin route no leading slash", async () => {
new Request("https://fresh.deno.dev/no-leading-slash-here"), new Request("https://fresh.deno.dev/no-leading-slash-here"),
); );
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
const body = await resp.text(); const body = await resp.text();
assertStringIncludes( assertStringIncludes(
body, body,
+2 -2
View File
@@ -6,7 +6,7 @@ import {
withFresh, withFresh,
withPageName, withPageName,
} from "./test_utils.ts"; } from "./test_utils.ts";
import { Status } from "../server.ts"; import { STATUS_CODE } from "../server.ts";
Deno.test({ Deno.test({
name: "render async server component", name: "render async server component",
@@ -110,7 +110,7 @@ Deno.test({
async (server) => { async (server) => {
const res = await server.get(`/fail`); const res = await server.get(`/fail`);
assertEquals(res.status, Status.NotFound); assertEquals(res.status, STATUS_CODE.NotFound);
const html = await res.text(); const html = await res.text();
assertEquals(html, "Not found."); assertEquals(html, "Not found.");
}, },
+5 -5
View File
@@ -1,5 +1,5 @@
import { INTERNAL_PREFIX } from "../runtime.ts"; import { INTERNAL_PREFIX } from "../runtime.ts";
import { ServerContext, Status } from "../server.ts"; import { ServerContext, STATUS_CODE } from "../server.ts";
import { assert, assertEquals } from "./deps.ts"; import { assert, assertEquals } from "./deps.ts";
import manifest from "./fixture_router/fresh.gen.ts"; import manifest from "./fixture_router/fresh.gen.ts";
@@ -22,7 +22,7 @@ Deno.test("forwards slash placed at the end of url", async () => {
const targetUrl = "https://fresh.deno.dev/about"; const targetUrl = "https://fresh.deno.dev/about";
const resp = await router(new Request(targetUrl)); const resp = await router(new Request(targetUrl));
assert(resp); assert(resp);
assertEquals(resp.status, Status.PermanentRedirect); assertEquals(resp.status, STATUS_CODE.PermanentRedirect);
// forwarded location should be with trailing slash // forwarded location should be with trailing slash
assertEquals(resp.headers.get("location"), targetUrl + "/"); assertEquals(resp.headers.get("location"), targetUrl + "/");
}); });
@@ -32,7 +32,7 @@ Deno.test("forwards slash placed at the end of url with hash and query string",
const queryAndHash = "?demo=test#what"; const queryAndHash = "?demo=test#what";
const resp = await router(new Request(targetUrl + queryAndHash)); const resp = await router(new Request(targetUrl + queryAndHash));
assert(resp); assert(resp);
assertEquals(resp.status, Status.PermanentRedirect); assertEquals(resp.status, STATUS_CODE.PermanentRedirect);
// forwarded location should be with trailing slash // forwarded location should be with trailing slash
assertEquals(resp.headers.get("location"), targetUrl + "/" + queryAndHash); assertEquals(resp.headers.get("location"), targetUrl + "/" + queryAndHash);
}); });
@@ -42,7 +42,7 @@ Deno.test("forwards slash not placed at the end of url with prefix", async () =>
const resp = await router(new Request(targetUrl)); const resp = await router(new Request(targetUrl));
assert(resp); assert(resp);
// we should get a 404 and not a redirect // we should get a 404 and not a redirect
assertEquals(resp.status, Status.NotFound); assertEquals(resp.status, STATUS_CODE.NotFound);
}); });
Deno.test("forwards slash not placed at the end of url for static file", async () => { Deno.test("forwards slash not placed at the end of url for static file", async () => {
@@ -50,6 +50,6 @@ Deno.test("forwards slash not placed at the end of url for static file", async (
const resp = await router(new Request(targetUrl)); const resp = await router(new Request(targetUrl));
assert(resp); assert(resp);
// we should not be getting a redirect // we should not be getting a redirect
assertEquals(resp.status, Status.OK); assertEquals(resp.status, STATUS_CODE.OK);
assertEquals(await resp.text(), "bar"); assertEquals(await resp.text(), "bar");
}); });
+1 -1
View File
@@ -12,7 +12,7 @@
"preact/": "https://esm.sh/preact@10.15.1/", "preact/": "https://esm.sh/preact@10.15.1/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3", "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
"$std/": "https://deno.land/std@0.205.0/", "$std/": "https://deno.land/std@0.208.0/",
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts", "$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts",
"$marked-mangle": "https://esm.sh/marked-mangle@1.0.1", "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1",
"$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.8.0/mod.ts", "$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.8.0/mod.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts"; import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
import { Image } from "https://deno.land/x/imagescript@1.2.15/mod.ts"; import { Image } from "https://deno.land/x/imagescript@1.2.15/mod.ts";
import { join } from "https://deno.land/std@0.205.0/path/mod.ts"; import { join } from "https://deno.land/std@0.208.0/path/mod.ts";
const url = Deno.args[0]; const url = Deno.args[0];
const id = Deno.args[1]; const id = Deno.args[1];