If I write test case like the below:
Deno.test.beforeAll(async () => {
const serverStarted = Promise.withResolvers();
Deno.serve({ onListen: serverStarted.resolve }, () => {
return new Response("some fixture response");
});
await serverStarted.promise;
});
Deno.test("some test using fixture server", async () => {
const resp = await fetch("http://localhost:8000/");
const text = await resp.text();
if (text !== "some fixture response") {
throw new Error(`Unexpected response: ${text}`);
}
});
The sanitizer reports these leaks:
error: Leaks detected:
- An async call to op_http_wait was started before the test, but completed during the test. Async operations should not complete in a test if they were not started in that test.
- An async call to op_http_wait was started in this test, but never completed.
To get more details where leaks occurred, run again with the --trace-leaks flag.
This seems to be the correct behavior of the sanitizer, but it also means that Deno.serve cannot be used inside Deno.test.beforeAll.
Since starting a web server as a fixture is a common need in testing, can we somehow enable this pattern to work without op leak detected?