From 15067345edfc0a4f70c1583406db14694f607f59 Mon Sep 17 00:00:00 2001 From: fry69 <142489379+fry69@users.noreply.github.com> Date: Mon, 15 Sep 2025 22:31:07 +0200 Subject: [PATCH] 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 Co-authored-by: Emil Krebs <68400102+emilkrebs@users.noreply.github.com> Co-authored-by: Marvin Hagemeister --- www/main_test.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/www/main_test.ts b/www/main_test.ts index 36e7e729..63bf9cb6 100644 --- a/www/main_test.ts +++ b/www/main_test.ts @@ -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>; -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(