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

grunt-protractor-coverage

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-protractor-coverage - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

test/protractor/exclude.spec.js

10

Gruntfile.js

@@ -47,3 +47,3 @@ /*

},
phantom: {
local: {
options: {

@@ -53,8 +53,9 @@ args: {

// Arguments passed to the command
'browser': 'phantomjs'
'browser': 'chrome'
}
}
},
chrome: {
remote: {
options: {
configFile: "test/protractorConf.remote.js", // Default config file
args: {

@@ -112,3 +113,4 @@ baseUrl: 'http://localhost:3000/',

// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'copy', 'instrument', 'connect:server', 'protractor_coverage:chrome', 'makeReport']);
grunt.registerTask('test', ['clean', 'copy', 'instrument', 'connect:server', 'protractor_coverage:local', 'makeReport']);
grunt.registerTask('test-remote', ['clean', 'copy', 'instrument', 'connect:server', 'protractor_coverage:remote', 'makeReport']);

@@ -115,0 +117,0 @@ // By default, lint and run all tests.

7

package.json
{
"name": "grunt-protractor-coverage",
"version": "0.2.5",
"version": "0.2.6",
"description": "Instrument your code and gather coverage data from Protractor E2E tests",

@@ -12,3 +12,2 @@ "main": "Gruntfile.js",

"grunt-istanbul": "~0.2.5",
"grunt-protractor-runner": "~0.2.4",
"protractor": "~0.20.1",

@@ -23,3 +22,3 @@ "dargs-object": "~0.2.0",

"escodegen": "~1.3.0",
"coverage-collector": "0.0.3"
"coverage-collector": "0.0.4"
},

@@ -35,3 +34,3 @@ "devDependencies": {

"scripts": {
"test": "grunt test"
"test": "grunt clean jshint test-remote"
},

@@ -38,0 +37,0 @@ "repository": {

@@ -33,2 +33,43 @@ /*

module.exports = function(grunt) {
function instrumentSpecFile(payload, file){
var code= grunt.file.read(file);
var ast=esprima.parse(code);
if(!ast){
return;
}
estraverse.traverse(ast, {
enter: function (node, parent) {
if(node.type==='CallExpression' && node.callee.type==='Identifier' && node.callee.name==='describe'){
node.arguments
.filter(function(n){return n.type==='FunctionExpression';})
.forEach(function(f){
f.body.body=payload.body.concat(f.body.body);
});
}
}
});
estraverse.traverse(ast, {
enter: function (node, parent) {
if(node.type==='CallExpression' && node.callee.type==='Identifier' && node.callee.name==='require'){
node.arguments=node.arguments
.map(function(f){
if(f.type==='Literal'){
grunt.verbose.warn(JSON.stringify(f,null,4));
if(/^\.\//.test(f.value)){
if(!/\.js$/.test(f.value)){
f.value=f.value+'.js';
}
}
f.value=f.value.replace(/^\.\//, path.dirname(file)+'/');
}
return f;
});
}
}
});
var newSpecFile=(new tmp.File()).path;
grunt.verbose.writeln("Writing new Spec file: %s", newSpecFile);
grunt.file.write(newSpecFile, escodegen.generate(ast));
return newSpecFile;
}

@@ -101,50 +142,11 @@ grunt.registerMultiTask('protractor_coverage', 'Instrument your code and gather coverage data from Protractor E2E tests', function() {

specs = specs.concat(pConfigs.config.specs || []);
grunt.verbose.writeln("Provided specs:", specs);
var files = grunt.file.expand({cwd:configDir},specs);
if(!files.length){
files=grunt.file.expand({cwd:process.cwd()},specs);
}
grunt.verbose.writeln("Expanded specs:", files);
//for each spec file, wrap each method call with a closure to save the coverage object
specs.forEach(function(pattern){
var files=[];
files=files.concat(grunt.file.expand(configDir+'/'+pattern));
if(files.length===0){
files=files.concat(grunt.file.expand(process.cwd()+'/'+pattern));
}
files.forEach(function(file){
var code= grunt.file.read(file);
var ast=esprima.parse(code);
if(!ast){
return;
}
estraverse.traverse(ast, {
enter: function (node, parent) {
if(node.type==='CallExpression' && node.callee.type==='Identifier' && node.callee.name==='describe'){
node.arguments
.filter(function(n){return n.type==='FunctionExpression';})
.forEach(function(f){
f.body.body=saveCoverageAST.body.concat(f.body.body);
});
}
}
});
estraverse.traverse(ast, {
enter: function (node, parent) {
if(node.type==='CallExpression' && node.callee.type==='Identifier' && node.callee.name==='require'){
node.arguments=node.arguments
.map(function(f){
if(f.type==='Literal'){
grunt.verbose.warn(JSON.stringify(f,null,4));
if(/^\.\//.test(f.value)){
if(!/\.js$/.test(f.value)){
f.value=f.value+'.js';
}
}
f.value=f.value.replace(/^\.\//, path.dirname(file)+'/');
}
return f;
});
}
}
});
var newSpecFile=(new tmp.File()).path;
grunt.file.write(newSpecFile, escodegen.generate(ast));
suppliedArgs.specs.push(newSpecFile);
});
});
suppliedArgs.specs=files.map(function(file){return instrumentSpecFile(saveCoverageAST, file);});
args = args

@@ -224,7 +226,7 @@ .concat(dargs(suppliedArgs, {

try{
var data=JSON.parse(payload);
data.forEach(function(obj, i){
var filename=path.normalize([coverageDir,'/',i, '.json'].join(''));
fs.writeFileSync(filename, JSON.stringify(obj));
});
// var data=JSON.parse(payload);
// data.forEach(function(obj, i){
var filename=path.normalize([coverageDir,'/coverage.json'].join(''));
fs.writeFileSync(filename, payload);
// });
}catch(e){

@@ -231,0 +233,0 @@ grunt.log.error("Got error: " + e.message);

@@ -39,8 +39,6 @@ // A reference configuration file.

// connect to an already running instance of selenium. This usually looks like
// seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumAddress: 'http://ondemand.saucelabs.com/wd/hub',
seleniumAddress: 'http://localhost:4444/wd/hub',
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
// sauceUser: 'fasterness',
// sauceKey: '128690e9-57c0-485c-9728-464a08acbf69',
// The timeout for each script run on the browser. This should be longer

@@ -54,3 +52,4 @@ // than the maximum time your application needs to stabilize between tasks.

specs: [
'test/protractor/*.spec.js'
'test/protractor/*.spec.js',
'!**/exclude.spec.js'
],

@@ -65,10 +64,5 @@

capabilities: {
'username': process.env['SAUCE_USERNAME'],
'accessKey':process.env['SAUCE_ACCESS_KEY'],
'browserName': 'chrome',
// 'browserName': 'firefox'
// 'browserName': 'phantomjs'
'build': process.env['TRAVIS_BUILD_NUMBER'],
'tags': ['CI'],
'tunnel-identifier': process.env['TRAVIS_JOB_NUMBER'],
},

@@ -75,0 +69,0 @@ params: {

Sorry, the diff of this file is not supported yet

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