Skip to content

Commit 1506734

Browse files
fry69google-labs-jules[bot]marvinhagemeisteremilkrebs
authored
chore: resolve resource leak in www/main_test.ts (#3428)
The `buildVite` function returns a disposable object which was not being properly disposed of, leading to a resource leak warning in the test suite. This change wraps the tests in `www/main_test.ts` in an async function and uses `await using` to ensure that the temporary directory created by `buildVite` is cleaned up after the tests complete. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Marvin Hagemeister <marvin@deno.com> Co-authored-by: Emil Krebs <68400102+emilkrebs@users.noreply.github.com> Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
1 parent de9b8a7 commit 1506734

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

www/main_test.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,38 @@ import {
44
} from "../packages/fresh/tests/test_utils.tsx";
55
import { expect } from "@std/expect";
66
import { retry } from "@std/async/retry";
7-
import { buildVite } from "../packages/plugin-vite/tests/test_utils.ts";
7+
import {
8+
buildVite,
9+
launchProd,
10+
} from "../packages/plugin-vite/tests/test_utils.ts";
11+
12+
let result: Awaited<ReturnType<typeof buildVite>>;
813

9-
const result = await buildVite(import.meta.dirname!);
14+
Deno.test.beforeAll(async () => {
15+
result = await buildVite(import.meta.dirname!);
16+
});
17+
18+
Deno.test.afterAll(async () => {
19+
await result?.[Symbol.asyncDispose]();
20+
});
1021

11-
Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
12-
await withChildProcessServer(
13-
{
14-
cwd: result.tmp,
15-
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
16-
},
17-
async (address) => {
22+
Deno.test({
23+
name: "CORS should not set on GET /fresh-badge.svg",
24+
sanitizeOps: false,
25+
sanitizeResources: false,
26+
fn: async () => {
27+
await launchProd({ cwd: result.tmp }, async (address) => {
1828
const resp = await fetch(`${address}/fresh-badge.svg`);
1929
await resp?.body?.cancel();
2030
expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null);
21-
},
22-
);
31+
});
32+
},
2333
});
2434

2535
Deno.test({
2636
name: "shows version selector",
37+
sanitizeOps: false,
38+
sanitizeResources: false,
2739
fn: async () => {
2840
await retry(async () => {
2941
await withChildProcessServer(

0 commit comments

Comments
 (0)