Best JavaScript code snippet using istanbul
test-if.js
Source:test-if.js
1/*jslint nomen: true */2var helper = require('../helper'),3 code,4 verifier;5/*jshint maxlen: 500 */6module.exports = {7 "with a simple if": {8 "as a statement": {9 setUp: function (cb) {10 code = [11 'output = -1;',12 'if (args[0] > args [1])',13 ' output = args[0];'14 ];15 verifier = helper.verifier(__filename, code);16 cb(null);17 },18 "should cover then path": function (test) {19 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });20 test.done();21 },22 "should cover else path": function (test) {23 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1, 3: 0 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });24 test.done();25 }26 },27 "as a block": {28 setUp: function (cb) {29 code = [30 'output = -1;',31 'if (args[0] > args [1]) {',32 ' output = args[0];',33 '}'34 ];35 verifier = helper.verifier(__filename, code);36 cb();37 },38 "should cover then path": function (test) {39 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });40 test.done();41 },42 "should cover else path": function (test) {43 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1, 3: 0 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });44 test.done();45 }46 },47 "on a single line": {48 "as statement": {49 setUp: function (cb) {50 code = [51 'output = -1;',52 'if (args[0] > args [1]) output = args[0];'53 ];54 verifier = helper.verifier(__filename, code);55 cb();56 },57 "should cover then path": function (test) {58 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });59 test.done();60 },61 "should cover else path": function (test) {62 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });63 test.done();64 }65 },66 "as block": {67 setUp: function (cb) {68 code = [69 'output = -1;',70 'if (args[0] > args [1]) { output = args[0]; }'71 ];72 verifier = helper.verifier(__filename, code);73 cb();74 },75 "should cover then path": function (test) {76 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });77 test.done();78 },79 "should cover else path": function (test) {80 verifier.verify(test, [ 10, 20 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });81 test.done();82 }83 }84 }85 },86 "with a simple if-else": {87 "as a statement": {88 setUp: function (cb) {89 code = [90 'if (args[0] > args [1])',91 ' output = args[0];',92 'else',93 ' output = args[1];'94 ];95 verifier = helper.verifier(__filename, code);96 cb(null);97 },98 "should cover then path": function (test) {99 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 4: 0 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });100 test.done();101 },102 "should cover else path": function (test) {103 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1, 2: 0, 4: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });104 test.done();105 }106 },107 "as a block": {108 setUp: function (cb) {109 code = [110 'if (args[0] > args [1]) {',111 ' output = args[0];',112 '} else {',113 ' output = args[1];',114 '}'115 ];116 verifier = helper.verifier(__filename, code);117 cb();118 },119 "should cover then path": function (test) {120 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1, 2: 1, 4: 0 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });121 test.done();122 },123 "should cover else path": function (test) {124 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1, 2: 0, 4: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });125 test.done();126 }127 },128 "on a single line": {129 "as statement": {130 setUp: function (cb) {131 code = [132 'if (args[0] > args [1]) output = args[0]; else output = args[1];'133 ];134 verifier = helper.verifier(__filename, code);135 cb();136 },137 "should cover then path": function (test) {138 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });139 test.done();140 },141 "should cover else path": function (test) {142 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });143 test.done();144 }145 },146 "as block": {147 setUp: function (cb) {148 code = [149 'if (args[0] > args [1]) { output = args[0]; } else { output = args[1]; }'150 ];151 verifier = helper.verifier(__filename, code);152 cb();153 },154 "should cover then path": function (test) {155 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });156 test.done();157 },158 "should cover else path": function (test) {159 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });160 test.done();161 }162 },163 "as mixed with then-block": {164 setUp: function (cb) {165 code = [166 'if (args[0] > args [1]) { output = args[0]; } else output = args[1];'167 ];168 verifier = helper.verifier(__filename, code);169 cb();170 },171 "should cover then path": function (test) {172 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });173 test.done();174 },175 "should cover else path": function (test) {176 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });177 test.done();178 }179 },180 "as mixed with else-block": {181 setUp: function (cb) {182 code = [183 'if (args[0] > args [1]) output = args[0]; else { output = args[1]; }'184 ];185 verifier = helper.verifier(__filename, code);186 cb();187 },188 "should cover then path": function (test) {189 verifier.verify(test, [ 20, 10 ], 20, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0 } });190 test.done();191 },192 "should cover else path": function (test) {193 verifier.verify(test, [ 10, 20 ], 20, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1 } });194 test.done();195 }196 }197 }198 },199 "with nested ifs": {200 "without an else": {201 "and no blocks": {202 setUp: function (cb) {203 code = [204 'output = -1;',205 'if (args[0] > args[1]) if (args[1] > args[2]) output = args[2];'206 ];207 verifier = helper.verifier(__filename, code);208 cb();209 },210 "should cover first else and nothing below": function (test) {211 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0 } });212 test.done();213 },214 "should cover first then": function (test) {215 verifier.verify(test, [ 20, 10, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0 } });216 test.done();217 },218 "should cover first then and second then": function (test) {219 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });220 test.done();221 }222 },223 "and blocks": {224 setUp: function (cb) {225 code = [226 'output = -1;',227 'if (args[0] > args[1]) { if (args[1] > args[2]) { output = args[2]; } }'228 ];229 verifier = helper.verifier(__filename, code);230 cb();231 },232 "should cover first else and nothing below": function (test) {233 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0 } });234 test.done();235 },236 "should cover first then": function (test) {237 verifier.verify(test, [ 20, 10, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0 } });238 test.done();239 },240 "should cover first then and second then": function (test) {241 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });242 test.done();243 }244 }245 },246 "with elses": {247 "and no blocks": {248 setUp: function (cb) {249 code = [250 'output = -1;',251 'if (args[0] > args[1]) if (args[1] > args[2]) output = args[2]; else output = args[1];'252 ];253 verifier = helper.verifier(__filename, code);254 cb();255 },256 "should cover first else and nothing below": function (test) {257 verifier.verify(test, [ 10, 20, 15 ], -1, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0 } });258 test.done();259 },260 "should cover first then": function (test) {261 verifier.verify(test, [ 20, 10, 15 ], 10, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 1 } });262 test.done();263 },264 "should cover first then and second then": function (test) {265 verifier.verify(test, [ 20, 10, 5 ], 5, { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 0 } });266 test.done();267 }268 },269 "including else ifs with blocks": {270 setUp: function (cb) {271 code = [272 'if (args[0] < args[1]) {',273 ' output = args[0];',274 '} else if (args[1] < args[2]) {',275 ' output = args[1];',276 '} else if (args[2] < args[3]) {',277 ' output = args[2];',278 '} else {',279 ' output = args[3];',280 '}'281 ];282 verifier = helper.verifier(__filename, code);283 cb();284 },285 "should cover all else paths": function (test) {286 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0, 8: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });287 test.done();288 },289 "should cover one then path": function (test) {290 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });291 test.done();292 },293 "should cover upper then paths": function (test) {294 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });295 test.done();296 },297 "should cover uppermost then paths": function (test) {298 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });299 test.done();300 }301 },302 "including else ifs without blocks": {303 setUp: function (cb) {304 code = [305 'if (args[0] < args[1])',306 ' output = args[0];',307 'else if (args[1] < args[2])',308 ' output = args[1];',309 'else if (args[2] < args[3])',310 ' output = args[2];',311 'else',312 ' output = args[3];'313 ];314 verifier = helper.verifier(__filename, code);315 cb();316 },317 "should cover all else paths": function (test) {318 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0, 8: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });319 test.done();320 },321 "should cover one then path": function (test) {322 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });323 test.done();324 },325 "should cover upper then paths": function (test) {326 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });327 test.done();328 },329 "should cover uppermost then paths": function (test) {330 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0, 8: 0 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });331 test.done();332 }333 },334 "including else ifs without blocks (compact)": {335 setUp: function (cb) {336 code = [337 'if (args[0] < args[1]) output = args[0]; else if (args[1] < args[2]) output = args[1]; else if (args[2] < args[3]) output = args[2]; else output = args[3];'338 ];339 verifier = helper.verifier(__filename, code);340 cb();341 },342 "should cover all else paths": function (test) {343 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 0, '7': 1 } });344 test.done();345 },346 "should cover one then path": function (test) {347 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0 } });348 test.done();349 },350 "should cover upper then paths": function (test) {351 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });352 test.done();353 },354 "should cover uppermost then paths": function (test) {355 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0 } });356 test.done();357 }358 },359 "including else ifs without blocks (modified)": {360 setUp: function (cb) {361 code = [362 'output = args[3]; if (args[0] < args[1])',363 ' output = args[0];',364 'else if (args[1] < args[2])',365 ' output = args[1];',366 'else if (args[2] < args[3])',367 ' output = args[2];'368 ];369 verifier = helper.verifier(__filename, code);370 cb();371 },372 "should cover all else paths": function (test) {373 verifier.verify(test, [ 4, 3, 2, 1 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 0, '6': 1, '7': 0 } });374 test.done();375 },376 "should cover one then path": function (test) {377 verifier.verify(test, [ 4, 3, 1, 2 ], 1, { lines: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1 }, branches: { '1': [ 0, 1 ], '2' : [ 0, 1 ], '3': [ 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 0, '6': 1, '7': 1 } });378 test.done();379 },380 "should cover upper then paths": function (test) {381 verifier.verify(test, [ 4, 2, 3, 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 4: 1, 5: 0, 6: 0 }, branches: { '1': [ 0, 1 ], '2' : [ 1, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 1, '6': 0, '7': 0 } });382 test.done();383 },384 "should cover uppermost then paths": function (test) {385 verifier.verify(test, [ 1, 2, 3, 1 ], 1, { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0 }, branches: { '1': [ 1, 0 ], '2' : [ 0, 0 ], '3': [ 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 0, '6': 0, '7': 0 } });386 test.done();387 }388 }389 }390 }...
test-statement.js
Source:test-statement.js
1/*jslint nomen: true */2var helper = require('../helper'),3 Instrumenter = require('../../lib/instrumenter'),4 code,5 verifier;6module.exports = {7 "with a simple statement": {8 setUp: function (cb) {9 code = [10 'var x = args[0] > 5 ? args[0] : "undef";',11 'output = x;'12 ];13 verifier = helper.verifier(__filename, code);14 cb();15 },16 "should cover line and one branch": function (test) {17 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });18 test.done();19 },20 "should cover line and other branch": function (test) {21 verifier.verify(test, [ 1 ], "undef", { lines: { 1: 1, 2: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });22 test.done();23 }24 },25 "with no filename": {26 setUp: function (cb) {27 code = [28 'output = args[0];'29 ];30 verifier = helper.verifier(null, code, { debug: true, walkDebug: true });31 cb();32 },33 "should not barf in setup": function (test) {34 verifier.verify(test, [ 1 ], 1, { lines: { 1: 1 }, branches: {}, functions: {}, statements: { 1: 1 } });35 test.done();36 }37 },38 "with a windows style file path": {39 setUp: function (cb) {40 code = [41 'var x = args[0] > 5 ? args[0] : "undef";',42 'output = x;'43 ];44 verifier = helper.verifier("c:\\a\\b\\c\\d\\e.js", code);45 cb();46 },47 "should have correct key in coverage variable": function (test) {48 verifier.verify(test, [ 1 ], "undef", { lines: { 1: 1, 2: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });49 var coverage = verifier.getCoverage(),50 key = Object.keys(coverage)[0];51 test.equals("c:\\a\\b\\c\\d\\e.js", key);52 test.done();53 }54 },55 "with junk code": {56 setUp: function (cb) {57 code = [58 'output = args[0] : 1 : 2;'59 ];60 verifier = helper.verifier(null, code, { debug: true, walkDebug: true });61 cb();62 },63 "should have verification errors": function (test) {64 verifier.verifyError(test);65 test.done();66 }67 },68 "with code that is not a string": {69 "should have verification errors": function (test) {70 test.throws(function () {71 var instrumenter = new Instrumenter();72 instrumenter.instrumentSync({}, 'foo.js');73 }, Error, 'Code must be a string');74 test.done();75 }76 },77 "with shebang code": {78 setUp: function (cb) {79 code = [80 '#!/usr/bin/env node',81 'var x = args[0] > 5 ? args[0] : "undef";',82 'output = x;'83 ];84 verifier = helper.verifier(__filename, code);85 cb();86 },87 "should cover line and one branch": function (test) {88 verifier.verify(test, [ 10 ], 10, { lines: { 2: 1, 3: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });89 test.done();90 },91 "should cover line and other branch": function (test) {92 verifier.verify(test, [ 1 ], "undef", { lines: { 2: 1, 3: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });93 test.done();94 }95 },96 "with source code packed in": {97 setUp: function (cb) {98 code = [99 'var x = args[0] > 5 ? args[0] : "undef";',100 'output = x;'101 ];102 verifier = helper.verifier(__filename, code, { embedSource: true, coverageVariable: null });103 cb();104 },105 "coverage should have code packed in": function (test) {106 verifier.verifyNoError(test);107 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });108 var cov = verifier.getCoverage(),109 fileCov = cov[Object.keys(cov)[0]];110 test.ok(fileCov.code);111 test.done();112 }113 },114 "with code having a return statement on mainline": {115 setUp: function (cb) {116 code = [117 'return 10;'118 ];119 verifier = helper.verifier(__filename, code);120 cb();121 },122 "should pass coverage": function (test) {123 verifier.verifyNoError(test);124 test.done();125 }126 },127 "with code having a return statement on mainline and no autowrap": {128 setUp: function (cb) {129 code = [130 'return 10;'131 ];132 verifier = helper.verifier(__filename, code, { noAutoWrap: true });133 cb();134 },135 "should fail coverage": function (test) {136 verifier.verifyError(test);137 test.done();138 }139 },140 "with no mainline returns and no autowrap": {141 setUp: function (cb) {142 code = [143 '#!/usr/bin/env node',144 'var x = args[0] > 5 ? args[0] : "undef";',145 'output = x;'146 ];147 verifier = helper.verifier(__filename, code, { noAutoWrap: true });148 cb();149 },150 "should cover line and one branch": function (test) {151 verifier.verify(test, [ 10 ], 10, { lines: { 2: 1, 3: 1 }, branches: { 1: [1, 0 ]}, functions: {}, statements: { 1: 1, 2: 1 } });152 test.done();153 },154 "should cover line and other branch": function (test) {155 verifier.verify(test, [ 1 ], "undef", { lines: { 2: 1, 3: 1 }, branches: { 1: [ 0, 1 ]}, functions: {}, statements: { 1: 1, 2: 1 } });156 test.done();157 }158 }...
verifierdb.py
Source:verifierdb.py
...54 (N, g, salt, verifier) = value55 x = mathtls.makeX(salt, username, param)56 v = powMod(g, x, N)57 return (verifier == v)58 def makeVerifier(username, password, bits):59 """Create a verifier entry which can be stored in a VerifierDB.60 @type username: str61 @param username: The username for this verifier. Must be less62 than 256 characters in length.63 @type password: str64 @param password: The password for this verifier.65 @type bits: int66 @param bits: This values specifies which SRP group parameters67 to use. It must be one of (1024, 1536, 2048, 3072, 4096, 6144,68 8192). Larger values are more secure but slower. 2048 is a69 good compromise between safety and speed.70 @rtype: tuple71 @return: A tuple which may be stored in a VerifierDB.72 """73 usernameBytes = bytearray(username, "utf-8")74 passwordBytes = bytearray(password, "utf-8")75 return mathtls.makeVerifier(usernameBytes, passwordBytes, bits)...
Using AI Code Generation
1var istanbul = require('istanbul');2var verifier = new istanbul.Verifier();3verifier.addFile('coverage/coverage.json');4verifier.verify({5}, function (err, passed) {6 if (passed) {7 console.log('Code coverage passed');8 } else {9 console.log('Code coverage failed');10 }11});12var istanbul = require('istanbul');13var verifier = new istanbul.Verifier();14verifier.verifyFile('coverage/coverage.json', 'app.js', {15}, function (err, passed) {16 if (passed) {17 console.log('Code coverage passed');18 } else {19 console.log('Code coverage failed');20 }21});
Using AI Code Generation
1var Verifier = require('istanbul').Verifier;2var collector = new istanbul.Collector();3var reporter = new istanbul.Reporter();4var sync = false;5collector.add(coverage);6var config = istanbul.config.loadFile('config.json');7Verifier.loadConfig(config).verify(collector, function (err, report) {8 if (err) {9 console.log(err);10 } else {11 console.log(report);12 }13});14reporter.add('text');15reporter.addAll([ 'lcov', 'json' ]);16reporter.write(collector, sync, function () {17 console.log('Reports generated');18});19{20 "check": {21 "global": {22 }23 }24}
Using AI Code Generation
1var istanbul = require('istanbul');2var instrumenter = new istanbul.Instrumenter();3var code = 'var x = 1 + 1';4var instrumentedCode = instrumenter.instrumentSync(code, 'test.js');5var istanbul = require('istanbul');6var instrumenter = new istanbul.Instrumenter();7var code = 'var x = 1 + 1';8var instrumentedCode = instrumenter.instrumentSync(code, 'test2.js');9var istanbul = require('istanbul');10var instrumenter = new istanbul.Instrumenter();11var code = 'var x = 1 + 1';12var instrumentedCode = instrumenter.instrumentSync(code, 'test3.js');13var istanbul = require('istanbul');14var instrumenter = new istanbul.Instrumenter();15var code = 'var x = 1 + 1';16var instrumentedCode = instrumenter.instrumentSync(code, 'test4.js');17var istanbul = require('istanbul');18var instrumenter = new istanbul.Instrumenter();19var code = 'var x = 1 + 1';20var instrumentedCode = instrumenter.instrumentSync(code, 'test5.js');21var istanbul = require('istanbul');22var instrumenter = new istanbul.Instrumenter();23var code = 'var x = 1 + 1';24var instrumentedCode = instrumenter.instrumentSync(code, 'test6.js');25var istanbul = require('istanbul');26var instrumenter = new istanbul.Instrumenter();27var code = 'var x = 1 + 1';28var instrumentedCode = instrumenter.instrumentSync(code, 'test7.js');29var istanbul = require('istanbul
Using AI Code Generation
1var istanbul = require('istanbul');2var Verifier = istanbul.Verifier;3var verifier = new Verifier();4var istanbul = require('istanbul');5var Report = istanbul.Report;6var report = new Report();7var istanbul = require('istanbul');8var ReportCollector = istanbul.ReportCollector;9var reportCollector = new ReportCollector();10var istanbul = require('istanbul');11var Store = istanbul.Store;12var store = new Store();13var istanbul = require('istanbul');14var Template = istanbul.Template;15var template = new Template();16var istanbul = require('istanbul');17var TreeSummarizer = istanbul.TreeSummarizer;18var treeSummarizer = new TreeSummarizer();19var istanbul = require('istanbul');20var utils = istanbul.utils;21var istanbul = require('istanbul');22var Visitor = istanbul.Visitor;23var visitor = new Visitor();24var istanbul = require('istanbul');25var hook = istanbul.lib.hook;26var istanbul = require('istanbul');27var report = istanbul.lib.report;28var istanbul = require('istanbul');29var collector = istanbul.lib.collector;30var istanbul = require('istanbul');31var instrumenter = istanbul.lib.instrumenter;32var istanbul = require('istanbul');33var collector = istanbul.lib.collector;34var istanbul = require('istanbul');35var report = istanbul.lib.report;
Using AI Code Generation
1var istanbul = require('istanbul');2var path = require('path');3var verifier = new istanbul.Instrumenter.Verifier();4var map = JSON.parse(fs.readFileSync('coverage/coverage-final.json', 'utf8'));5verifier.verify(map, path.resolve('src'), function (error) {6 if (error) {7 console.log('Code coverage check failed:', error);8 process.exit(1);9 } else {10 console.log('Code coverage check passed!');11 }12});
Using AI Code Generation
1var istanbul = require('istanbul');2var verifier = new istanbul.Reporter.Verifier();3verifier.addReporter('text-summary');4verifier.verify(5 {6 },7 function (err) {8 }9);
Using AI Code Generation
1var Verifier = require('istanbul').Verifier;2var verifier = new Verifier();3var report = require('./coverage/coverage.json');4verifier.addReporter('text');5verifier.verify(report, {pct: 90}, function (err) {6 if (err) {7 console.log('Failed to meet coverage threshold: ' + err);8 process.exit(1);9 }10 console.log('Coverage threshold met');11});12module.exports = function(config) {13 config.set({14 preprocessors: {15 },16 coverageReporter: {17 }18 });19};20import { expect } from 'chai';21import { sum } from '../src';22describe('sum', () => {23 it('should return the sum of two numbers', () => {24 const result = sum(1, 2);25 expect(result).to.equal(3);26 });27});28module.exports = function(grunt) {29 grunt.initConfig({30 mochaTest: {31 test: {32 options: {33 },34 }35 },36 istanbul: {37 coverage: {38 options: {
Using AI Code Generation
1var istanbul = require('istanbul');2var verifier = new istanbul.Verifier();3verifier.addFile('coverage/coverage.json');4verifier.verify()5 .then(function (report) {6 console.log(report);7 })8 .catch(function (err) {9 console.log(err);10 });11"scripts": {12 }13var aws = require('aws-sdk');14var multer = require('multer');
Using AI Code Generation
1var istanbul = require('istanbul-middleware');2var verifier = new istanbul.Verifier();3verifier.addFile('path/to/your/coverage/file.json');4var istanbul = require('istanbul-middleware');5var report = new istanbul.Report();6report.addFile('path/to/your/coverage/file.json');7var istanbul = require('istanbul-middleware');8var report = new istanbul.Report();9report.addFile('path/to/your/coverage/file.json', {statements: 90});10var istanbul = require('istanbul-middleware');11var report = new istanbul.Report();12report.addFile('path/to/your/coverage/file.json', {statements: 90, branches: 90, lines: 90, functions: 90});13var istanbul = require('istanbul-middleware');14var report = new istanbul.Report();15report.addFile('path/to/your/coverage/file.json', {statements: 90, branches: 90, lines: 90, functions: 90}, 'text-summary');16var istanbul = require('istanbul-middleware');17var report = new istanbul.Report();18report.addFile('path/to/your/coverage/file.json', {statements: 90, branches: 90, lines: 90, functions: 90}, ['text-summary', 'html']);19var istanbul = require('istanbul-middleware');20var report = new istanbul.Report();21report.addFile('path/to/your/coverage/file.json', {statements: 90, branches: 90, lines: 90, functions: 90}, ['text-summary', 'html'], 'test/coverage');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!