test-agent
Advanced tools
Comparing version 0.22.9 to 0.22.10
@@ -34,2 +34,8 @@ var server = new (require('../websocket-server')), | ||
option('coverage-thresholds', { | ||
alias: 't', | ||
desc: "Path to coverage thresholds files", | ||
default: './coverage-thresholds.json' | ||
}). | ||
option('growl', { | ||
@@ -91,7 +97,9 @@ desc: "Enables growl notifications for server" | ||
use(Enhancements.MochaTestEvents). | ||
use(Enhancements.BlanketConsoleReporter). | ||
use(Enhancements.QueueTests). | ||
use(Enhancements.StartCoverages). | ||
use(Enhancements.EventMirror). | ||
use(Enhancements.Watcher); | ||
use(Enhancements.Watcher). | ||
use(Enhancements.BlanketConsoleReporter, { | ||
path: fsPath.join(process.env.PWD, argv['coverage-thresholds']) | ||
}); | ||
@@ -98,0 +106,0 @@ if(argv.growl){ |
var Client = require('../../node/client'), | ||
Apps = require('../../node/server'), | ||
optimist = require('optimist'), | ||
fsPath = require('path'), | ||
argv, | ||
@@ -53,2 +54,6 @@ reporters, | ||
}). | ||
option('coverage-thresholds', { | ||
alias: 't', | ||
desc: "Path to coverage thresholds files" | ||
}). | ||
option('server', { | ||
@@ -118,3 +123,5 @@ desc: 'Location of the websocket server to connect to.', | ||
if (enableCoverage) { | ||
client.use(Apps.BlanketConsoleReporter); | ||
client.use(Apps.BlanketConsoleReporter, { | ||
path: fsPath.join(process.env.PWD, argv['coverage-thresholds']) | ||
}); | ||
} | ||
@@ -140,2 +147,12 @@ | ||
client.on('coverage runner end', function(runner){ | ||
client.send('close'); | ||
if(runner.totalFailures === 0){ | ||
process.exit(0); | ||
} | ||
process.exit(1); | ||
}); | ||
client.start(); |
(function() { | ||
'use strict'; | ||
function BlanketConsoleReporter() { | ||
function BlanketConsoleReporter(options) { | ||
for (var key in options) { | ||
if (options.hasOwnProperty(key)) { | ||
this[key] = options[key]; | ||
} | ||
} | ||
this.setupThresholds(); | ||
this.totalPasses = 0; | ||
this.totalFailures = 0; | ||
} | ||
@@ -10,7 +18,9 @@ | ||
enhance: function enhance(server) { | ||
server.on('coverage report', this._onCoverageData.bind(this)); | ||
enhance: function enhance(worker) { | ||
this.worker = worker; | ||
worker.on('coverage report', this.onCoverageData.bind(this)); | ||
worker.on('test runner end', this.onTestRunnerEnd.bind(this)); | ||
}, | ||
_onCoverageData: function _onCoverageData(data) { | ||
onCoverageData: function onCoverageData(data) { | ||
data = this._parseCoverageData(data); | ||
@@ -20,2 +30,7 @@ this._printConsoleFormat(data); | ||
onTestRunnerEnd: function onTestRunnerEnd() { | ||
this._printCoverageSummary(); | ||
this.worker.emit('coverage runner end', this); | ||
}, | ||
_parseCoverageData: function _parseCoverageData(data) { | ||
@@ -31,3 +46,3 @@ var coverResults = [], | ||
var percentage = function(covered, total) { | ||
return (Math.round(((covered / total) * 100) * 100) / 100) + ' %'; | ||
return Math.round(((covered / total) * 100) * 100) / 100; | ||
}; | ||
@@ -73,14 +88,19 @@ | ||
_printConsoleFormat: function _printConsoleFormat(coverResults) { | ||
var titleColor = '\u001b[1;36m', | ||
var appName = coverResults[0].filename.match(/[A-Za-z0-9_-]+/gi)[1], | ||
titleColor = '\u001b[1;36m', | ||
fileNameColor = '\u001b[0;37m', | ||
stmtColor = '\u001b[0;33m', | ||
percentageColor = '\u001b[0;36m', | ||
passColor = '\u001b[0;32m', | ||
failColor = '\u001b[0;31m', | ||
thresholdColor = '\u001b[0;34m', | ||
originColor = '\u001b[0m', | ||
outputFormat; | ||
outputFormat, | ||
fails = 0, | ||
totals = coverResults.length - 1; | ||
// Print title | ||
console.log('\n%s-- Blanket.js Test Coverage Result --\n', titleColor); | ||
console.log('%sFile Name%s - %sCovered/Total Smts%s - %sCoverage(%)%s\n', | ||
fileNameColor, originColor, stmtColor, originColor, percentageColor, | ||
originColor); | ||
console.log('\n%s-- Test Coverage for %s%s%s --\n', titleColor, stmtColor, | ||
(appName[0].toUpperCase() + appName.slice(1)), titleColor); | ||
console.log('%sFile Name%s - %sCovered/Total Smts%s - %sCoverage (%)\n', | ||
fileNameColor, originColor, stmtColor, originColor, passColor); | ||
@@ -91,4 +111,16 @@ // Print coverage result for each file | ||
formatPrefix = (filename === 'Global Total' ? '\n' : ' '), | ||
seperator = ' - '; | ||
seperator = ' - ', | ||
isPassThreshold = this.validateThreshold(appName, dataItem), | ||
arrow = isPassThreshold ? ' > ' : ' < ', | ||
covColor = isPassThreshold ? passColor : failColor; | ||
if (filename !== 'Global Total') { | ||
if (!isPassThreshold) { | ||
fails++; | ||
this.totalFailures++; | ||
} else { | ||
this.totalPasses++; | ||
} | ||
} | ||
filename = (filename === 'Global Total' ? filename : | ||
@@ -99,7 +131,56 @@ (filename.substr(0, filename.indexOf('?')) || filename)); | ||
outputFormat += stmtColor + dataItem.stmts + originColor + seperator; | ||
outputFormat += percentageColor + dataItem.percentage + originColor; | ||
outputFormat += covColor + dataItem.percentage + ' %' + originColor; | ||
console.log(outputFormat); | ||
}); | ||
}, this); | ||
outputFormat = thresholdColor + '\nThreshold = ' + | ||
this.getAppThreshold(appName) + '%, '; | ||
if (fails === 0) { | ||
outputFormat += passColor + 'COVERAGE PASS'; | ||
} else { | ||
outputFormat += failColor + 'COVERAGE FAIL: ' + fails + '/' + | ||
totals + ' files failed coverage'; | ||
} | ||
console.log(outputFormat); | ||
}, | ||
_printCoverageSummary: function _printCoverageSummary() { | ||
var passColor = '\u001b[0;32m', | ||
failColor = '\u001b[0;31m', | ||
originColor = '\u001b[0m', | ||
passes = this.totalPasses, | ||
fails = this.totalFailures, | ||
totals = passes + fails, | ||
output; | ||
if (this.totalFailures === 0) { | ||
output = passColor + 'SUMMARY COVERAGE PASS: ' + passes + '/' + totals; | ||
output += ' files passed coverage'; | ||
} else { | ||
output = failColor + 'SUMMARY COVERAGE FAILS: ' + fails + '/' + totals; | ||
output += ' files failed coverage'; | ||
} | ||
console.log(output + originColor); | ||
}, | ||
setupThresholds: function setupThresholds() { | ||
this.thresholds = {}; | ||
if (this.path) { | ||
this.thresholds = require(this.path); | ||
} | ||
}, | ||
getAppThreshold: function getAppThreshold(appName) { | ||
return this.thresholds[appName] || 0; | ||
}, | ||
validateThreshold: function validateThreshold(appName, dataItem) { | ||
return (dataItem.percentage > this.getAppThreshold(appName)); | ||
} | ||
}; | ||
@@ -106,0 +187,0 @@ |
@@ -145,3 +145,2 @@ (function(window) { | ||
box.mocha.setup({ | ||
ignoreLeaks: true, | ||
globals: globalIgnores, | ||
@@ -148,0 +147,0 @@ ui: self.ui, |
{ | ||
"name": "test-agent", | ||
"version": "0.22.9", | ||
"version": "0.22.10", | ||
"author": "James Lal", | ||
@@ -5,0 +5,0 @@ "description": "execute client side tests from browser report back to cli", |
Sorry, the diff of this file is too big to display
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
254510
74
7933
23