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
+20 -18
View File
@@ -1,7 +1,12 @@
import { assert, assertEquals, assertMatch, delay, puppeteer } from "./deps.ts";
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
import { startFreshServer, withFresh, withPageName } from "./test_utils.ts";
import {
startFreshServer,
withFakeServe,
withFresh,
withPageName,
} from "./test_utils.ts";
/**
* Start the server with the main file.
@@ -339,24 +344,21 @@ Deno.test({
});
// Test for: https://github.com/denoland/fresh/issues/1655
Deno.test({
name: "don't duplicate css class",
async fn() {
await withFresh(
"./tests/fixture_twind_app/main.ts",
async (address) => {
const res = await fetch(`${address}/app_class`);
assertEquals(res.status, 200);
Deno.test("don't duplicate css class", async () => {
await withFakeServe(
"./tests/fixture_twind_app/main.ts",
async (server) => {
const res = await server.get(`/app_class`);
assertEquals(res.status, 200);
// Don't use an HTML parser here which would de-duplicate the
// class names automatically
const html = await res.text();
assertMatch(html, /html class="bg-slate-800">/);
assertMatch(html, /head class="bg-slate-800">/);
assertMatch(html, /body class="bg-slate-800">/);
},
);
},
// Don't use an HTML parser here which would de-duplicate the
// class names automatically
const html = await res.text();
assertMatch(html, /html class="bg-slate-800">/);
assertMatch(html, /head class="bg-slate-800">/);
assertMatch(html, /body class="bg-slate-800">/);
},
);
});
// Test for: https://github.com/denoland/fresh/issues/1655