reed
reed13mo ago

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
bartlomieju
bartlomieju13mo ago
You can use DENO_UNSTABLE_COVERAGE_DIR env var (though at your own risk since it's non public)
reed
reed13mo ago
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 🤷‍♂️
bartlomieju
bartlomieju13mo ago
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 fix
reed
reed13mo ago
thanks 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
.worker
.run_event_loop(maybe_coverage_collector.is_none())
.await?;
.worker
.run_event_loop(maybe_coverage_collector.is_none())
.await?;
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:
const ac = new AbortController();
start(manifest, {
signal: ac.signal,
});
setTimeout(() => ac.abort(), 10000);
const ac = new AbortController();
start(manifest, {
signal: ac.signal,
});
setTimeout(() => ac.abort(), 10000);
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"
bartlomieju
bartlomieju13mo ago
Ah great that it unblocked you. If you got it working for deno run make sure to open a PR 🙂
reed
reed13mo ago
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 PR
bartlomieju
bartlomieju13mo ago
Is it failing locally or on CI? You can post in #dev
reed
reed13mo ago
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?