🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

karma-iframes

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-iframes - npm Package Compare versions

Comparing version

to
1.2.1

@@ -10,2 +10,6 @@ # Changelog

### 1.2.1
* Output a list of deep-links to individual suites in debug mode.
## 1.1

@@ -12,0 +16,0 @@

{
"name": "karma-iframes",
"version": "1.2.0",
"version": "1.2.1",
"description": "Lets you run each test in a separate context, loaded as an iframe.",

@@ -28,3 +28,3 @@ "main": "index.js",

"chai": "^4.1.2",
"karma": "^1.7.1",
"karma": "^3.1.1",
"karma-chai": "^0.1.0",

@@ -31,0 +31,0 @@ "karma-chrome-launcher": "^2.2.0",

@@ -10,14 +10,14 @@ // jshint es3: false

function Suite(path, showTitle) {
// state is one of
// • 'pending' (before the total is known)
// • 'started' (after total is known but before all suites have executed)
// • 'complete' (when total === finished)
this.state = 'pending',
this.fileName = path.match(/\/([^/]+)\.iframe\.html$/)[1];
this.path = path;
this.iframe = document.createElement('iframe');
this.wrapper = document.createElement('span');
this.showTitle = showTitle;
this.total = NaN;
this.finished = 0;
// state is one of
// • 'pending' (before the total is known)
// • 'started' (after total is known but before all suites have executed)
// • 'complete' (when total === finished)
this.state = 'pending';
this.fileName = path.match(/\/([^/]+)\.iframe\.html$/)[1];
this.path = path;
this.iframe = document.createElement('iframe');
this.wrapper = document.createElement('span');
this.showTitle = showTitle;
this.total = NaN;
this.finished = 0;
}

@@ -69,12 +69,12 @@

Suite.prototype.run = function() {
if(isDebug) {
console.debug(`Running suite ${this.fileName}`);
}
if (this.showTitle) {
this.wrapper.style.float = 'left';
this.wrapper.innerHTML = this.fileName + '<br>';
}
this.wrapper.appendChild(this.iframe);
this.iframe.src = this.path;
document.body.appendChild(this.wrapper)
if(isDebug) {
console.debug(`Running suite ${this.fileName}`);
}
if (this.showTitle) {
this.wrapper.style.float = 'left';
this.wrapper.innerHTML = this.fileName + '<br>';
}
this.wrapper.appendChild(this.iframe);
this.iframe.src = this.path;
document.body.appendChild(this.wrapper)
};

@@ -108,15 +108,15 @@

suiteComplete(result);
this.onComplete();
this.onComplete();
this.cleanup();
};
Suite.prototype.onComplete = function() {};
Suite.prototype.onComplete = function() {};
Suite.prototype.cleanup = function() {
this.iframe.parentNode.removeChild(this.iframe);
this.wrapper.parentNode.removeChild(this.wrapper);
window.removeEventListener('message', this.messageListener, false);
this.iframe = null;
this.wrapper = null;
this.messageListener = null;
this.iframe.parentNode.removeChild(this.iframe);
this.wrapper.parentNode.removeChild(this.wrapper);
window.removeEventListener('message', this.messageListener, false);
this.iframe = null;
this.wrapper = null;
this.messageListener = null;
}

@@ -188,5 +188,5 @@

function suiteComplete(result) {
if (result.coverage) {
coverageCollector.addCoverage(result.coverage);
}
if (result.coverage) {
coverageCollector.addCoverage(result.coverage);
}

@@ -203,105 +203,119 @@ // Have all suites completed?

}
if (result.coverage) {
result.coverage = coverageCollector.getFinalCoverage();
}
if (result.coverage) {
result.coverage = coverageCollector.getFinalCoverage();
}
karma.complete(result);
}
function start () {
// jshint validthis: true
let files = Object.keys(karma.files).filter(file => file.match(/\.iframe\.html$/));
let concurrency = parseInt(karma.config.concurrency, 10) || 10;
let showFrameTitle = karma.config.showFrameTitle || false;
let ran = 0;
let preparedSuites = [];
preparedSuites = files.map(file => {
let suite = new Suite(file, showFrameTitle);
suite.init(suites);
return suite;
});
function start () {
// jshint validthis: true
let files = Object.keys(karma.files).filter(file => file.match(/\.iframe\.html$/));
preparedSuites.reverse();
let concurrency = parseInt(karma.config.concurrency, 10) || 10;
let showFrameTitle = karma.config.showFrameTitle || false;
let ran = 0;
let preparedSuites = [];
preparedSuites = files.map(file => {
let suite = new Suite(file, showFrameTitle);
suite.init(suites);
return suite;
});
function runNextSuite () {
let suite = preparedSuites.pop();
if (!suite) {
return;
}
suite.onComplete = function () {
ran--;
runNextSuite();
};
suite.run();
ran++;
if (ran < concurrency) {
setTimeout(runNextSuite, 0);
}
}
if(isDebug) {
let debugLinks = document.createElement('div');
preparedSuites.forEach(suite => {
let link = document.createElement('a');
link.href = suite.path;
link.target = '_blank';
link.style.display = 'block';
link.appendChild(document.createTextNode(suite.fileName));
debugLinks.appendChild(link);
});
document.body.insertBefore(debugLinks, document.body.firstChild);
}
runNextSuite();
}
preparedSuites.reverse();
//
// Helper to collect coverages from each suite
// (supports only one coverage format)
//
var coverageCollector = {
coverages: [],
addCoverage: function (coverage) {
this.coverages.push(coverage);
},
function runNextSuite () {
let suite = preparedSuites.pop();
if (!suite) {
return;
}
suite.onComplete = function () {
ran--;
runNextSuite();
};
suite.run();
ran++;
if (ran < concurrency) {
setTimeout(runNextSuite, 0);
}
}
getFinalCoverage: function () {
var coverages = this.coverages;
return coverages.length ? this.mergeCoverages(coverages) : null;
},
runNextSuite();
}
mergeCoverages: function (coverages) {
var mergedCoverage = {},
collector = this;
//
// Helper to collect coverages from each suite
// (supports only one coverage format)
//
var coverageCollector = {
coverages: [],
addCoverage: function (coverage) {
this.coverages.push(coverage);
},
coverages.forEach(function (coverageBySrc) {
Object.keys(coverageBySrc).forEach(function (srcKey) {
if (!(srcKey in mergedCoverage)) {
mergedCoverage[srcKey] = collector.dirtyClone(coverageBySrc[srcKey]);
return;
}
getFinalCoverage: function () {
var coverages = this.coverages;
return coverages.length ? this.mergeCoverages(coverages) : null;
},
var masterCoverage = mergedCoverage[srcKey],
coverage = coverageBySrc[srcKey];
mergeCoverages: function (coverages) {
var mergedCoverage = {},
collector = this;
// b - branches,
['b'].forEach(function (prop) {
if (!coverage[prop]) {
return;
}
Object.keys(coverage[prop]).forEach(function (branch) {
if (!coverage[prop][branch]) {
return;
}
(masterCoverage[prop][branch] || []).forEach(function (value, index) {
masterCoverage[prop][branch][index] += (coverage[prop][branch] || [])[index] || 0;
});
});
});
coverages.forEach(function (coverageBySrc) {
Object.keys(coverageBySrc).forEach(function (srcKey) {
if (!(srcKey in mergedCoverage)) {
mergedCoverage[srcKey] = collector.dirtyClone(coverageBySrc[srcKey]);
return;
}
// f - functions, s - statements
['f', 's'].forEach(function (prop) {
Object.keys(masterCoverage[prop]).forEach(function (index) {
masterCoverage[prop][index] += (coverage[prop] || [])[index] || 0;
});
});
});
});
var masterCoverage = mergedCoverage[srcKey],
coverage = coverageBySrc[srcKey];
return mergedCoverage;
},
// b - branches,
['b'].forEach(function (prop) {
if (!coverage[prop]) {
return;
}
Object.keys(coverage[prop]).forEach(function (branch) {
if (!coverage[prop][branch]) {
return;
}
(masterCoverage[prop][branch] || []).forEach(function (value, index) {
masterCoverage[prop][branch][index] += (coverage[prop][branch] || [])[index] || 0;
});
});
});
dirtyClone: function (object) {
return JSON.parse(JSON.stringify(object));
}
};
// f - functions, s - statements
['f', 's'].forEach(function (prop) {
Object.keys(masterCoverage[prop]).forEach(function (index) {
masterCoverage[prop][index] += (coverage[prop] || [])[index] || 0;
});
});
});
});
return mergedCoverage;
},
dirtyClone: function (object) {
return JSON.parse(JSON.stringify(object));
}
};
karma.start = start;
})(window.__karma__);