deno: `deno test --coverage` doesn't seem accurate
I have the following report for coverage for a function:
40 407 : export function parseInfo(s: string): DeliveryInfo {
41 501 : const tokens = s.split(".");
42 0 : if (tokens.length !== 9 && tokens[0] !== "$JS" && tokens[1] !== "ACK") {
43 0 : throw new Error(`not js message`);
44 0 : }
45 : // "$JS.ACK.<stream>.<consumer>.<redeliveryCount><streamSeq><deliverySequence>.<timestamp>.<pending>"
46 501 : const di = {} as DeliveryInfo;
47 501 : di.stream = tokens[2];
48 501 : di.consumer = tokens[3];
49 501 : di.redeliveryCount = parseInt(tokens[4], 10);
50 501 : di.streamSequence = parseInt(tokens[5], 10);
51 501 : di.deliverySequence = parseInt(tokens[6], 10);
52 501 : di.timestampNanos = parseInt(tokens[7], 10);
53 112 : di.pending = parseInt(tokens[8], 10);
54 507 : return di;
55 413 : }
Notice how lines 42:44 report zero coverage.
But elsewhere:
Deno.test("jsmsg - parse rejects subject is not 9 tokens", () => {
const fn = (s: string, ok: boolean) => {
try {
console.dir(s)
parseInfo(s);
if (!ok) {
fail(`${s} should have failed to parse`);
}
} catch (err) {
if (ok) {
fail(`${s} shouldn't have failed to parse: ${err.message}`);
}
}
};
const chunks = `$JS.ACK.stream.consumer.1.2.3.4.5`.split(".");
for (let i = 1; i <= chunks.length; i++) {
fn(chunks.slice(0, i).join("."), i === 9);
}
});
Clearly, the code is executed, so it should leave some sort of trace.
I wonder if there’s some sort of mismatch - my tests live in a tests directory, while the module is elsewhere.
Is it possible it is getting skewed by imports?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 22 (17 by maintainers)
I’ll try to get this done for 1.13 😃
@caspervonb yes it is in master
@caspervonb while looking at the repo may be a bit daunting, it isn’t. The only wrinkle is getting a build of the nats-server, but if you look at the GitHub actions, that will be much easier than you think. If you have
goinstalled, it is simply:I tried 1.8.1 before filing just to make sure the fix you just put there didn’t solve it.
@caspervonb - sure thing, how about this: https://gist.github.com/aricart/c383ef4739ad3b8385771c742c3d53b3