Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 6x 10x 10x 10x 2x 10x 4x 1x 10x 10x 50x 30x 30x 20x 10x 10x 40x 10x 10x 30x 10x 10x 10x 10x 50x 20x 30x 10x 10x 10x 10x 50x 30x 20x 50x 1x 10x 10x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /* branches test cases */ const AssignmentPattern = require('./assignment.js'); const ConditionalExpression = require('./conditional.js'); const IfStatement = require('./if.js'); const LogicalExpression = require('./logical.js'); const SwitchStatement = require('./switch.js'); const SwitchStatementNoBreak = require('./switch-no-break.js'); const OptionalChaining = require('./optional-chaining.js'); const uncoveredFunction = (a) => { const list = [1, 2, 3, 4, 5]; list.forEach((v) => { console.log(v); }); if (a) { // both if and else path are uncovered console.log(a); } }; const logicalReturn = function(a) { if (a < 5 || a > 8) { console.log(a); } // same branch start const defaultArg = arguments.length > 1 && typeof arguments[1] !== 'undefined' ? arguments[1] : true; console.log(defaultArg); // test return count if (a < 3) { return; } // count will be left 10 - 2 = 8 /** multiple lines comments * for checking fixRangeStart */ // comments again if (a < 5 || a > 8) { console.log(a); } }; const listForEach = function(a) { const list = [1, 2, 3, 4, 5]; list.forEach((v) => { if (v > 2) { console.log(v); return; } console.log(v); }); if (!a) { // else path should be uncovered console.log(a); } for (const item of list) { if (item > 3) { console.log(item); break; } console.log(item); } }; function coveredFunction(a) { // branch count should be 10:0 not 1:0 const testCountWithFunName = a || 0; logicalReturn(a); // branches in a block statement for (let i = 0, j = 1; i < 5; i++) { if (i > 2) { console.log(i); } else if (i > 100) { uncoveredFunction(); } } listForEach(a); const l = 5; let i = 0; while (i < l) { if (i < 3) { console.log(i); } else { console.log(i); } i++; } } class MyCLass { static propTypes = 1; #privateField = 42; static #privateKey = 2; constructor(a) { // branch count should be 10:0 not 1:0 const testCountWithFunName = a || 0; this.myMethod(a); } myMethod(a) { } } function functionNeverMind(a) { if (a) { console.log(a); // not covered } } const branch = (a) => { let i = 0; while (i < 10) { coveredFunction(i + 1); new MyCLass(i + 1); i++; } if (a) { // else path should be covered functionNeverMind(a); } // multiple lines and operator after /* eslint-disable operator-linebreak */ if ( i || a || a + i ) { console.log('known issue: second line should be uncovered not partial'); } AssignmentPattern(); ConditionalExpression(); IfStatement(); LogicalExpression(); SwitchStatement(); SwitchStatementNoBreak(); OptionalChaining(); }; module.exports = { branch }; |