chore: speed up tests (#1791)

This PR speeds up tests by handling custom created `Requests` object
directly instead of binding a socket and making a real HTTP request. For
most tests this is fine, and for those that aren't the existing testing
methods are all preserved.
This commit is contained in:
Marvin Hagemeister
2023-09-18 18:44:22 +02:00
committed by GitHub
parent c76f15479f
commit 3850131063
12 changed files with 247 additions and 158 deletions
+7 -3
View File
@@ -91,6 +91,11 @@ interface StaticFile {
etag: string;
}
export type FromManifestOptions = FreshOptions & {
skipSnapshot?: boolean;
dev?: boolean;
};
export class ServerContext {
#dev: boolean;
#routes: Route[];
@@ -149,7 +154,7 @@ export class ServerContext {
*/
static async fromManifest(
manifest: Manifest,
opts: FreshOptions & { skipSnapshot?: boolean; dev?: boolean },
opts: FromManifestOptions,
): Promise<ServerContext> {
const dev = Deno.env.get("__FRSH_LEGACY_DEV") === "true" ||
Boolean(opts.dev);
@@ -907,9 +912,8 @@ export class ServerContext {
"%cAn error occurred during route handling or page rendering.",
"color:red",
);
let codeFrame: string | undefined = undefined;
if (this.#dev && error instanceof Error) {
codeFrame = await getCodeFrame(error);
const codeFrame = await getCodeFrame(error);
if (codeFrame) {
console.error();
+1
View File
@@ -1,6 +1,7 @@
import { LayoutConfig } from "$fresh/server.ts";
import { ComponentChildren } from "preact";
import { ServerContext } from "./context.ts";
export type { FromManifestOptions } from "./context.ts";
export { Status } from "./deps.ts";
import {
ErrorHandler,