Skip to content

Commit

Permalink
Change custom reporter format to avoid "define" conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-seville committed May 4, 2013
1 parent 237972f commit 4a64aed
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion component.json
@@ -1,5 +1,5 @@
{
"name": "blanket",
"version": "1.1.4",
"version": "1.1.5",
"main": ["./dist/qunit/blanket.js"]
}
7 changes: 3 additions & 4 deletions dist/jasmine/blanket_jasmine.js
@@ -1,4 +1,4 @@
/*! blanket - v1.1.4 */
/*! blanket - v1.1.5 */

(function(define){

Expand Down Expand Up @@ -4492,9 +4492,8 @@ _blanket.extend({
delete coverage_data.files.branchFcn;
}
if (typeof _blanket.options("reporter") === "string"){
require([_blanket.options("reporter").replace(".js","")],function(r){
r(coverage_data,_blanket.options("reporter_options"));
});
_blanket._loadFile(_blanket.options("reporter"));
_blanket.customReporter(coverage_data,_blanket.options("reporter_options"));
}else if (typeof _blanket.options("reporter") === "function"){
_blanket.options("reporter")(coverage_data);
}else if (typeof _blanket.defaultReporter === 'function'){
Expand Down
2 changes: 1 addition & 1 deletion dist/jasmine/blanket_jasmine.min.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/qunit/blanket.js
@@ -1,4 +1,4 @@
/*! blanket - v1.1.4 */
/*! blanket - v1.1.5 */

if (typeof QUnit !== 'undefined'){ QUnit.config.autostart = false; }
(function(define){
Expand Down Expand Up @@ -4493,9 +4493,8 @@ _blanket.extend({
delete coverage_data.files.branchFcn;
}
if (typeof _blanket.options("reporter") === "string"){
require([_blanket.options("reporter").replace(".js","")],function(r){
r(coverage_data,_blanket.options("reporter_options"));
});
_blanket._loadFile(_blanket.options("reporter"));
_blanket.customReporter(coverage_data,_blanket.options("reporter_options"));
}else if (typeof _blanket.options("reporter") === "function"){
_blanket.options("reporter")(coverage_data);
}else if (typeof _blanket.defaultReporter === 'function'){
Expand Down
2 changes: 1 addition & 1 deletion dist/qunit/blanket.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/advanced_browser.md
Expand Up @@ -40,15 +40,15 @@ Custom reporters are used by Blanket to display the coverage results. Blanket c

See the [simple_json_reporter](https://raw.github.com/alex-seville/blanket/master/src/reporters/simple_json_reporter.js) as a very basic example of a reporter.

Reporters need to be wrapped in a define statement, and return a function that accept the coverage results object as an argument, ex:
Reporters are functions assigned to blanket.customReporter, which accept the coverage results object as an argument, ex:

```
define([],function myReporter(){
(function myReporter(){
//your reporter code
return function(coverage_results){
blanket.customReporter=function(coverage_results){
console.log(coverage_results);
};
};
})();
```

The example above will create a reporter that will print the coverage result object to the console. Not useful, but it illustrates the pattern.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "blanket",
"description": "seamless js code coverage",
"version": "1.1.4",
"version": "1.1.5",
"homepage": "https://github.com/alex-seville/blanket",
"author": {
"name": "Alex-Seville",
Expand Down
5 changes: 2 additions & 3 deletions src/blanket_browser.js
Expand Up @@ -165,9 +165,8 @@ _blanket.extend({
delete coverage_data.files.branchFcn;
}
if (typeof _blanket.options("reporter") === "string"){
require([_blanket.options("reporter").replace(".js","")],function(r){
r(coverage_data,_blanket.options("reporter_options"));
});
_blanket._loadFile(_blanket.options("reporter"));
_blanket.customReporter(coverage_data,_blanket.options("reporter_options"));
}else if (typeof _blanket.options("reporter") === "function"){
_blanket.options("reporter")(coverage_data);
}else if (typeof _blanket.defaultReporter === 'function'){
Expand Down
13 changes: 7 additions & 6 deletions src/reporters/lcov_reporter.js
@@ -1,10 +1,11 @@
define([],function lcov_reporter(){
//lcov_reporter
(function (){
//takes the option: toHTML {boolean}

var body = document.body;

var appendHtml = function ( filename,data,toHTML) {

var str="";
str += 'SF:' + filename + '\n';

Expand All @@ -27,8 +28,8 @@ define([],function lcov_reporter(){
window._$blanket_LCOV = str;
}
};
return function(coverageData,options){

blanket.customReporter=function(coverageData,options){
var toHTML=true;
if (typeof options !== 'undefined' && typeof options.toHTML !== 'undefined'){
toHTML = options.toHTML;
Expand All @@ -38,4 +39,4 @@ define([],function lcov_reporter(){
appendHtml(filename,data,toHTML);
}
};
});
})();
11 changes: 6 additions & 5 deletions src/reporters/simple_json_reporter.js
@@ -1,14 +1,15 @@
define([],function simple_json_reporter(){

//simple_json_reporter
(function (){

var body = document.body;

var appendHtml = function (el, str) {
var div = document.createElement('div');
div.innerText = str;
el.appendChild(div);
};
return function(coverageData){

blanket.customReporter= function(coverageData){
appendHtml(body, JSON.stringify(coverageData,null,"\t"));
};
});
})();

0 comments on commit 4a64aed

Please sign in to comment.