tests: de-flake tests and re-enable sanitizers (#1786)

This commit is contained in:
Luca Casonato
2023-09-18 11:09:24 +02:00
committed by GitHub
parent c2a82e723e
commit 795836ed29
14 changed files with 89 additions and 185 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
deno: ["v1.x"] deno: ["canary"]
os: [macOS-latest, windows-latest, ubuntu-latest] os: [macOS-latest, windows-latest, ubuntu-latest]
include: include:
- os: ubuntu-latest - os: ubuntu-latest
+6 -2
View File
@@ -115,9 +115,11 @@ async function testBuild(
await browser.close(); await browser.close();
} }
} finally { } finally {
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
} }
}); });
@@ -137,9 +139,11 @@ async function testBuild(
"Restoring from snapshot message should not appear in dev mode", "Restoring from snapshot message should not appear in dev mode",
); );
} finally { } finally {
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
} }
}); });
} finally { } finally {
-1
View File
@@ -116,7 +116,6 @@ Deno.test({
await Deno.remove(tmpDirName, { recursive: true }); await Deno.remove(tmpDirName, { recursive: true });
}, },
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
+15 -9
View File
@@ -134,14 +134,15 @@ Deno.test({
await page.close(); await page.close();
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
await retry(() => Deno.remove(tmpDirName, { recursive: true })); await retry(() => Deno.remove(tmpDirName, { recursive: true }));
}, },
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -227,14 +228,15 @@ Deno.test({
await page.close(); await page.close();
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
await retry(() => Deno.remove(tmpDirName, { recursive: true })); await retry(() => Deno.remove(tmpDirName, { recursive: true }));
}, },
sanitizeResources: false,
}); });
Deno.test("fresh-init error(help)", async function (t) { Deno.test("fresh-init error(help)", async function (t) {
@@ -357,14 +359,15 @@ Deno.test({
await delay(100); await delay(100);
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
await retry(() => Deno.remove(tmpDirName, { recursive: true })); await retry(() => Deno.remove(tmpDirName, { recursive: true }));
}, },
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -405,9 +408,11 @@ Deno.test({
const doc = await fetchHtml(`${address}/env`); const doc = await fetchHtml(`${address}/env`);
assertTextMany(doc, "h1", ["true"]); assertTextMany(doc, "h1", ["true"]);
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
await t.step("build code and start server again", async () => { await t.step("build code and start server again", async () => {
@@ -435,12 +440,13 @@ Deno.test({
const doc = await fetchHtml(`${address}/env`); const doc = await fetchHtml(`${address}/env`);
assertTextMany(doc, "h1", ["true"]); assertTextMany(doc, "h1", ["true"]);
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
await retry(() => Deno.remove(tmpDirName, { recursive: true })); await retry(() => Deno.remove(tmpDirName, { recursive: true }));
}, },
sanitizeResources: false,
}); });
-63
View File
@@ -58,9 +58,6 @@ Deno.test({
}); });
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -88,9 +85,6 @@ Deno.test({
}); });
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
function withPage(fn: (page: Page, address: string) => Promise<void>) { function withPage(fn: (page: Page, address: string) => Promise<void>) {
@@ -122,9 +116,6 @@ Deno.test({
}); });
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -146,9 +137,6 @@ Deno.test({
await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now"); await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now");
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -176,9 +164,6 @@ Deno.test({
); );
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -193,9 +178,6 @@ Deno.test({
await page.waitForSelector(".added-by-use-effect"); await page.waitForSelector(".added-by-use-effect");
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -212,9 +194,6 @@ Deno.test({
assert(await page.waitForSelector("#browser-true")); assert(await page.waitForSelector("#browser-true"));
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -232,9 +211,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -252,9 +228,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -275,9 +248,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -298,9 +268,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -318,9 +285,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -343,9 +307,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -369,9 +330,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -391,9 +349,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -418,9 +373,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -439,9 +391,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -457,9 +406,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -475,9 +421,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -495,9 +438,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -560,9 +500,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test("throws when passing non-jsx children to an island", async (t) => { Deno.test("throws when passing non-jsx children to an island", async (t) => {
+3 -3
View File
@@ -39,10 +39,10 @@ Deno.test({
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
-3
View File
@@ -194,7 +194,4 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
+31 -43
View File
@@ -724,10 +724,7 @@ Deno.test({
}, },
}); });
Deno.test("jsx pragma works", { Deno.test("jsx pragma works", async (t) => {
sanitizeOps: false,
sanitizeResources: false,
}, async (t) => {
// Preparation // Preparation
const { serverProcess, lines, address } = await startFreshServer({ const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_jsx_pragma/main.ts"], args: ["run", "-A", "./tests/fixture_jsx_pragma/main.ts"],
@@ -756,15 +753,14 @@ Deno.test("jsx pragma works", {
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
Deno.test("preact/debug is active in dev mode", { Deno.test("preact/debug is active in dev mode", async (t) => {
sanitizeOps: false,
sanitizeResources: false,
}, async (t) => {
// Preparation // Preparation
const { serverProcess, lines, address } = await startFreshServer({ const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_render_error/main.ts"], args: ["run", "-A", "./tests/fixture_render_error/main.ts"],
@@ -794,15 +790,14 @@ Deno.test("preact/debug is active in dev mode", {
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
Deno.test("preloading javascript files", { Deno.test("preloading javascript files", async () => {
sanitizeOps: false,
sanitizeResources: false,
}, async () => {
// Preparation // Preparation
const { serverProcess, lines, address } = await startFreshServer({ const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture/main.ts"], args: ["run", "-A", "./tests/fixture/main.ts"],
@@ -843,16 +838,15 @@ Deno.test("preloading javascript files", {
} finally { } finally {
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
} }
}); });
Deno.test("PORT environment variable", { Deno.test("PORT environment variable", async () => {
sanitizeOps: false,
sanitizeResources: false,
}, async () => {
const PORT = "8765"; const PORT = "8765";
// Preparation // Preparation
const { serverProcess, lines } = await startFreshServer({ const { serverProcess, lines } = await startFreshServer({
@@ -866,27 +860,30 @@ Deno.test("PORT environment variable", {
await resp.body?.cancel(); await resp.body?.cancel();
assert(resp); assert(resp);
assertEquals(resp.status, Status.OK); assertEquals(resp.status, Status.OK);
await resp.body!.cancel();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
Deno.test("throw on route export 'handlers' instead of 'handler'", { Deno.test(
sanitizeOps: false, "throw on route export 'handlers' instead of 'handler'",
sanitizeResources: false, async () => {
}, async () => { const result = await new Deno.Command(Deno.execPath(), {
const result = await new Deno.Command(Deno.execPath(), { args: ["run", "-A", "./tests/fixture_invalid_handlers/main.ts"],
args: ["run", "-A", "./tests/fixture_invalid_handlers/main.ts"], stderr: "piped",
stderr: "piped", stdout: "piped",
stdout: "piped", }).output();
}).output();
assertEquals(result.code, 1); assertEquals(result.code, 1);
const text = new TextDecoder().decode(result.stderr); const text = new TextDecoder().decode(result.stderr);
assertMatch(text, /Did you mean "handler"\?/); assertMatch(text, /Did you mean "handler"\?/);
}); },
);
Deno.test("rendering custom _500.tsx page for default handlers", async (t) => { Deno.test("rendering custom _500.tsx page for default handlers", async (t) => {
await withFresh("./tests/fixture_custom_500/main.ts", async (address) => { await withFresh("./tests/fixture_custom_500/main.ts", async (address) => {
@@ -905,10 +902,7 @@ Deno.test("rendering custom _500.tsx page for default handlers", async (t) => {
}); });
}); });
Deno.test("renders error boundary", { Deno.test("renders error boundary", async () => {
sanitizeOps: false,
sanitizeResources: false,
}, async () => {
await withPageName("./tests/fixture/main.ts", async (page, address) => { await withPageName("./tests/fixture/main.ts", async (page, address) => {
await page.goto(`${address}/error_boundary`); await page.goto(`${address}/error_boundary`);
const text = await page.$eval("body", (el) => el.textContent); const text = await page.$eval("body", (el) => el.textContent);
@@ -978,9 +972,6 @@ Deno.test({
await waitForText(page, "p", "it works"); await waitForText(page, "p", "it works");
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -1010,9 +1001,6 @@ Deno.test({
}); });
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test("adds refresh script to html", async () => { Deno.test("adds refresh script to html", async () => {
+3 -3
View File
@@ -122,10 +122,10 @@ Deno.test({
await browser.close(); await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
-18
View File
@@ -20,9 +20,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -38,9 +35,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -62,9 +56,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -107,9 +98,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -127,9 +115,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -153,9 +138,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
-3
View File
@@ -16,7 +16,4 @@ Deno.test({
await waitForText(page, "#counter-2 p", "3"); await waitForText(page, "#counter-2 p", "3");
}); });
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
+21 -11
View File
@@ -166,12 +166,13 @@ export async function withFresh(
try { try {
await fn(address); await fn(address);
} finally { } finally {
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
// Wait until the process exits // Wait until the process exits
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
} }
} }
@@ -194,19 +195,20 @@ export async function withPageName(
await browser.close(); await browser.close();
} }
} finally { } finally {
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
// Wait until the process exits // Wait until the process exits
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
} }
} }
export async function startFreshServerExpectErrors( export async function startFreshServerExpectErrors(
options: Deno.CommandOptions, options: Deno.CommandOptions,
) { ) {
const { serverProcess, address } = await spawnServer(options, true); const { serverProcess, lines, address } = await spawnServer(options, true);
if (address) { if (address) {
throw Error("Server started correctly"); throw Error("Server started correctly");
@@ -222,6 +224,16 @@ export async function startFreshServerExpectErrors(
for await (const line of errorLines) { for await (const line of errorLines) {
output += line + "\n"; output += line + "\n";
} }
try {
serverProcess.kill("SIGTERM");
} catch {
// ignore the error, this may throw on windows if the process has already
// exited
}
await serverProcess.status;
for await (const _ of lines) { /* noop */ }
return output; return output;
} }
@@ -315,16 +327,14 @@ async function spawnServer(
stderr: expectErrors ? "piped" : "inherit", stderr: expectErrors ? "piped" : "inherit",
}).spawn(); }).spawn();
const decoder = new TextDecoderStream();
const lines: ReadableStream<string> = serverProcess.stdout const lines: ReadableStream<string> = serverProcess.stdout
.pipeThrough(decoder) .pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream(), { .pipeThrough(new TextLineStream());
preventCancel: true,
});
const output: string[] = []; const output: string[] = [];
let address = ""; let address = "";
for await (const line of lines) { // @ts-ignore yes it does
for await (const line of lines.values({ preventCancel: true })) {
output.push(line); output.push(line);
const match = line.match(/https?:\/\/localhost:\d+/g); const match = line.match(/https?:\/\/localhost:\d+/g);
if (match) { if (match) {
+4 -18
View File
@@ -22,25 +22,16 @@ async function setUpServer(path: string) {
* terminate server * terminate server
*/ */
const terminate = async () => { const terminate = async () => {
await lines.cancel();
await browser.close(); await browser.close();
serverProcess.kill("SIGKILL"); serverProcess.kill("SIGKILL");
await serverProcess.status; await serverProcess.status;
// TextDecoder leaks, so close it manually. // Drain the lines stream
const denoResourcesMap = new Map( for await (const _ of lines) { /* noop */ }
Object.entries(Deno.resources()).map(([rid, representation]) => {
return [representation, parseInt(rid)];
}),
);
const textDecoderRid = denoResourcesMap.get("textDecoder");
if (textDecoderRid != null) {
Deno.close(textDecoderRid);
}
}; };
return { page: page, terminate: terminate, address }; return { page: page, terminate, address };
} }
/** /**
@@ -312,8 +303,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
@@ -347,8 +336,6 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
// Test for: https://github.com/denoland/fresh/issues/1655 // Test for: https://github.com/denoland/fresh/issues/1655
@@ -370,9 +357,8 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
// Test for: https://github.com/denoland/fresh/issues/1655 // Test for: https://github.com/denoland/fresh/issues/1655
Deno.test("don't duplicate css class with twindV1", async () => { Deno.test("don't duplicate css class with twindV1", async () => {
await withFresh( await withFresh(
+5 -7
View File
@@ -5,9 +5,7 @@ import VERSIONS from "../versions.json" assert { type: "json" };
const dir = dirname(import.meta.url); const dir = dirname(import.meta.url);
Deno.test("CORS should not set on GET /fresh-badge.svg", { Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
sanitizeResources: false,
}, async () => {
const { serverProcess, lines, address } = await startFreshServer({ const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", join(dir, "./main.ts")], args: ["run", "-A", join(dir, "./main.ts")],
}); });
@@ -17,14 +15,14 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", {
assertEquals(res.headers.get("cross-origin-resource-policy"), null); assertEquals(res.headers.get("cross-origin-resource-policy"), null);
await lines.cancel();
serverProcess.kill("SIGTERM"); serverProcess.kill("SIGTERM");
await serverProcess.status; await serverProcess.status;
// Drain the lines stream
for await (const _ of lines) { /* noop */ }
}); });
Deno.test("shows version selector", { Deno.test("shows version selector", async () => {
sanitizeResources: false,
}, async () => {
await withPageName(join(dir, "./main.ts"), async (page, address) => { await withPageName(join(dir, "./main.ts"), async (page, address) => {
await page.goto(`${address}/docs`); await page.goto(`${address}/docs`);
await page.waitForSelector("#version"); await page.waitForSelector("#version");