KyleJuneK
Denoβ€’9mo agoβ€’
9 replies
KyleJune

Coverage for child processes

Does coverage not work for spawned child processes? I was trying to write an end to end test by spawning my server as a child process, but it seems like any code touched in that child process doesn't count towards coverage. Is there any way to get it to count?

In the following test case, I have it spawn my hono server, then wait for Deno.serve to start listening before it tries making a fetch request to the hono server. The test passes, showing that it was able to use the endpoint that returns "Hello, World!" text, but the coverage shows it as untouched since it is in a child process.

describe("serves application when running main", () => {
  it("should serve the application", async () => {
    const command = new Deno.Command(Deno.execPath(), {
      args: ["run", "-A", resolve(import.meta.dirname!, "./main.ts")],
      stdout: "piped",
      stderr: "piped",
    });
    await using child = command.spawn();
    const stdout = mergeReadableStreams(child.stdout, child.stderr)
      .pipeThrough(new TextDecoderStream())
      .pipeThrough(new TextLineStream());

    // Wait for server to start by monitoring stdout
    for await (const line of stdout) {
      if (line.includes("Listening on")) {
        break;
      }
    }

    const res = await fetch("http://localhost:8000/");
    assertEquals(res.status, 200);
    assertEquals(await res.text(), "Hello, World!");
  });
});
image.png
image.png
Was this page helpful?