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