File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments