fix: flaky doesn't leak data across renderers test (#1901)
Using `createHandler()` is simpler than starting a server and fetching a page. `createHandler()` avoids unnecessary network requests, which can be flaky when you only need to analyse parts of the returned request. I think we should push for more use of `createHandler()` and only start a server as a last resort. This closes #1896, or rather the particular test mentioned there, but other tests involving TCP connections can still occur. Again, their remedy is to use `createHandler()` instead of starting a server.
This commit is contained in:
+22
-22
@@ -1,28 +1,28 @@
|
|||||||
import {
|
import { assertSelector, parseHtml } from "$fresh/tests/test_utils.ts";
|
||||||
assertSelector,
|
|
||||||
fetchHtml,
|
|
||||||
withFresh,
|
|
||||||
} from "$fresh/tests/test_utils.ts";
|
|
||||||
import { assertEquals } from "$std/testing/asserts.ts";
|
import { assertEquals } from "$std/testing/asserts.ts";
|
||||||
|
import { createHandler } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fixture/fresh.gen.ts";
|
||||||
|
import options from "./fixture/options.ts";
|
||||||
|
|
||||||
|
const handler = await createHandler(manifest, options);
|
||||||
|
|
||||||
|
// Issue: https://github.com/denoland/fresh/issues/1636
|
||||||
Deno.test("doesn't leak data across renderers", async () => {
|
Deno.test("doesn't leak data across renderers", async () => {
|
||||||
// Issue: https://github.com/denoland/fresh/issues/1636
|
async function load(name: string) {
|
||||||
await withFresh("./tests/fixture/main.ts", async (address) => {
|
const req = new Request(`http://localhost/admin/${name}`);
|
||||||
function load(name: string) {
|
const resp = await handler(req);
|
||||||
return fetchHtml(`${address}/admin/${name}`).then((doc) => {
|
const doc = parseHtml(await resp.text());
|
||||||
assertSelector(doc, "#__FRSH_STATE");
|
|
||||||
const text = doc.querySelector("#__FRSH_STATE")?.textContent!;
|
|
||||||
const json = JSON.parse(text);
|
|
||||||
assertEquals(json, { "v": [[{ "site": name }], []] });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const promises: Promise<void>[] = [];
|
assertSelector(doc, "#__FRSH_STATE");
|
||||||
for (let i = 0; i < 100; i++) {
|
const text = doc.querySelector("#__FRSH_STATE")?.textContent!;
|
||||||
promises.push(load("foo"));
|
const json = JSON.parse(text);
|
||||||
promises.push(load("bar"));
|
assertEquals(json, { "v": [[{ "site": name }], []] });
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
const promises = [];
|
||||||
});
|
for (let i = 0; i < 100; i++) {
|
||||||
|
promises.push(load("foo"));
|
||||||
|
promises.push(load("bar"));
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user