Coverage

90%
40
36
4

/Users/alexsouthern/Dropbox/blanket/lib/blanket.js

89%
39
35
4
LineHitsSource
11var parseAndModify = (typeof exports === 'undefined' ? window.falafel : require("/Users/alexsouthern/Dropbox/blanket/lib/./falafel").falafel);
2
31(typeof exports === 'undefined' ? window : exports).blanket = (function(){
41 var linesToAddTracking = [
5 "ExpressionStatement",
6 "LabeledStatement" ,
7 "BreakStatement" ,
8 "ContinueStatement" ,
9 "VariableDeclaration",
10 "ReturnStatement" ,
11 "ThrowStatement" ,
12 "Line",
13 "TryStatement" ,
14 "FunctionDeclaration" ,
15 "IfStatement" ,
16 "WhileStatement" ,
17 "DoWhileStatement" ,
18 "ForStatement" ,
19 "ForInStatement" ,
20 "SwitchStatement" ,
21 "WithStatement"
22 ],
23 linesToAddBrackets = [
24 "IfStatement" ,
25
26 "WhileStatement" ,
27 "DoWhileStatement" ,
28 "ForStatement" ,
29 "ForInStatement" ,
30 "WithStatement"
31 ],
32 covVar = (typeof window === 'undefined' ? "_$jscoverage" : "window._$blanket" ),
33 blanket = {
34 loadOnly: "",
35 instrument: function(config, next){
362 var inFile = config.inputFile,
37 inFileName = config.inputFileName;
382 var sourceArray = this._prepareSource(inFile);
392 blanket._trackingArraySetup=[];
402 var instrumented = parseAndModify(inFile,{loc:true,comment:true}, this._addTracking,inFileName);
412 instrumented = this._trackingSetup(inFileName,sourceArray)+instrumented;
422 next(instrumented);
43 },
44 _trackingArraySetup: [],
45 _prepareSource: function(source){
463 return source.replace(/'/g,"\'").replace(/( | | )/gm," ").split(' ');
47 },
48 _trackingSetup: function(filename,sourceArray){
49
503 var sourceString = sourceArray.join("', '");
513 var intro = "if (typeof "+covVar+" === 'undefined') "+covVar+" = {}; ";
523 intro += "if (typeof "+covVar+"['"+filename+"'] === 'undefined'){";
53
543 intro += covVar+"['"+filename+"']=[]; ";
553 intro += covVar+"['"+filename+"'].source=['"+sourceString+"']; ";
561 //initialize array values
573 blanket._trackingArraySetup.sort().forEach(function(item){
5812 intro += covVar+"['"+filename+"']["+item+"]=0; ";
59 });
60
613 intro += "}";
623 return intro;
63 },
64 _blockifyIf: function(node){
65
6687 if (linesToAddBrackets.indexOf(node.type) > -1){
677 var bracketsExistObject = node.consequent || node.body;
687 var bracketsExistAlt = node.alternate;
697 if( bracketsExistAlt && bracketsExistAlt.type != "BlockStatement") {
702 bracketsExistAlt.update("{ "+bracketsExistAlt.source()+"} ");
71 }
727 if( bracketsExistObject && bracketsExistObject.type != "BlockStatement") {
736 bracketsExistObject.update("{ "+bracketsExistObject.source()+"} ");
74 }
75 }
76 },
77 _addTracking: function (node,filename) {
7887 blanket._blockifyIf(node);
7987 if (linesToAddTracking.indexOf(node.type) > -1){
8023 if (node.type == "VariableDeclaration" &&
81 (node.parent.type == "ForStatement" || node.parent.type == "ForInStatement")){
820 return;
83 }
8423 if (node.loc && node.loc.start){
8523 node.update(covVar+"['"+filename+"']["+node.loc.start.line+"]++; "+node.source());
8623 blanket._trackingArraySetup.push(node.loc.start.line);
87 }else{
881 //I don't think we can handle a node with no location
890 throw new Error("The instrumenter encountered a node with no location: "+Object.keys(node));
90 }
91
92 }
93 },
94 report: function(coverage_data){
950 coverage_data.files = (typeof window === 'undefined' ? _$jscoverage : window._$blanket );
960 Reporter(coverage_data);
97 }
98 };
991 return blanket;
100})();
101
102
103

testfile2

100%
1
1
0
LineHitsSource
15var a=3;if(a==1)a=2;else if(a==3){a=4;}result=a;