grunt-contrib-jasmine-phantom
Advanced tools
Comparing version 0.8.6 to 0.8.7
{ | ||
"name": "grunt-contrib-jasmine-phantom", | ||
"description": "Run jasmine specs headlessly through PhantomJS with more memory optimization.", | ||
"version": "0.8.6", | ||
"version": "0.8.7", | ||
"homepage": "https://github.com/undefinedN/grunt-contrib-jasmine-phantom", | ||
@@ -28,10 +28,13 @@ "author": { | ||
"dependencies": { | ||
"grunt-lib-phantomjs": "^0.6.0", | ||
"rimraf": "~2.1.4", | ||
"async": ">=0.9.0", | ||
"chalk": "~0.4.0", | ||
"lodash": "~2.4.1", | ||
"console.table": ">=0.4.0", | ||
"es5-shim": "~4.0.1", | ||
"fs-extra": "^0.16.3", | ||
"grunt-lib-phantomjs": "^0.6.0", | ||
"jasmine-core": ">=2.0.4", | ||
"async": ">=0.9.0", | ||
"console.table": ">=0.4.0" | ||
"lcov-result-merger": "^1.0.2", | ||
"lodash": "~2.4.1", | ||
"node-uuid": "^1.4.2", | ||
"rimraf": "~2.1.4" | ||
}, | ||
@@ -58,3 +61,35 @@ "devDependencies": { | ||
"memory leak fix" | ||
] | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Jarrod Overson", | ||
"url": "http://jarrodoverson.com" | ||
}, | ||
{ | ||
"name": "\"Cowboy\" Ben Alman", | ||
"url": "http://benalman.com" | ||
} | ||
], | ||
"gitHead": "d516ba15c2c06c25a3e7c635bf86b89526040e9e", | ||
"_id": "grunt-contrib-jasmine-phantom@0.8.6", | ||
"_shasum": "63349182793606dcc94732d659ff42abac2c53df", | ||
"_from": "grunt-contrib-jasmine-phantom@>=0.8.6 <0.9.0", | ||
"_npmVersion": "2.3.0", | ||
"_nodeVersion": "0.10.35", | ||
"_npmUser": { | ||
"name": "svap.reddy", | ||
"email": "svap.reddy@hotmail.com" | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "svap.reddy", | ||
"email": "svap.reddy@hotmail.com" | ||
} | ||
], | ||
"dist": { | ||
"shasum": "63349182793606dcc94732d659ff42abac2c53df", | ||
"tarball": "http://registry.npmjs.org/grunt-contrib-jasmine-phantom/-/grunt-contrib-jasmine-phantom-0.8.6.tgz" | ||
}, | ||
"directories": {}, | ||
"_resolved": "https://registry.npmjs.org/grunt-contrib-jasmine-phantom/-/grunt-contrib-jasmine-phantom-0.8.6.tgz" | ||
} |
@@ -1,2 +0,2 @@ | ||
# grunt-contrib-jasmine v0.8.2 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-jasmine.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-jasmine) | ||
# grunt-contrib-jasmine-phantom v0.8.5 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-jasmine.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-jasmine) | ||
@@ -35,2 +35,4 @@ > Run jasmine specs headlessly through PhantomJS. | ||
`unit` -> It contains options for jasmine task to run specs. | ||
Automatically builds and maintains your spec runner and runs your tests headlessly through PhantomJS. | ||
@@ -42,2 +44,6 @@ | ||
#### Run with code coverage | ||
Specify coverage field in options passed as mentioned in options section and the run `jasmine:unit --coverage` | ||
#### Customize your SpecRunner with templates | ||
@@ -63,2 +69,18 @@ | ||
#### coverage | ||
Type: `Object` | ||
Configuration to run code coverage. By the default this plugin uses Blanket js. | ||
Example: | ||
coverage: { | ||
yes: 'app/', // To be covered | ||
no: "[spec, app/vendor]", // To be skipped | ||
onCoverage: function(cb) { // Callback to run after all specs executed. | ||
// Do your stuff with this.lcovPath, this.leastCovered and this.percentage | ||
cb(); | ||
} | ||
} | ||
#### src | ||
@@ -65,0 +87,0 @@ Type: `String|Array` |
@@ -17,2 +17,4 @@ /* | ||
var uuid = require('node-uuid'); | ||
function msToTime(duration) { | ||
@@ -41,5 +43,5 @@ var milliseconds = parseInt((duration % 1000) / 100), | ||
ws.on('open', function() { | ||
ws.send('Connected'); | ||
});*/ | ||
ws.on('open', function() { | ||
ws.send('Connected'); | ||
});*/ | ||
@@ -76,4 +78,2 @@ // npm lib | ||
function shuffleArray(array) { | ||
@@ -111,2 +111,20 @@ for (var i = array.length - 1; i > 0; i--) { | ||
try { | ||
fs.mkdirSync('./lcov'); | ||
} catch (e) { | ||
} | ||
var reportQueue = []; | ||
/*async.queue(function(task, cb) { | ||
var id = 'locv_' + task.file; | ||
fs.writeFileSync('./lcov/' + id + '.info', task.data, 'utf8', function(err){ | ||
if(err) { | ||
console.log('Error storing report for ' + task.file); | ||
} | ||
cb(); | ||
}); | ||
}, 10)*/ | ||
; | ||
var $phantomjs = require('grunt-lib-phantomjs'); | ||
@@ -117,3 +135,8 @@ | ||
grunt.registerMultiTask('jasmine', 'Run jasmine specs headlessly through PhantomJS.', function () { | ||
var done = this.async(); | ||
var cover = grunt.option('coverage'); | ||
var LZString = require('../vendor/lz-string.js'); | ||
var providedSpecs, optionalHandlers, eventName, handler; | ||
@@ -146,5 +169,8 @@ | ||
summary: false, | ||
cover: false, | ||
'--load-images': false | ||
}); | ||
options.cover = cover; | ||
if (grunt.option('debug')) { | ||
@@ -184,6 +210,4 @@ grunt.log.debug(options); | ||
var done = this.async(); | ||
var outFileName = options.outfile.replace('.html', (options.cover && options.coverage ? '_phantom' : '') + '.html'); | ||
var outFileName = options.outfile; | ||
var totalSpecs = 0, | ||
@@ -230,12 +254,16 @@ totalTime = 0, | ||
switch (item.status) { | ||
case "passed": | ||
msgC = chalk.italic.green; | ||
pipeC = chalk.cyan; | ||
break; | ||
case "failed": | ||
intFailed += 1; | ||
msgC = chalk.italic.red; | ||
pipeC = chalk.red; | ||
failedSpecs[failedSpecs.length] = item; | ||
break; | ||
case "passed": | ||
msgC = chalk.italic.green; | ||
pipeC = chalk.cyan; | ||
break; | ||
case "failed": | ||
intFailed += 1; | ||
msgC = chalk.italic.red; | ||
pipeC = chalk.red; | ||
failedSpecs[failedSpecs.length] = item; | ||
break; | ||
default: | ||
msgC = chalk.bgYellow.black; | ||
pipeC = chalk.red; | ||
break; | ||
} | ||
@@ -268,2 +296,4 @@ console.log((new Array(indentLevel + 1).join(' ')) + pipeC('| ') + time('( ' + item.duration + 'ms' + ' ) ') + msgC(item.description)); | ||
var coverageReport = {}; | ||
function enque(callback) { | ||
@@ -280,3 +310,3 @@ | ||
return phantomjs.spawn(file, { | ||
var x = phantomjs.spawn(file, { | ||
failCode: 90, | ||
@@ -287,3 +317,3 @@ options: options, | ||
} | ||
}).pid; | ||
}); | ||
@@ -307,4 +337,5 @@ } | ||
phantomjs.on('jasmine.jasmineDone', function () { | ||
// console.log(chalk.red('Jasmine done from one of the instances')); | ||
callback(null, thisReport); | ||
phantomjs.halt(); | ||
callback(null, thisReport); | ||
// console.log(specsLeft); | ||
@@ -314,2 +345,3 @@ }); | ||
phantomjs.on('jasmine.completedFile', function (report) { | ||
// console.log(report.file + ' is completed'); | ||
var idx = specsLeft.indexOf(report.file); | ||
@@ -336,3 +368,2 @@ completed += 1; | ||
grunt.log.writeln(); | ||
console.log(arguments); | ||
grunt.warn('PhantomJS timed out, possibly due to an unfinished async spec.', 90); | ||
@@ -342,3 +373,3 @@ }); | ||
phantomjs.on('console', function (msg) { | ||
if (options.debug === true) { | ||
if (options.debug) {// if (msg.indexOf('XMLHttpRequest') === -1) { | ||
grunt.log.writeln('\n' + chalk.yellow('console : ') + chalk.italic(msg)); | ||
@@ -376,2 +407,18 @@ } | ||
phantomjs.on('lcov', function (_report) { | ||
if (_report.data) { | ||
coverageReport[_report.file] = _report.data; | ||
} else { | ||
console.log(chalk.red(_report.file + ' file missed to report.')); | ||
} | ||
_report = null; | ||
}); | ||
optionalHandlers = options.handlers || {}; | ||
for(eventName in optionalHandlers) { | ||
handler = optionalHandlers[eventName]; | ||
phantomjs.on(eventName, typeof handler === "function" ? handler: function(){}); | ||
} | ||
pid = phantomRunner(options, function (err, status) { | ||
@@ -408,3 +455,7 @@ var success = !err && status.failed === 0; | ||
async.parallel(executables, function (err, results) { | ||
exec('killall -9 phantomjs', function (error, stdout, stderr) {}); | ||
// exec('killall -9 phantomjs', function (error, stdout, stderr) {}); | ||
console.log('Reports :' + Object.keys(coverageReport).length); | ||
var count = 0; | ||
@@ -430,6 +481,127 @@ | ||
} else { | ||
console.log('') | ||
console.log(''); | ||
} | ||
done(); | ||
if(options.cover && options.coverage) { | ||
async.parallel([function (cb) { | ||
if (Object.keys(coverageReport).length > 0) { | ||
var fse = require('fs-extra'), tName = './.grunt/grunt-contrib-jasmine/temp'; | ||
fse.removeSync(tName); | ||
console.log(chalk.green.italic('Generating Coverage report...')); | ||
fse.ensureDirSync(tName); | ||
fse.ensureDirSync('./coverage'); | ||
for (var i in coverageReport) { | ||
fse.outputFileSync(tName + '/coverage_' + i + '.log', coverageReport[i]); | ||
delete coverageReport[i]; | ||
} | ||
var mergerPath = './node_modules/grunt-contrib-jasmine-phantom/node_modules/.bin/lcov-result-merger'; | ||
require('child_process').exec(mergerPath + " '" + tName + "/*.log' './coverage/lcov.log'", function (err) { | ||
if (err) { | ||
console.log(err); | ||
console.log(chalk.red('Unable to generate Coverage report. Error while merging it')); | ||
} else { | ||
console.log(chalk.green.italic('Generated Coverage report!')); | ||
} | ||
fse.removeSync(tName); | ||
cb(null, './coverage/lcov.log'); | ||
}); | ||
} else { | ||
cb(null); | ||
} | ||
}], function (errors, results) { | ||
var lcovPath = results[0]; | ||
fs.readFile(lcovPath, "utf8", function (err, data) { | ||
if (err) { | ||
console.log('Something bad happened while reading lcov string'); | ||
throw err; | ||
} | ||
data = data.split('end_of_record'); | ||
var readBlock = function (cb) { | ||
var results, name, gotHits, block, total; | ||
block = this.block; | ||
results = block.split('\n'); | ||
name = results.splice(0, 1).pop(); | ||
gotHits = total = 0; | ||
results.forEach(function (line) { | ||
try { | ||
line = line.split(':')[1].split(','); | ||
total += 1; | ||
if (+line[1] !== 0) { | ||
gotHits += 1; | ||
} | ||
} catch (e) { | ||
} | ||
}); | ||
var percentage = (gotHits / total) * 100; | ||
cb(null, {name: name, percentage: percentage}); | ||
}; | ||
var execute = []; | ||
data.forEach(function (block) { | ||
block = block.trim(); | ||
if (block.length > 0) { | ||
execute[execute.length] = readBlock.bind({block: block}); | ||
} | ||
}); | ||
async.parallel(execute, function (err, results) { | ||
var grandTotal = 0; | ||
results = results.sort(function (a, b) { | ||
return a.percentage - b.percentage; | ||
}); | ||
results.forEach(function (a) { | ||
grandTotal += parseFloat(a.percentage); | ||
}); | ||
var percentage = (grandTotal / results.length).toFixed(2); | ||
var eventPayLoad = { | ||
percentage: percentage, | ||
leastCovered: results.slice(0, 5), | ||
lcovPath: lcovPath | ||
} | ||
console.log('\n' + chalk.green.bold('****************** Coverage Report ******************') + '\n'); | ||
console.log(chalk.green.bold.underline('Code coverage: ' + percentage) + '% \n'); | ||
var count = 0; | ||
results = results.map(function (v) { | ||
v.percentage = v.percentage.toFixed(2); | ||
return v; | ||
}); | ||
console.table(results); | ||
if (options.coverage && typeof options.coverage.onCoverage === "function") { | ||
options.coverage.onCoverage.call(eventPayLoad, function () { | ||
done(); | ||
}); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
@@ -436,0 +608,0 @@ |
@@ -83,3 +83,2 @@ | ||
this.started = true; | ||
//phantom.sendMessage('jasmine.jasmineStarted'); | ||
}; | ||
@@ -124,4 +123,10 @@ | ||
PhantomReporter.prototype.jasmineDone = function () { | ||
window.$jasmineDone = function(){ | ||
if(window.blanket) { | ||
phantom.sendMessage('lcov', { data: window._$blanket_LCOV, file: current }); | ||
} | ||
console.log('Jasmine done'); | ||
this.finished = true; | ||
@@ -147,13 +152,13 @@ | ||
// document.location.replace('http://localhost/'); | ||
window.setTimeout(function() { | ||
document.location.replace(path); | ||
}, 0); | ||
document.location.replace(path); | ||
} else { | ||
//console.log('last : ' + current); | ||
phantom.sendMessage('jasmine.jasmineDone'); | ||
// phantom.sendMessage('jasmine.done.PhantomReporter'); | ||
} | ||
}; | ||
} | ||
if(!window.blanket) { | ||
PhantomReporter.prototype.jasmineDone = window.$jasmineDone; | ||
} | ||
PhantomReporter.prototype.suiteDone = function (suiteMetadata) { | ||
@@ -240,2 +245,3 @@ if (suiteMetadata.fullName.indexOf(current) === 0) { | ||
}); | ||
return string; | ||
@@ -242,0 +248,0 @@ } |
@@ -81,2 +81,13 @@ | ||
if(options.cover && options.coverage) { | ||
exports.copyTempFile(__dirname + '/../../vendor/blanket.js', 'blanket.js'); | ||
exports.copyTempFile(__dirname + '/../../vendor/jasmine-2.x-blanket.js', 'jasmine-2.x-blanket.js'); | ||
exports.copyTempFile(__dirname + '/../../vendor/lcov_reporter.js', 'lcov_reporter.js'); | ||
exports.copyTempFile(__dirname + '/../../vendor/lz-string.js', 'lz_string.js'); | ||
} | ||
[].concat(jasmineRequire.files.cssFiles, jasmineRequire.files.jsFiles).forEach(function(name) { | ||
@@ -137,3 +148,23 @@ var srcPath = path.join(jasmineRequire.files.path, name); | ||
}; | ||
source = options.template.process(grunt, task, context); | ||
if(options.cover && options.coverage) { | ||
var coverStr = function(lcovString){ | ||
return '<script data-cover-only="' + options.coverage.yes + '" data-cover-never="' + options.coverage.no + '" src=".grunt/grunt-contrib-jasmine/blanket.js" ' + lcovString + ' ></script><script src=".grunt/grunt-contrib-jasmine/jasmine-2.x-blanket.js"></script><script src=".grunt/grunt-contrib-jasmine/lz_string.js"></script>'; | ||
}; | ||
// Below is very very dirty. Will remove it with alternative method soon. | ||
var customSource = source; | ||
var fname = specrunner.replace('.html', '_phantom.html'); | ||
var repString = '<script src=".grunt/grunt-contrib-jasmine/boot.js"></script>'; | ||
var lcovString = ' data-cover-reporter=".grunt/grunt-contrib-jasmine/lcov_reporter.js" data-cover-reporter-options=\'{ "toHTML": false}\' '; | ||
var str = repString + coverStr(lcovString); | ||
customSource = customSource.replace(repString, str); | ||
str = repString + coverStr(''); | ||
source = source.replace(repString, str); | ||
grunt.file.write(fname, customSource); | ||
} | ||
grunt.file.write(specrunner, source); | ||
@@ -180,4 +211,2 @@ } else { | ||
while(patternArray.length > 0) { | ||
pattern = (patternArray.splice(0, 1)[0]); | ||
if(pattern.length > 0) { | ||
@@ -195,2 +224,4 @@ if(pattern.indexOf('/') === -1) { | ||
} | ||
pattern = (patternArray.splice(0, 1)[0]); | ||
} | ||
@@ -197,0 +228,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
490719
32
11718
362
12
9
5
+ Addedfs-extra@^0.16.3
+ Addedlcov-result-merger@^1.0.2
+ Addednode-uuid@^1.4.2
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedduplexify@3.7.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfirst-chunk-stream@1.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfs-extra@0.16.5(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.03.1.0(transitive)
+ Addedglob-stream@5.3.5(transitive)
+ Addedgraceful-fs@3.0.12(transitive)
+ Addedgulp-sourcemaps@1.6.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.02.1.1(transitive)
+ Addedis-glob@2.0.13.1.0(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedis-valid-glob@0.3.0(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedlazystream@1.0.1(transitive)
+ Addedlcov-result-merger@1.2.0(transitive)
+ Addedlodash.isequal@4.5.0(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmerge-stream@1.0.1(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednatives@1.1.6(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedordered-read-streams@0.3.0(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpath-dirname@1.0.2(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedreadable-stream@1.0.342.3.83.6.2(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedstream-shift@1.0.3(transitive)
+ Addedstring_decoder@1.1.11.3.0(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-bom-stream@1.0.0(transitive)
+ Addedthrough2@0.6.52.0.54.0.2(transitive)
+ Addedthrough2-filter@2.0.03.1.0(transitive)
+ Addedto-absolute-glob@0.1.1(transitive)
+ Addedunique-stream@2.3.1(transitive)
+ Addedvali-date@1.0.0(transitive)
+ Addedvinyl@1.2.0(transitive)
+ Addedvinyl-fs@2.4.4(transitive)