Coverage

77%
75
58
17

/Users/alexsouthern/Dropbox/blanket/src/blanket.js

77%
74
57
17
LineHitsSource
11var parseAndModify = (typeof exports === 'undefined' ? window.falafel : require("/Users/alexsouthern/Dropbox/blanket/src/./lib/falafel").falafel);
2
31function copy(o){
40 var _copy = Object.create( Object.getPrototypeOf(o) );
50 var propNames = Object.getOwnPropertyNames(o);
6
70 propNames.forEach(function(name){
80 var desc = Object.getOwnPropertyDescriptor(o, name);
90 Object.defineProperty(_copy, name, desc);
10 });
11
120 return _copy;
13}
14
151(typeof exports === 'undefined' ? window : exports).blanket = (function(){
161 var linesToAddTracking = [
17 "ExpressionStatement",
18 "LabeledStatement" ,
19 "BreakStatement" ,
20 "ContinueStatement" ,
21 "VariableDeclaration",
22 "ReturnStatement" ,
23 "ThrowStatement" ,
24 "TryStatement" ,
25 "FunctionDeclaration" ,
26 "IfStatement" ,
27 "WhileStatement" ,
28 "DoWhileStatement" ,
29 "ForStatement" ,
30 "ForInStatement" ,
31 "SwitchStatement" ,
32 "WithStatement"
33 ],
34 linesToAddBrackets = [
35 "IfStatement" ,
36
37 "WhileStatement" ,
38 "DoWhileStatement" ,
39 "ForStatement" ,
40 "ForInStatement" ,
41 "WithStatement"
42 ],
43 covVar = (typeof window === 'undefined' ? "_$jscoverage" : "window._$blanket" ),
44 reporter,instrumentFilter,adapter,
45 coverageInfo = {},existingRequireJS=false,
46 blanket = {
47 _reporter: null,
48 extend: function(obj) {
49 //borrowed from underscore
500 blanket._extend(blanket,obj);
51 },
52 _extend: function(dest,source){
530 if (source) {
540 for (var prop in source) {
550 if (dest[prop]){
560 blanket._extend(dest[prop],source[prop]);
57 }else{
580 dest[prop] = source[prop];
59 }
60 }
61 }
62 },
63 setExistingRequirejs: function(exists){
642 existingRequireJS = exists || false;
65 },
66 getExistingRequirejs: function(){
673 return existingRequireJS;
68 },
69 setFilter: function(filter){
703 instrumentFilter = filter;
71 },
72 getFilter: function(){
734 return instrumentFilter;
74 },
75 setReporter: function(reporterFcn){
764 reporter = reporterFcn;
77 },
78 getReporter: function(){
794 return reporter;
80 },
81 instrument: function(config, next){
822 var inFile = config.inputFile,
83 inFileName = config.inputFileName;
842 var sourceArray = this._prepareSource(inFile);
852 blanket._trackingArraySetup=[];
862 var instrumented = parseAndModify(inFile,{loc:true,comment:true}, this._addTracking,inFileName);
872 instrumented = this._trackingSetup(inFileName,sourceArray)+instrumented;
882 next(instrumented);
89 },
90 _trackingArraySetup: [],
91 _prepareSource: function(source){
923 return source.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/(\r\n|\n|\r)/gm,"\n").split('\n');
93 },
94 _trackingSetup: function(filename,sourceArray){
95
963 var sourceString = sourceArray.join("',\n'");
973 var intro = "if (typeof "+covVar+" === 'undefined') "+covVar+" = {};\n";
983 intro += "if (typeof "+covVar+"['"+filename+"'] === 'undefined'){";
99
1003 intro += covVar+"['"+filename+"']=[];\n";
1013 intro += covVar+"['"+filename+"'].source=['"+sourceString+"'];\n";
102 //initialize array values
1033 blanket._trackingArraySetup.sort(function(a,b){
1049 return parseInt(a,10) > parseInt(b,10);
105 }).forEach(function(item){
10610 intro += covVar+"['"+filename+"']["+item+"]=0;\n";
107 });
108
1093 intro += "}";
1103 return intro;
111 },
112 _blockifyIf: function(node){
113
11487 if (linesToAddBrackets.indexOf(node.type) > -1){
1157 var bracketsExistObject = node.consequent || node.body;
1167 var bracketsExistAlt = node.alternate;
1177 if( bracketsExistAlt && bracketsExistAlt.type !== "BlockStatement") {
1182 bracketsExistAlt.update("{\n"+bracketsExistAlt.source()+"}\n");
119 }
1207 if( bracketsExistObject && bracketsExistObject.type !== "BlockStatement") {
1216 bracketsExistObject.update("{\n"+bracketsExistObject.source()+"}\n");
122 }
123 }
124 },
125 _addTracking: function (node,filename) {
12687 blanket._blockifyIf(node);
12787 if (linesToAddTracking.indexOf(node.type) > -1){
12819 if (node.type === "VariableDeclaration" &&
129 (node.parent.type === "ForStatement" || node.parent.type === "ForInStatement")){
1300 return;
131 }
13219 if (node.loc && node.loc.start){
13319 node.update(covVar+"['"+filename+"']["+node.loc.start.line+"]++;\n"+node.source());
13419 blanket._trackingArraySetup.push(node.loc.start.line);
135 }else{
136 //I don't think we can handle a node with no location
1370 throw new Error("The instrumenter encountered a node with no location: "+Object.keys(node));
138 }
139 }
140 },
141 setupCoverage: function(){
1421 coverageInfo.instrumentation = "blanket";
1431 coverageInfo.stats = {
144 "suites": 0,
145 "tests": 0,
146 "passes": 0,
147 "pending": 0,
148 "failures": 0,
149 "start": new Date()
150 };
151 },
152 _checkIfSetup: function(){
1534 if (!coverageInfo.stats){
1540 throw new Error("You must call blanket.setupCoverage() first.");
155 }
156 },
157 testEvents: {
158 onTestStart: function(){
1591 blanket._checkIfSetup();
1601 coverageInfo.stats.tests++;
1611 coverageInfo.stats.pending++;
162 },
163 onTestDone: function(total,passed){
1641 blanket._checkIfSetup();
1651 if(passed === total){
1661 coverageInfo.stats.passes++;
167 }else{
1680 coverageInfo.stats.failures++;
169 }
1701 coverageInfo.stats.pending--;
171 },
172 onModuleStart: function(){
1731 blanket._checkIfSetup();
1741 coverageInfo.stats.suites++;
175 },
176 onTestsDone: function(){
1771 blanket._checkIfSetup();
1781 coverageInfo.stats.end = new Date();
1791 if (typeof exports === 'undefined'){
1800 blanket.report(coverageInfo);
181 }else{
1821 blanket.getReporter().call(this,coverageInfo);
183 }
184 }
185 }
186 };
1871 return blanket;
188})();
189

testfile2

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