grunt-protractor-coverage
Advanced tools
Comparing version 0.1.1 to 0.2.1
{ | ||
"name": "grunt-protractor-coverage", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"description": "Instrument your code and gather coverage data from Protractor E2E tests", | ||
@@ -5,0 +5,0 @@ "main": "Gruntfile.js", |
@@ -17,3 +17,3 @@ /* | ||
var estraverse=require('estraverse'); | ||
var escodegen=require('escodegen') | ||
var escodegen=require('escodegen'); | ||
@@ -23,10 +23,2 @@ module.exports = function(grunt) { | ||
grunt.registerMultiTask('protractor_coverage', 'Instrument your code and gather coverage data from Protractor E2E tests', function() { | ||
var saveCoverageSource = grunt.file.read("resources/saveCoverage.tmpl"); | ||
var saveCoverageContent=grunt.template.process( saveCoverageSource, { | ||
data: { | ||
dirname: coverageDir, | ||
coverage: '__coverage__' | ||
} | ||
}); | ||
var saveCoverageAST=esprima.parse(saveCoverageContent); | ||
// '.../node_modules/protractor/lib/protractor.js' | ||
@@ -46,2 +38,15 @@ var protractorMainPath = require.resolve('protractor'); | ||
}); | ||
var saveCoverageTemplate = grunt.file.expand(["resources/saveCoverage.tmpl", "node_modules/grunt-protractor-coverage/resources/saveCoverage.tmpl", process.cwd()+'/**/resources/saveCoverage.tmpl']).shift(); | ||
if(!saveCoverageTemplate){ | ||
grunt.fail.fatal("Coverage template file not found."); | ||
} | ||
var coverageDir = path.resolve(opts.coverageDir||'coverage/'); | ||
var saveCoverageSource = grunt.file.read(saveCoverageTemplate); | ||
var saveCoverageContent=grunt.template.process( saveCoverageSource, { | ||
data: { | ||
dirname: coverageDir, | ||
coverage: '__coverage__' | ||
} | ||
}); | ||
var saveCoverageAST=esprima.parse(saveCoverageContent); | ||
grunt.verbose.writeln("Options: " + util.inspect(opts)); | ||
@@ -77,4 +82,3 @@ | ||
}, {}); | ||
var coverageDir = path.resolve(opts.coverageDir||'coverage/'); | ||
var configDir=path.dirname(path.resolve(opts.configFile)); | ||
grunt.file.mkdir(coverageDir); | ||
@@ -86,9 +90,15 @@ | ||
specs = specs.concat(pConfigs.config.specs || []); | ||
//for each spec file, wrap each method call with a closure to save the coverage object | ||
specs.forEach(function(pattern){ | ||
grunt.file.expand(pattern).forEach(function(file){ | ||
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; | ||
if(!ast){ | ||
return; | ||
} | ||
estraverse.traverse(ast, { | ||
@@ -98,5 +108,5 @@ enter: function (node, parent) { | ||
node.arguments | ||
.filter(function(n){return n.type==='FunctionExpression'}) | ||
.filter(function(n){return n.type==='FunctionExpression';}) | ||
.forEach(function(f){ | ||
f.body.body=saveCoverageAST.body.concat(f.body.body) | ||
f.body.body=saveCoverageAST.body.concat(f.body.body); | ||
}); | ||
@@ -106,2 +116,21 @@ } | ||
}); | ||
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; | ||
@@ -108,0 +137,0 @@ grunt.file.write(newSpecFile, escodegen.generate(ast)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
8627124
27920