Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add document.currentScript support #558

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions dist/jasmine/blanket_jasmine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! blanket - v1.2.1 */
/*! blanket - v1.2.3 */

(function(define){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.acorn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
Expand Down Expand Up @@ -4941,9 +4941,9 @@ blanket.defaultReporter = function(coverage){
hasBranchTracking = Object.keys(coverage.files).some(function(elem){
return typeof coverage.files[elem].branchData !== 'undefined';
}),
bodyContent = "<div id='blanket-main'><div class='blanket bl-title'><div class='bl-cl bl-file'><a href='http://alex-seville.github.com/blanket/' target='_blank' class='bl-logo'>Blanket.js</a> results</div><div class='bl-cl rs'>Coverage (%)</div><div class='bl-cl rs'>Covered/Total Smts.</div>"+(hasBranchTracking ? "<div class='bl-cl rs'>Covered/Total Branches</div>":"")+"<div style='clear:both;'></div></div>",
fileTemplate = "<div class='blanket {{statusclass}}'><div class='bl-cl bl-file'><span class='bl-nb'>{{fileNumber}}.</span><a href='javascript:blanket_toggleSource(\"file-{{fileNumber}}\")'>{{file}}</a></div><div class='bl-cl rs'>{{percentage}} %</div><div class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</div>"+( hasBranchTracking ? "<div class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</div>" : "" )+"<div id='file-{{fileNumber}}' class='bl-source' style='display:none;'>{{source}}</div><div style='clear:both;'></div></div>";
grandTotalTemplate = "<div class='blanket grand-total {{statusclass}}'><div class='bl-cl'>{{rowTitle}}</div><div class='bl-cl rs'>{{percentage}} %</div><div class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</div>"+( hasBranchTracking ? "<div class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</div>" : "" ) + "<div style='clear:both;'></div></div>";
bodyContent = "<table id='blanket-main'><tr><th class='blanket bl-title'><th class='bl-cl bl-file'><a href='http://alex-seville.github.com/blanket/' target='_blank' class='bl-logo'>Blanket.js</a> results</th><th class='bl-cl rs'>Coverage (%)</th><th class='bl-cl rs'>Covered/Total Smts.</th>"+(hasBranchTracking ? "<th class='bl-cl rs'>Covered/Total Branches</th>":"")+"<th style='clear:both;'></th></tr></table>",
fileTemplate = "<tr><td class='blanket {{statusclass}}'><td class='bl-cl bl-file'><span class='bl-nb'>{{fileNumber}}.</span><a href='javascript:blanket_toggleSource(\"file-{{fileNumber}}\")'>{{file}}</a></td><td class='bl-cl rs'>{{percentage}} %</td><td class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</td>"+( hasBranchTracking ? "<td class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</td>" : "" )+"<td id='file-{{fileNumber}}' class='bl-source' style='display:none;'>{{source}}</td><td style='clear:both;'></td></td></tr>";
grandTotalTemplate = "<tr><td class='blanket grand-total {{statusclass}}'><td class='bl-cl'>{{rowTitle}}</td><td class='bl-cl rs'>{{percentage}} %</td><td class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</td>"+( hasBranchTracking ? "<td class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</td>" : "" ) + "<td style='clear:both;'></td></td></tr>";

function blanket_toggleSource(id) {
var element = document.getElementById(id);
Expand Down Expand Up @@ -4977,8 +4977,7 @@ blanket.defaultReporter = function(coverage){
.replace(/\"/g, "&quot;")
.replace(/\'/g, "&apos;")
.replace(/`/g, "&grave;")
.replace(/[$]/g, "&dollar;")
.replace(/&/g, "&amp;");
.replace(/[$]/g, "&dollar;");
}

function isBranchFollowed(data,bool){
Expand Down Expand Up @@ -5029,7 +5028,7 @@ blanket.defaultReporter = function(coverage){
}
var thisline = cols[colsIndex];
//consequent

var cons = thisline.consequent;
if (cons.start.line > lineNum){
branchStack.unshift([thisline.alternate,thisline]);
Expand All @@ -5038,7 +5037,7 @@ blanket.defaultReporter = function(coverage){
}else{
var style = "<span class='" + (isBranchFollowed(thisline,true) ? 'branchOkay' : 'branchWarning') + "'>";
newsrc += escapeInvalidXmlChars(src.slice(0,cons.start.column-offset)) + style;

if (cols.length > colsIndex+1 &&
cols[colsIndex+1].consequent.start.line === lineNum &&
cols[colsIndex+1].consequent.start.column-offset < cols[colsIndex].consequent.end.column-offset)
Expand Down Expand Up @@ -5114,23 +5113,23 @@ blanket.defaultReporter = function(coverage){
numberOfFilesCovered = 0,
code = [],
i;


var end = [];
for(i = 0; i < statsForFile.source.length; i +=1){
var src = statsForFile.source[i];

if (branchStack.length > 0 ||
typeof statsForFile.branchData !== 'undefined')
{
if (typeof statsForFile.branchData[i+1] !== 'undefined')
{
var cols = statsForFile.branchData[i+1].filter(isUndefined);
var colsIndex=0;


src = branchReport(colsIndex,src,cols,0,i+1).src;

}else if (branchStack.length){
src = branchReport(0,src,null,0,i+1).src;
}else{
Expand Down Expand Up @@ -5176,7 +5175,7 @@ blanket.defaultReporter = function(coverage){
totals.passedBranches += passedBranches;
totals.totalBranches += totalBranches;

// if "data-cover-modulepattern" was provided,
// if "data-cover-modulepattern" was provided,
// track totals per module name as well as globally
if (modulePatternRegex) {
var moduleName = file.match(modulePatternRegex)[1];
Expand Down Expand Up @@ -5217,7 +5216,7 @@ blanket.defaultReporter = function(coverage){
bodyContent += output;
}

// create temporary function for use by the global totals reporter,
// create temporary function for use by the global totals reporter,
// as well as the per-module totals reporter
var createAggregateTotal = function(numSt, numCov, numBranch, numCovBr, moduleName) {

Expand All @@ -5235,8 +5234,8 @@ blanket.defaultReporter = function(coverage){
bodyContent += totalsOutput;
};

// if "data-cover-modulepattern" was provided,
// output the per-module totals alongside the global totals
// if "data-cover-modulepattern" was provided,
// output the per-module totals alongside the global totals
if (modulePatternRegex) {
for (var thisModuleName in totals.moduleTotalStatements) {
if (totals.moduleTotalStatements.hasOwnProperty(thisModuleName)) {
Expand Down Expand Up @@ -5272,7 +5271,11 @@ blanket.defaultReporter = function(coverage){
//http://stackoverflow.com/a/2954896
var toArray =Array.prototype.slice;
var scripts = toArray.call(document.scripts);
toArray.call(scripts[scripts.length - 1].attributes)
var script = scripts[scripts.length - 1];
if(document['currentScript']) { // Test to see if it exists without throwing an error
script = document.currentScript;
}
toArray.call(script.attributes)
.forEach(function(es){
if(es.nodeName === "data-cover-only"){
newOptions.filter = es.nodeValue;
Expand Down Expand Up @@ -5304,10 +5307,10 @@ blanket.defaultReporter = function(coverage){
}
}
}
if (es.nodeName === "data-cover-testReadyCallback"){
if (es.nodeName.toLowerCase() === "data-cover-testreadycallback"){
newOptions.testReadyCallback = es.nodeValue;
}
if (es.nodeName === "data-cover-customVariable"){
if (es.nodeName.toLowerCase() === "data-cover-customvariable"){
newOptions.customVariable = es.nodeValue;
}
if (es.nodeName === "data-cover-flags"){
Expand Down Expand Up @@ -5352,6 +5355,7 @@ blanket.defaultReporter = function(coverage){
blanket._commonjs = {};
}
})();

(function(_blanket){
_blanket.extend({
utils: {
Expand Down Expand Up @@ -5392,21 +5396,27 @@ _blanket.extend({
},
collectPageScripts: function(){
var toArray = Array.prototype.slice;
var scripts = toArray.call(document.scripts);
var selectedScripts=[],scriptNames=[];
var filter = _blanket.options("filter");

function selectAllScripts() {
var browserScripts = toArray.call(document.scripts);
var blanketScripts = toArray.call(document.getElementsByTagName('blanket'));
return browserScripts.concat(blanketScripts);
}

if(filter != null){
//global filter in place, data-cover-only
var antimatch = _blanket.options("antifilter");
selectedScripts = toArray.call(document.scripts)
selectedScripts = selectAllScripts()
.filter(function(s){
return toArray.call(s.attributes).filter(function(sn){
return sn.nodeName === "src" && _blanket.utils.matchPatternAttribute(sn.nodeValue,filter) &&
(typeof antimatch === "undefined" || !_blanket.utils.matchPatternAttribute(sn.nodeValue,antimatch));
}).length === 1;
});
}else{
selectedScripts = toArray.call(document.querySelectorAll("script[data-cover]"));
selectedScripts = toArray.call(document.querySelectorAll("script[data-cover], blanket"));
}
scriptNames = selectedScripts.map(function(s){
return _blanket.utils.qualifyURL(
Expand Down
8 changes: 4 additions & 4 deletions dist/jasmine/blanket_jasmine.min.js

Large diffs are not rendered by default.

Loading