diff --git a/.vscode/import_map.json b/.vscode/import_map.json index 7d586475..867a8e50 100644 --- a/.vscode/import_map.json +++ b/.vscode/import_map.json @@ -12,7 +12,7 @@ "@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.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", "$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", diff --git a/src/build/deps.ts b/src/build/deps.ts index 8f7878c0..67d2a126 100644 --- a/src/build/deps.ts +++ b/src/build/deps.ts @@ -4,7 +4,7 @@ export { join, relative, toFileUrl, -} from "https://deno.land/std@0.205.0/path/mod.ts"; -export { escape as regexpEscape } from "https://deno.land/std@0.205.0/regexp/escape.ts"; +} from "https://deno.land/std@0.208.0/path/mod.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 { 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"; diff --git a/src/dev/deps.ts b/src/dev/deps.ts index f356bae2..5efea053 100644 --- a/src/dev/deps.ts +++ b/src/dev/deps.ts @@ -9,24 +9,24 @@ export { resolve, SEP, toFileUrl, -} from "https://deno.land/std@0.205.0/path/mod.ts"; -export { normalize } from "https://deno.land/std@0.205.0/path/posix/mod.ts"; -export { DAY, WEEK } from "https://deno.land/std@0.205.0/datetime/constants.ts"; -export * as colors from "https://deno.land/std@0.205.0/fmt/colors.ts"; +} from "https://deno.land/std@0.208.0/path/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.208.0/datetime/constants.ts"; +export * as colors from "https://deno.land/std@0.208.0/fmt/colors.ts"; export { walk, type WalkEntry, WalkError, -} from "https://deno.land/std@0.205.0/fs/walk.ts"; -export { parse } from "https://deno.land/std@0.205.0/flags/mod.ts"; +} from "https://deno.land/std@0.208.0/fs/walk.ts"; +export { parse } from "https://deno.land/std@0.208.0/flags/mod.ts"; export { gte, lt, parse as semverParse, -} from "https://deno.land/std@0.205.0/semver/mod.ts"; -export { emptyDir, existsSync } from "https://deno.land/std@0.205.0/fs/mod.ts"; -export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; -export { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts"; +} from "https://deno.land/std@0.208.0/semver/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.208.0/jsonc/mod.ts"; +export { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts"; // ts-morph export { Node, Project } from "https://deno.land/x/ts_morph@20.0.0/mod.ts"; diff --git a/src/dev/imports.ts b/src/dev/imports.ts index c00ddb79..81b9b52d 100644 --- a/src/dev/imports.ts +++ b/src/dev/imports.ts @@ -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_CORE_VERSION = "1.5.0"; 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 function freshImports(imports: Record) { diff --git a/src/server/code_frame_test.ts b/src/server/code_frame_test.ts index 97f1ec71..d1b6b7a8 100644 --- a/src/server/code_frame_test.ts +++ b/src/server/code_frame_test.ts @@ -1,6 +1,5 @@ -import { assertSnapshot } from "$std/testing/snapshot.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) { const codeFrame = createCodeFrame(text, line, column); diff --git a/src/server/context.ts b/src/server/context.ts index 811d18e4..28749902 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -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 { FreshConfig, Manifest, UnknownHandlerContext } from "./mod.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 location = `${path}${url.search}`; return new Response(null, { - status: Status.TemporaryRedirect, + status: STATUS_CODE.TemporaryRedirect, headers: { location }, }); } else if (trailingSlashEnabled && !url.pathname.endsWith("/")) { @@ -232,7 +232,7 @@ export class ServerContext { if (!isFile && !isInternal) { url.pathname += "/"; - return Response.redirect(url, Status.PermanentRedirect); + return Response.redirect(url, STATUS_CODE.PermanentRedirect); } } @@ -390,7 +390,7 @@ export class ServerContext { ) { route.pattern += "/"; } - const createRender = genRender(route, Status.OK); + const createRender = genRender(route, STATUS_CODE.OK); if (typeof route.handler === "function") { routes[route.pattern] = { baseRoute: route.baseRoute, @@ -445,7 +445,7 @@ export class ServerContext { const errorHandlerRender = genRender( this.#extractResult.error, - Status.InternalServerError, + STATUS_CODE.InternalServerError, ); const errorHandler: router.ErrorHandler = async ( req, @@ -595,8 +595,8 @@ export class ServerContext { : "public, max-age=604800, immutable", }; - const contentType = typeByExtension(extname(params.path)); - if (contentType) headers["Content-Type"] = contentType; + const type = contentType(extname(params.path)); + if (type) headers["Content-Type"] = type; return new Response(contents, { status: 200, @@ -625,7 +625,7 @@ const createRenderNotFound = ( const notFound = extractResult.notFound; if (!notFound.component) { return sendResponse(["Not found.", undefined], { - status: Status.NotFound, + status: STATUS_CODE.NotFound, isDev: dev, statusText: undefined, headers: undefined, @@ -660,7 +660,7 @@ const createRenderNotFound = ( } return sendResponse(resp, { - status: Status.NotFound, + status: STATUS_CODE.NotFound, isDev: dev, statusText: undefined, headers: undefined, diff --git a/src/server/deps.ts b/src/server/deps.ts index 13220051..04bca9e2 100644 --- a/src/server/deps.ts +++ b/src/server/deps.ts @@ -7,22 +7,23 @@ export { isAbsolute, join, toFileUrl, -} from "https://deno.land/std@0.205.0/path/mod.ts"; -export { walk } from "https://deno.land/std@0.205.0/fs/walk.ts"; -export * as colors from "https://deno.land/std@0.205.0/fmt/colors.ts"; +} from "https://deno.land/std@0.208.0/path/mod.ts"; +export { walk } from "https://deno.land/std@0.208.0/fs/walk.ts"; +export * as colors from "https://deno.land/std@0.208.0/fmt/colors.ts"; export { type Handler as ServeHandler, serve, -} from "https://deno.land/std@0.205.0/http/server.ts"; -export { Status } from "https://deno.land/std@0.205.0/http/http_status.ts"; +} from "https://deno.land/std@0.208.0/http/server.ts"; +export { STATUS_CODE } from "https://deno.land/std@0.208.0/http/status.ts"; export { - typeByExtension, -} from "https://deno.land/std@0.205.0/media_types/mod.ts"; -export { toHashString } from "https://deno.land/std@0.205.0/crypto/to_hash_string.ts"; -export { escape } from "https://deno.land/std@0.205.0/regexp/escape.ts"; -export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; + contentType, +} from "https://deno.land/std@0.208.0/media_types/content_type.ts"; +export { toHashString } from "https://deno.land/std@0.208.0/crypto/to_hash_string.ts"; +export { escape } from "https://deno.land/std@0.208.0/regexp/escape.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 { assertEquals, 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"; diff --git a/src/server/fs_extract.ts b/src/server/fs_extract.ts index 4c119a2e..859d813a 100644 --- a/src/server/fs_extract.ts +++ b/src/server/fs_extract.ts @@ -22,11 +22,11 @@ import * as router from "./router.ts"; import DefaultErrorHandler from "./default_error_page.tsx"; import { basename, + contentType, dirname, extname, join, toFileUrl, - typeByExtension, walk, } from "./deps.ts"; import { BUILD_ID } from "./build_id.ts"; @@ -316,7 +316,7 @@ export async function extractRoutes( const localUrl = toFileUrl(entry.path); const path = localUrl.href.substring(staticDirUrl.href.length); const stat = await Deno.stat(localUrl); - const contentType = typeByExtension(extname(path)) ?? + const type = contentType(extname(path)) ?? "application/octet-stream"; const etag = await crypto.subtle.digest( "SHA-1", @@ -330,7 +330,7 @@ export async function extractRoutes( localUrl, path, size: stat.size, - contentType, + contentType: type, etag, }; staticFiles.push(staticFile); diff --git a/src/server/mod.ts b/src/server/mod.ts index 5d9dfe43..fbf9a921 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -1,6 +1,6 @@ import { ServerContext } from "./context.ts"; export type { FromManifestConfig, FromManifestOptions } from "./context.ts"; -export { Status } from "./deps.ts"; +export { STATUS_CODE } from "./deps.ts"; import { ErrorHandler, FreshConfig, diff --git a/tests/deps.ts b/tests/deps.ts index 16ebf8d2..e727d44c 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -13,13 +13,13 @@ export { assertNotMatch, assertRejects, assertStringIncludes, -} from "https://deno.land/std@0.205.0/assert/mod.ts"; -export { assertSnapshot } from "https://deno.land/std@0.205.0/testing/snapshot.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"; export { TextLineStream, -} from "https://deno.land/std@0.205.0/streams/text_line_stream.ts"; -export { delay } from "https://deno.land/std@0.205.0/async/delay.ts"; -export { retry } from "https://deno.land/std@0.205.0/async/retry.ts"; +} from "https://deno.land/std@0.208.0/streams/text_line_stream.ts"; +export { delay } from "https://deno.land/std@0.208.0/async/delay.ts"; +export { retry } from "https://deno.land/std@0.208.0/async/retry.ts"; export { default as puppeteer, Page, @@ -32,7 +32,7 @@ export { } from "https://esm.sh/linkedom@0.15.1"; 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.205.0/fs/mod.ts"; +export { copy } from "https://deno.land/std@0.208.0/fs/mod.ts"; export { basename, dirname, @@ -40,5 +40,5 @@ export { fromFileUrl, join, relative, -} from "https://deno.land/std@0.205.0/path/mod.ts"; -export * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts"; +} from "https://deno.land/std@0.208.0/path/mod.ts"; +export * as JSONC from "https://deno.land/std@0.208.0/jsonc/mod.ts"; diff --git a/tests/dev_command_test.ts b/tests/dev_command_test.ts index 5ea8674b..c0aca3e2 100644 --- a/tests/dev_command_test.ts +++ b/tests/dev_command_test.ts @@ -1,5 +1,5 @@ import { assert, assertEquals, assertStringIncludes } from "./deps.ts"; -import { Status } from "../server.ts"; +import { STATUS_CODE } from "../server.ts"; import { assertNotSelector, assertSelector, @@ -66,7 +66,7 @@ Deno.test("preact/debug is active in dev mode", async () => { // SSR error is shown const resp = await server.get("/"); await resp.text(); // Consume - assertEquals(resp.status, Status.InternalServerError); + assertEquals(resp.status, STATUS_CODE.InternalServerError); const { title } = await getErrorOverlay(server, "/"); 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`); await res.text(); // Consume body 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 json = await res2.json(); 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"); }, ); diff --git a/tests/error_test.ts b/tests/error_test.ts index e195e3c1..2a6af30c 100644 --- a/tests/error_test.ts +++ b/tests/error_test.ts @@ -1,11 +1,11 @@ -import { Status } from "../server.ts"; +import { STATUS_CODE } from "../server.ts"; import { assertEquals, 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.InternalServerError); + assertEquals(resp.status, STATUS_CODE.InternalServerError); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); await resp.text(); // Consume diff --git a/tests/fixture_route_analysis/deno.json b/tests/fixture_route_analysis/deno.json index 27f292de..4ec11b09 100644 --- a/tests/fixture_route_analysis/deno.json +++ b/tests/fixture_route_analysis/deno.json @@ -10,7 +10,7 @@ "preact/": "https://esm.sh/preact@10.15.1/", "@preact/signals": "https://esm.sh/*@preact/signals@1.1.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": { "jsx": "react-jsx", diff --git a/tests/init_test.ts b/tests/init_test.ts index bd52fa59..dbf7926e 100644 --- a/tests/init_test.ts +++ b/tests/init_test.ts @@ -1,5 +1,5 @@ import * as path from "$std/path/mod.ts"; -import { Status } from "../src/server/deps.ts"; +import { STATUS_CODE } from "../src/server/deps.ts"; import { assert, assertEquals, @@ -110,7 +110,7 @@ Deno.test({ // Access the root page const res = await fetch(address); await res.body?.cancel(); - assertEquals(res.status, Status.OK); + assertEquals(res.status, STATUS_CODE.OK); // verify the island is revived. const browser = await puppeteer.launch({ @@ -201,7 +201,7 @@ Deno.test({ // Access the root page const res = await fetch(address); await res.body?.cancel(); - assertEquals(res.status, Status.OK); + assertEquals(res.status, STATUS_CODE.OK); // verify the island is revived. const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); diff --git a/tests/main_test.ts b/tests/main_test.ts index b8fddaed..7bd5aa89 100644 --- a/tests/main_test.ts +++ b/tests/main_test.ts @@ -1,4 +1,4 @@ -import { ServerContext, Status } from "../server.ts"; +import { ServerContext, STATUS_CODE } from "../server.ts"; import { assert, assertEquals, @@ -28,7 +28,7 @@ const handler = ctx.handler(); Deno.test("/ page prerender", async () => { const resp = await handler(new Request("https://fresh.deno.dev/")); 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("server"), "fresh test server"); const body = await resp.text(); @@ -55,7 +55,7 @@ Deno.test("/ page prerender", async () => { Deno.test("/props/123 page prerender", async () => { const resp = await handler(new Request("https://fresh.deno.dev/props/123")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); const doc = parseHtml(body); @@ -72,7 +72,7 @@ Deno.test("/props/123 page prerender", async () => { Deno.test("/greet/[name] page prerender", async () => { const resp = await handler(new Request("https://fresh.deno.dev/bar")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "
Hello bar
"); @@ -84,7 +84,7 @@ Deno.test("/api/head_override - HEAD", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.NoContent); + assertEquals(resp.status, STATUS_CODE.NoContent); assertEquals(resp.body, null); assertEquals( resp.headers.get("content-type"), @@ -98,7 +98,7 @@ Deno.test("/api/get_only - HEAD fallback", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.body, null); assertEquals( resp.headers.get("content-type"), @@ -112,7 +112,7 @@ Deno.test("/intercept - GET html", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "
This is HTML
"); }); @@ -123,7 +123,7 @@ Deno.test("/intercept - GET text", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertEquals(body, "This is plain text"); }); @@ -134,7 +134,7 @@ Deno.test("/intercept - POST", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertEquals(body, "POST response"); }); @@ -145,7 +145,7 @@ Deno.test("/intercept - DELETE", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.MethodNotAllowed); + assertEquals(resp.status, STATUS_CODE.MethodNotAllowed); }); Deno.test("/intercept_args - GET html", async () => { @@ -154,7 +154,7 @@ Deno.test("/intercept_args - GET html", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "
intercepted
"); }); @@ -165,7 +165,7 @@ Deno.test("/status_overwrite", async () => { }); const resp = await handler(req); assert(resp); - assertEquals(resp.status, Status.Unauthorized); + assertEquals(resp.status, STATUS_CODE.Unauthorized); assertEquals(resp.headers.get("x-some-header"), "foo"); const body = await resp.text(); assertStringIncludes(body, "
This is HTML
"); @@ -178,13 +178,13 @@ Deno.test("/api/get_only - NOTAMETHOD", async () => { }), ); assert(resp); - assertEquals(resp.status, Status.MethodNotAllowed); + assertEquals(resp.status, STATUS_CODE.MethodNotAllowed); }); Deno.test("/api/xyz not found", async () => { const resp = await handler(new Request("https://fresh.deno.dev/api/xyz")); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); const body = await resp.text(); assertStringIncludes(body, "404 not found: /api/xyz"); }); @@ -192,7 +192,7 @@ Deno.test("/api/xyz not found", async () => { Deno.test("/static page prerender", async () => { const resp = await handler(new Request("https://fresh.deno.dev/static")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assert(!body.includes(`main.js`)); @@ -205,7 +205,7 @@ Deno.test("/static page prerender", async () => { Deno.test("/books/:id page - /books/123", async () => { const resp = await handler(new Request("https://fresh.deno.dev/books/123")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "
Book 123
"); @@ -214,13 +214,13 @@ Deno.test("/books/:id page - /books/123", async () => { Deno.test("/books/:id page - /books/abc", async () => { const resp = await handler(new Request("https://fresh.deno.dev/books/abc")); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); }); Deno.test("/i18n{/:lang}?/lang page - /i18n/lang", async () => { const resp = await handler(new Request("https://fresh.deno.dev/i18n/lang")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "
Hello
"); @@ -231,7 +231,7 @@ Deno.test("/i18n{/:lang}?/lang page - /i18n/en/lang", async () => { new Request("https://fresh.deno.dev/i18n/en/lang"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "
Hello en
"); @@ -242,7 +242,7 @@ Deno.test("redirect /pages/fresh/ to /pages/fresh", async () => { new Request("https://fresh.deno.dev/pages/fresh/"), ); assert(resp); - assertEquals(resp.status, Status.TemporaryRedirect); + assertEquals(resp.status, STATUS_CODE.TemporaryRedirect); assertEquals( resp.headers.get("location"), "/pages/fresh", @@ -254,7 +254,7 @@ Deno.test("redirect /pages/////fresh///// to /pages/////fresh", async () => { new Request("https://fresh.deno.dev/pages/////fresh/////"), ); assert(resp); - assertEquals(resp.status, Status.TemporaryRedirect); + assertEquals(resp.status, STATUS_CODE.TemporaryRedirect); assertEquals( resp.headers.get("location"), "/pages/////fresh", @@ -266,7 +266,7 @@ Deno.test("redirect /pages/////fresh/ to /pages/////fresh", async () => { new Request("https://fresh.deno.dev/pages/////fresh/"), ); assert(resp); - assertEquals(resp.status, Status.TemporaryRedirect); + assertEquals(resp.status, STATUS_CODE.TemporaryRedirect); assertEquals( resp.headers.get("location"), "/pages/////fresh", @@ -278,13 +278,13 @@ Deno.test("no redirect for /pages/////fresh", async () => { new Request("https://fresh.deno.dev/pages/////fresh"), ); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); }); Deno.test("/failure", async () => { const resp = await handler(new Request("https://fresh.deno.dev/failure")); assert(resp); - assertEquals(resp.status, Status.InternalServerError); + assertEquals(resp.status, STATUS_CODE.InternalServerError); const body = await resp.text(); assert(body.includes("500 internal error: it errored!")); assertStringIncludes( @@ -296,7 +296,7 @@ Deno.test("/failure", async () => { Deno.test("/foo/:path*", async () => { const resp = await handler(new Request("https://fresh.deno.dev/foo/bar/baz")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assert(body.includes("bar/baz")); }); @@ -319,14 +319,14 @@ Deno.test("static files in custom directory", async () => { const resp = await newRouter( new Request("https://fresh.deno.dev/custom.txt"), ); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assert(body.startsWith("dir")); }); Deno.test("static file - by file path", async () => { 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(); assert(body.startsWith("bar")); 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 // this is not a real server. 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( 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("content-type"), "text/plain"); + assertEquals(resp2.headers.get("content-type"), "text/plain; charset=UTF-8"); const resp3 = await handler( 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("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 () => { @@ -376,7 +376,7 @@ Deno.test("HEAD request", async () => { method: "HEAD", }), ); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertEquals(body, ""); @@ -387,7 +387,7 @@ Deno.test("HEAD request", async () => { }), ); assert(resp2); - assertEquals(resp2.status, Status.OK); + assertEquals(resp2.status, STATUS_CODE.OK); const body2 = await resp2.text(); assertEquals(body2, ""); }); @@ -407,7 +407,7 @@ Deno.test("static file - by 'hashed' path", async () => { new Request(`https://fresh.deno.dev${imgFilePath}`), ); const _ = await resp2.text(); - assertEquals(resp2.status, Status.OK); + assertEquals(resp2.status, STATUS_CODE.OK); assertEquals( resp2.headers.get("cache-control"), "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 const imgFilePathWithNoCache = body.match( @@ -459,7 +459,7 @@ Deno.test("/params/:path*", async () => { new Request("https://fresh.deno.dev/params/bar/baz"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertEquals(body, "bar/baz"); }); @@ -467,7 +467,7 @@ Deno.test("/params/:path*", async () => { Deno.test("/connInfo", async () => { const resp = await handler(new Request("https://fresh.deno.dev/connInfo")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertEquals(body, "localhost"); }); @@ -477,7 +477,7 @@ Deno.test("state in page props", async () => { new Request("https://fresh.deno.dev/state-in-props"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes( @@ -495,7 +495,7 @@ Deno.test({ new Request("https://fresh.deno.dev/middleware_root"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "root_mw"); assert(!body.includes("layer1_mw")); @@ -513,7 +513,7 @@ Deno.test({ assert(resp); // 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"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); // test log handler const latency = resp.headers.get("latency"); @@ -540,7 +540,7 @@ Deno.test({ new Request("https://fresh.deno.dev/layeredMdw/layer2/abc"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "layer1_mw"); @@ -552,7 +552,7 @@ Deno.test({ new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"), ); assert(resp1); - assertEquals(resp1.status, Status.OK); + assertEquals(resp1.status, STATUS_CODE.OK); const body1 = await resp1.text(); assertStringIncludes(body1, "root_mw"); assertStringIncludes(body1, "layer1_mw"); @@ -569,7 +569,7 @@ Deno.test({ new Request("https://fresh.deno.dev/layeredMdw/layer2"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "layer1_mw"); @@ -581,7 +581,7 @@ Deno.test({ new Request("https://fresh.deno.dev/layeredMdw/layer2-no-mw/without_mw"), ); assert(resp1); - assertEquals(resp1.status, Status.OK); + assertEquals(resp1.status, STATUS_CODE.OK); const body1 = await resp1.text(); assertStringIncludes(body1, "root_mw"); assertStringIncludes(body1, "layer1_mw"); @@ -599,7 +599,7 @@ Deno.test({ new Request("https://fresh.deno.dev/layeredMdw/layer2/layer3/abc"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "root_mw"); assertStringIncludes(body, "layer1_mw"); @@ -619,7 +619,7 @@ Deno.test({ new Request("https://fresh.deno.dev/state-middleware/foo"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); const doc = parseHtml(body); @@ -640,7 +640,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const _body = await resp.text(); // assert that outer has access to all params assertEquals( @@ -665,7 +665,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, "
1234
"); }, @@ -716,7 +716,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.InternalServerError); + assertEquals(resp.status, STATUS_CODE.InternalServerError); const body = await resp.text(); assertStringIncludes( body, @@ -734,7 +734,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); const body = await resp.text(); assertStringIncludes( body, @@ -752,7 +752,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); const body = await resp.text(); assertStringIncludes( body, @@ -770,7 +770,7 @@ Deno.test({ ), ); assert(resp); - assertEquals(resp.status, Status.NotFound); + assertEquals(resp.status, STATUS_CODE.NotFound); const body = await resp.text(); assertStringIncludes( body, @@ -789,7 +789,7 @@ Deno.test("jsx pragma works", async (t) => { await t.step("ssr", async () => { const resp = await fetch(address); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const text = await resp.text(); assertStringIncludes(text, "Hello World"); assertStringIncludes(text, "ssr"); @@ -877,7 +877,7 @@ Deno.test("PORT environment variable", async () => { const resp = await fetch("http://localhost:" + PORT); await resp.body?.cancel(); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); await resp.body!.cancel(); 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 t.step("SSR error is shown", async () => { const resp = await server.get("/"); - assertEquals(resp.status, Status.InternalServerError); + assertEquals(resp.status, STATUS_CODE.InternalServerError); const text = await resp.text(); assertStringIncludes(text, "Custom 500: Pickle Rick!"); }); diff --git a/tests/plugin_test.ts b/tests/plugin_test.ts index 87577452..87a59902 100644 --- a/tests/plugin_test.ts +++ b/tests/plugin_test.ts @@ -1,4 +1,4 @@ -import { ServerContext, Status } from "../server.ts"; +import { ServerContext, STATUS_CODE } from "../server.ts"; import { assert, assertEquals, @@ -33,7 +33,7 @@ const router = (req: Request) => { Deno.test("/static page prerender", async () => { const resp = await router(new Request("https://fresh.deno.dev/static")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes(body, ''); assert(!body.includes(`>{"v":[[],[]]}`)); @@ -52,7 +52,7 @@ Deno.test("/static page prerender", async () => { Deno.test("/with-island prerender", async () => { const resp = await router(new Request("https://fresh.deno.dev/with-island")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes( body, @@ -69,7 +69,7 @@ Deno.test("/with-island prerender", async () => { Deno.test("plugin routes and middleware", async () => { const resp = await router(new Request("https://fresh.deno.dev/test")); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes( body, @@ -86,7 +86,7 @@ Deno.test("plugin middleware multiple handlers", async () => { new Request("https://fresh.deno.dev/lots-of-middleware"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes( body, @@ -99,7 +99,7 @@ Deno.test("plugin route no leading slash", async () => { new Request("https://fresh.deno.dev/no-leading-slash-here"), ); assert(resp); - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); const body = await resp.text(); assertStringIncludes( body, diff --git a/tests/server_components_test.ts b/tests/server_components_test.ts index 95afeccb..df2eae8a 100644 --- a/tests/server_components_test.ts +++ b/tests/server_components_test.ts @@ -6,7 +6,7 @@ import { withFresh, withPageName, } from "./test_utils.ts"; -import { Status } from "../server.ts"; +import { STATUS_CODE } from "../server.ts"; Deno.test({ name: "render async server component", @@ -110,7 +110,7 @@ Deno.test({ async (server) => { const res = await server.get(`/fail`); - assertEquals(res.status, Status.NotFound); + assertEquals(res.status, STATUS_CODE.NotFound); const html = await res.text(); assertEquals(html, "Not found."); }, diff --git a/tests/trailing_slash_test.ts b/tests/trailing_slash_test.ts index 7947bcd7..75eb3466 100644 --- a/tests/trailing_slash_test.ts +++ b/tests/trailing_slash_test.ts @@ -1,5 +1,5 @@ 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 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 resp = await router(new Request(targetUrl)); assert(resp); - assertEquals(resp.status, Status.PermanentRedirect); + assertEquals(resp.status, STATUS_CODE.PermanentRedirect); // forwarded location should be with trailing slash 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 resp = await router(new Request(targetUrl + queryAndHash)); assert(resp); - assertEquals(resp.status, Status.PermanentRedirect); + assertEquals(resp.status, STATUS_CODE.PermanentRedirect); // forwarded location should be with trailing slash 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)); assert(resp); // 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 () => { @@ -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)); assert(resp); // we should not be getting a redirect - assertEquals(resp.status, Status.OK); + assertEquals(resp.status, STATUS_CODE.OK); assertEquals(await resp.text(), "bar"); }); diff --git a/www/deno.json b/www/deno.json index 998436aa..90190d19 100644 --- a/www/deno.json +++ b/www/deno.json @@ -12,7 +12,7 @@ "preact/": "https://esm.sh/preact@10.15.1/", "@preact/signals": "https://esm.sh/*@preact/signals@1.1.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", "$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", diff --git a/www/utils/screenshot.ts b/www/utils/screenshot.ts index 15d1fd6b..43097dd7 100644 --- a/www/utils/screenshot.ts +++ b/www/utils/screenshot.ts @@ -1,6 +1,6 @@ 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 { 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 id = Deno.args[1];