Coverage with subprocess
One of my tests involves spawning a subprocess. Is there any way to get this subprocess to participate in the overall code coverage runs? By default it seems to not be included. I mean that lines executed by the subprocess don't get logged.
8 Replies
You can use
DENO_UNSTABLE_COVERAGE_DIR
env var (though at your own risk since it's non public)And this should be set in the env property of the Deno.CommandOptions object I have? I tried this and I still couldn't generate coverage for my subprocess
{
args: ["run", "-A", "--unstable", name],
env: {
"DENO_UNSTABLE_COVERAGE_DIR": "cov",
},
}
is what i'm doing 🤷♂️
Oh sorry... my bad. That env var is only supported in
deno test
subcommand. So it actually won't work. Feel free to open an issue about it. Should be quite a straightfoward fixthanks for the hint (via it only working for
deno test
) this gave me the confidence to look into rust for the first time. i eventually got it working. this was significantly complicated by the way i was writing my test in typescript: i wasn't properly shutting down the server from Deno.serve, which prevented anything after this block
from finishing (e.g. collecting coverage in the worker). after rearranging the tests (which allowed the worker to properly exit), then my first rust changed showed its effect <:party_deno:1035517691517218847>
basically: serverProcess.kill("SIGTERM");
on the spawned subprocess is somehow too aggressive. instead of doing that after the test ends, i changed the way i launch the server to:
this has the downside of the test needing to finish in 10 seconds, but it at least allowed the coverage to complete. any explanation for this is appreciated. i will create a PR in the next few days for "allow DENO_UNSTABLE_COVERAGE_DIR in run subcommand"Ah great that it unblocked you. If you got it working for
deno run
make sure to open a PR 🙂cargo test
is failing even without my changes. What's the right channel to get help with this? I'd love to move forward with the PRIs it failing locally or on CI?
You can post in #dev
Locally. I'll give it another shot tomorrow and then reach out to that channel. If I get my tests sorted should I add you to the PR?