Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #250 from alex-seville/customVariable

Can pass in custom variable to use for coverage tracking
  • Loading branch information...
commit 4b50fb211d7cbd53b16915e5c7deffac99fdacb2 2 parents 2690096 + 52af25d
@alex-seville authored
View
3  README.md
@@ -118,6 +118,9 @@ And thanks also to: [RequireJS](http://requirejs.org/), [Esprima](http://esprima
## Revision History
+Mar 22-13 - 1.1.0
+Custom variable data attribute to use whatever variable you want for coverage tracking.
+
Mar 22-13 - 1.0.9
Blanket is not run on require in node now. Update to component version for bower. Branch tracking reporting fix. Preserve filenames in Node.
View
2  component.json
@@ -1,5 +1,5 @@
{
"name": "blanket",
- "version": "1.0.9",
+ "version": "1.1.0",
"main": ["./dist/qunit/blanket.js"]
}
View
25 dist/jasmine/blanket_jasmine.js
@@ -4028,13 +4028,13 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
"ForInStatement" ,
"WithStatement"
],
- covVar = (inBrowser ? "window._$blanket" : "_$jscoverage" ),
__blanket,
copynumber = Math.floor(Math.random()*1000),
coverageInfo = {},options = {
reporter: null,
adapter:null,
filter: null,
+ customVariable: null,
orderedLoading: true,
loader: null,
ignoreScriptError: false,
@@ -4081,6 +4081,14 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
}
}
},
+ getCovVar: function(){
+ var opt = _blanket.options("customVariable");
+ if (opt){
+ if (_blanket.options("debug")) {console.log("BLANKET-Using custom tracking variable:",opt);}
+ return inBrowser ? "window."+opt : opt;
+ }
+ return inBrowser ? "window._$blanket" : "_$jscoverage";
+ },
options: function(key,value){
if (typeof key !== "string"){
_blanket._extend(options,key);
@@ -4112,6 +4120,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
var branches = _blanket.options("branchTracking");
var sourceString = sourceArray.join("',\n'");
var intro = "";
+ var covVar = _blanket.getCovVar();
intro += "if (typeof "+covVar+" === 'undefined') "+covVar+" = {};\n";
if (branches){
@@ -4158,7 +4167,6 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
return intro;
},
_blockifyIf: function(node){
-
if (linesToAddBrackets.indexOf(node.type) > -1){
var bracketsExistObject = node.consequent || node.body;
var bracketsExistAlt = node.alternate;
@@ -4174,7 +4182,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//recursive on consequent and alternative
var line = node.loc.start.line;
var col = node.loc.start.column;
-
+
_blanket._branchingArraySetup.push({
line: line,
column: col,
@@ -4193,9 +4201,11 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//falafel doesn't take a file name
//so we include the filename in a closure
//and return the function to falafel
+ var covVar = _blanket.getCovVar();
+
return function(node){
_blanket._blockifyIf(node);
-
+
if (linesToAddTracking.indexOf(node.type) > -1 && node.parent.type !== "LabeledStatement"){
if (node.type === "VariableDeclaration" &&
(node.parent.type === "ForStatement" || node.parent.type === "ForInStatement")){
@@ -4257,7 +4267,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
this.report(coverageInfo);
}else{
if (!_blanket.options("branchTracking")){
- delete _$jscoverage.branchFcn;
+ delete (inBrowser ? window : global)[_blanket.getCovVar()].branchFcn;
}
this.options("reporter").call(this,coverageInfo);
}
@@ -6832,9 +6842,12 @@ blanket.defaultReporter = function(coverage){
if (es.nodeName === "data-cover-timeout"){
newOptions.timeout = es.nodeValue;
}
- if (es.nodeName === "testReadyCallback"){
+ if (es.nodeName === "data-cover-testReadyCallback"){
newOptions.testReadyCallback = es.nodeValue;
}
+ if (es.nodeName === "data-cover-customVariable"){
+ newOptions.customVariable = es.nodeValue;
+ }
if (es.nodeName === "data-cover-flags"){
var flags = " "+es.nodeValue+" ";
if (flags.indexOf(" unordered ") > -1){
View
2  dist/jasmine/blanket_jasmine.min.js
1 addition, 1 deletion not shown
View
25 dist/qunit/blanket.js
@@ -4029,13 +4029,13 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
"ForInStatement" ,
"WithStatement"
],
- covVar = (inBrowser ? "window._$blanket" : "_$jscoverage" ),
__blanket,
copynumber = Math.floor(Math.random()*1000),
coverageInfo = {},options = {
reporter: null,
adapter:null,
filter: null,
+ customVariable: null,
orderedLoading: true,
loader: null,
ignoreScriptError: false,
@@ -4082,6 +4082,14 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
}
}
},
+ getCovVar: function(){
+ var opt = _blanket.options("customVariable");
+ if (opt){
+ if (_blanket.options("debug")) {console.log("BLANKET-Using custom tracking variable:",opt);}
+ return inBrowser ? "window."+opt : opt;
+ }
+ return inBrowser ? "window._$blanket" : "_$jscoverage";
+ },
options: function(key,value){
if (typeof key !== "string"){
_blanket._extend(options,key);
@@ -4113,6 +4121,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
var branches = _blanket.options("branchTracking");
var sourceString = sourceArray.join("',\n'");
var intro = "";
+ var covVar = _blanket.getCovVar();
intro += "if (typeof "+covVar+" === 'undefined') "+covVar+" = {};\n";
if (branches){
@@ -4159,7 +4168,6 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
return intro;
},
_blockifyIf: function(node){
-
if (linesToAddBrackets.indexOf(node.type) > -1){
var bracketsExistObject = node.consequent || node.body;
var bracketsExistAlt = node.alternate;
@@ -4175,7 +4183,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//recursive on consequent and alternative
var line = node.loc.start.line;
var col = node.loc.start.column;
-
+
_blanket._branchingArraySetup.push({
line: line,
column: col,
@@ -4194,9 +4202,11 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//falafel doesn't take a file name
//so we include the filename in a closure
//and return the function to falafel
+ var covVar = _blanket.getCovVar();
+
return function(node){
_blanket._blockifyIf(node);
-
+
if (linesToAddTracking.indexOf(node.type) > -1 && node.parent.type !== "LabeledStatement"){
if (node.type === "VariableDeclaration" &&
(node.parent.type === "ForStatement" || node.parent.type === "ForInStatement")){
@@ -4258,7 +4268,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
this.report(coverageInfo);
}else{
if (!_blanket.options("branchTracking")){
- delete _$jscoverage.branchFcn;
+ delete (inBrowser ? window : global)[_blanket.getCovVar()].branchFcn;
}
this.options("reporter").call(this,coverageInfo);
}
@@ -6833,9 +6843,12 @@ blanket.defaultReporter = function(coverage){
if (es.nodeName === "data-cover-timeout"){
newOptions.timeout = es.nodeValue;
}
- if (es.nodeName === "testReadyCallback"){
+ if (es.nodeName === "data-cover-testReadyCallback"){
newOptions.testReadyCallback = es.nodeValue;
}
+ if (es.nodeName === "data-cover-customVariable"){
+ newOptions.customVariable = es.nodeValue;
+ }
if (es.nodeName === "data-cover-flags"){
var flags = " "+es.nodeValue+" ";
if (flags.indexOf(" unordered ") > -1){
View
2  dist/qunit/blanket.min.js
1 addition, 1 deletion not shown
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "blanket",
"description": "seamless js code coverage",
- "version": "1.0.9",
+ "version": "1.1.0",
"homepage": "https://github.com/alex-seville/blanket",
"author": {
"name": "Alex-Seville",
View
20 src/blanket.js
@@ -27,13 +27,13 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
"ForInStatement" ,
"WithStatement"
],
- covVar = (inBrowser ? "window._$blanket" : "_$jscoverage" ),
__blanket,
copynumber = Math.floor(Math.random()*1000),
coverageInfo = {},options = {
reporter: null,
adapter:null,
filter: null,
+ customVariable: null,
orderedLoading: true,
loader: null,
ignoreScriptError: false,
@@ -80,6 +80,14 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
}
}
},
+ getCovVar: function(){
+ var opt = _blanket.options("customVariable");
+ if (opt){
+ if (_blanket.options("debug")) {console.log("BLANKET-Using custom tracking variable:",opt);}
+ return inBrowser ? "window."+opt : opt;
+ }
+ return inBrowser ? "window._$blanket" : "_$jscoverage";
+ },
options: function(key,value){
if (typeof key !== "string"){
_blanket._extend(options,key);
@@ -111,6 +119,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
var branches = _blanket.options("branchTracking");
var sourceString = sourceArray.join("',\n'");
var intro = "";
+ var covVar = _blanket.getCovVar();
intro += "if (typeof "+covVar+" === 'undefined') "+covVar+" = {};\n";
if (branches){
@@ -157,7 +166,6 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
return intro;
},
_blockifyIf: function(node){
-
if (linesToAddBrackets.indexOf(node.type) > -1){
var bracketsExistObject = node.consequent || node.body;
var bracketsExistAlt = node.alternate;
@@ -173,7 +181,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//recursive on consequent and alternative
var line = node.loc.start.line;
var col = node.loc.start.column;
-
+
_blanket._branchingArraySetup.push({
line: line,
column: col,
@@ -192,9 +200,11 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
//falafel doesn't take a file name
//so we include the filename in a closure
//and return the function to falafel
+ var covVar = _blanket.getCovVar();
+
return function(node){
_blanket._blockifyIf(node);
-
+
if (linesToAddTracking.indexOf(node.type) > -1 && node.parent.type !== "LabeledStatement"){
if (node.type === "VariableDeclaration" &&
(node.parent.type === "ForStatement" || node.parent.type === "ForInStatement")){
@@ -256,7 +266,7 @@ var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
this.report(coverageInfo);
}else{
if (!_blanket.options("branchTracking")){
- delete _$jscoverage.branchFcn;
+ delete (inBrowser ? window : global)[_blanket.getCovVar()].branchFcn;
}
this.options("reporter").call(this,coverageInfo);
}
View
5 src/config.js
@@ -23,9 +23,12 @@
if (es.nodeName === "data-cover-timeout"){
newOptions.timeout = es.nodeValue;
}
- if (es.nodeName === "testReadyCallback"){
+ if (es.nodeName === "data-cover-testReadyCallback"){
newOptions.testReadyCallback = es.nodeValue;
}
+ if (es.nodeName === "data-cover-customVariable"){
+ newOptions.customVariable = es.nodeValue;
+ }
if (es.nodeName === "data-cover-flags"){
var flags = " "+es.nodeValue+" ";
if (flags.indexOf(" unordered ") > -1){
View
3  src/index.js
@@ -40,6 +40,9 @@ var blanketNode = function (userOptions,cli){
if (option === "onlyCwd" && !!optionValue){
newOptions.cwdRegex = new RegExp("^" + escapeRegExp(process.cwd()), "i");
}
+ if (option === "data-cover-customVariable"){
+ newOptions.customVariable = optionValue;
+ }
if (option === "data-cover-flags"){
newOptions.order = !optionValue.unordered;
newOptions.ignoreScriptError = !!optionValue.ignoreError;
Please sign in to comment.
Something went wrong with that request. Please try again.