Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-jasmine-phantom

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-jasmine-phantom - npm Package Compare versions

Comparing version 0.8.6 to 0.8.7

vendor/blanket.js

49

package.json
{
"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 @@

22

tasks/jasmine/reporters/PhantomReporter.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc