Skip to content

Commit fc192d7

Browse files
committed
test: 🧪 add a low coverage file example for testing
1 parent 236be83 commit fc192d7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test-src/lowCoverage.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file has intentionally low coverage for testing purposes
2+
export function poorlyTestedFunction() {
3+
// This branch is never tested
4+
if (Math.random() > 0.5) {
5+
console.log("This will never be executed in tests");
6+
return "unreachable";
7+
}
8+
9+
// This is the only part that gets tested
10+
return "tested";
11+
}
12+
13+
export function anotherPoorlyTestedFunction() {
14+
// Multiple untested branches
15+
const value = Math.random();
16+
17+
if (value < 0.3) {
18+
console.log("Branch 1 - never tested");
19+
return "branch1";
20+
} else if (value < 0.6) {
21+
console.log("Branch 2 - never tested");
22+
return "branch2";
23+
} else if (value < 0.9) {
24+
console.log("Branch 3 - never tested");
25+
return "branch3";
26+
} else {
27+
console.log("Branch 4 - never tested");
28+
return "branch4";
29+
}
30+
}
31+
32+
export function untestedFunction() {
33+
// This function is never called in tests
34+
return "completely untested";
35+
}

test-src/lowCoverage.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, test, expect } from "vitest";
2+
import { poorlyTestedFunction } from "./lowCoverage.js";
3+
4+
describe("Low Coverage Tests", () => {
5+
test("should return tested for the main path", () => {
6+
// This only tests the main return path, not the if branch
7+
expect(poorlyTestedFunction()).toBe("tested");
8+
});
9+
10+
// Intentionally not testing:
11+
// - The if branch in poorlyTestedFunction
12+
// - anotherPoorlyTestedFunction (completely untested)
13+
// - untestedFunction (completely untested)
14+
});

0 commit comments

Comments
 (0)