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>
This commit is contained in:
fry69
2025-09-15 22:31:07 +02:00
committed by GitHub
co-authored by google-labs-jules[bot] Marvin Hagemeister Emil Krebs Marvin Hagemeister
parent de9b8a7c40
commit 15067345ed
+23 -11
View File
@@ -4,26 +4,38 @@ import {
} from "../packages/fresh/tests/test_utils.tsx";
import { expect } from "@std/expect";
import { retry } from "@std/async/retry";
import { buildVite } from "../packages/plugin-vite/tests/test_utils.ts";
import {
buildVite,
launchProd,
} from "../packages/plugin-vite/tests/test_utils.ts";
const result = await buildVite(import.meta.dirname!);
let result: Awaited<ReturnType<typeof buildVite>>;
Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
await withChildProcessServer(
{
cwd: result.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
async (address) => {
Deno.test.beforeAll(async () => {
result = await buildVite(import.meta.dirname!);
});
Deno.test.afterAll(async () => {
await result?.[Symbol.asyncDispose]();
});
Deno.test({
name: "CORS should not set on GET /fresh-badge.svg",
sanitizeOps: false,
sanitizeResources: false,
fn: async () => {
await launchProd({ cwd: result.tmp }, async (address) => {
const resp = await fetch(`${address}/fresh-badge.svg`);
await resp?.body?.cancel();
expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null);
},
);
});
},
});
Deno.test({
name: "shows version selector",
sanitizeOps: false,
sanitizeResources: false,
fn: async () => {
await retry(async () => {
await withChildProcessServer(