-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
not able to use exclude functionality #403
Comments
@pjangam this is definitely a bug, which I've been able to reproduce; there's a workaround you can use in the meantime however.
I suggest running a command more like this:
Keep in mind that some shells expand globs; so it might be better to set this configuration in a |
Thanks @bcoe Given command did work for me. |
i have vendor.bundle.js file that i want to avoid instrumenting because i get FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@lxibarra I face the same issue with vendor.js file. can you let me know how you ignored this file? |
Hi @knagarajan1984 back then i did not got it to work so i ended up writing a small node script that takes a few parameters to know what folders and/or files to instrument/ignore. node sh-instrumenter.js --source=build-dev --target=build-instrumentedProd --codefiles=/myapp/source/files --directoryExclusions=/lib,/components,/models,/controllers,/external --fileExclusion=cache_controller.js,vendor.bundle.js,styles.bundle.js,polyfills.bundle.js,routes.config.js,*.js.map Im not sure if the issue was fixed but if not here is the code for the script, hope it helps. Regards /*
This file will instrument your code for tests coverage
this is an example command you can use
node sh-instrumenter.js --source=build-dev --target=build-instrumentedProd --codefiles=/myapp/src/scripts --directoryExclusions=/lib,/components,/models,/controllers,/external --fileExclusion=cache_controller.js,vendor.bundle.js,styles.bundle.js,polyfills.bundle.js,routes.config.js,*.js.map
*/
var istanbul = require('istanbul-lib-instrument');
var argv = require('yargs').argv;
var Walker = require('walker');
var fs = require('fs-extra');
var path = require('path');
var source = argv.source;
var target = argv.target;
var codefiles = argv.codefiles;
var _directoryExclusions = (argv.directoryExclusions || '').split(',');
var _fileExclusions = (argv.fileExclusion || '').split(',');
var color_green = '\x1b[32m';
var color_default = '\x1b[0m';
var excludedDirectories = [];
var excludedFiles = [];
var directoryExclusions = _directoryExclusions;
var fileExclusions = _fileExclusions;
function excludeDirectory(directory, stat) {
var fullPath;
for (var c = 0; c < directoryExclusions.length; c++) {
fullPath = target + codefiles + directoryExclusions[c].trim();
if(fullPath === directory) {
excludedDirectories.push(directory);
return false;
}
}
return true;
}
function excludeFile(file) {
var excluded = fileExclusions.find(function (exclusion) {
return file.match(exclusion.trim()) === null? false : true;
}) || false;
return excluded;
}
function instrumentFile(fileName) {
var fileSource = fs.readFileSync(fileName, 'utf8');
var instrumentor = istanbul.createInstrumenter({
coverageVariable: '___COVERAGE___',
produceSourceMap: true,
esModules: true,
});
var outputPath = fileName;
var sourceMapUrl = path.basename(outputPath) + '.map';
var instrumentedSource = instrumentor.instrumentSync(fileSource, fileName);
instrumentedSource = instrumentedSource + '\r\n //# sourceMappingURL=' + sourceMapUrl;
var sourceMap = instrumentor.lastSourceMap();
////# sourceMappingURL=inline.bundle.js.map
fs.writeFileSync(outputPath, instrumentedSource);
fs.writeFileSync(outputPath + '.map', JSON.stringify(sourceMap));
}
function copyExcludedElements(excludedArr) {
excludedArr.forEach(function(elem) {
console.log(color_default, 'Copying ', elem.replace(target, source), 'to', elem);
fs.copySync(elem.replace(target, source), elem);
});
}
fs.removeSync(target);
fs.copySync(source, target);
Walker(target + codefiles)
.filterDir(excludeDirectory)
.on('file', function(file, stat) {
var excluded = excludeFile(file);
if(excluded === false) {
console.log('Instrumenting', file);
instrumentFile(file);
} else {
excludedFiles.push(file);
}
})
.on('end', function() {
console.log(color_green, 'Instrumenting finished');
console.log(color_green, 'Completing bundle with un instrumented files');
copyExcludedElements(excludedDirectories);
copyExcludedElements(excludedFiles);
console.log(color_green, 'Done');
console.log(color_default, '.');
});
` |
The |
Good to know thanks |
Expected Behavior
nyc command should work with exclude switch
Observed Behavior
nyc fails to instrument when I use exclude switch in command
Bonus Points! Code (or Repository) that Reproduces Issue
from command line in my project folder
nyc -x
submodules/**/*.js
--reporter=text --all node_modules/mocha/bin/mocha -- testForensic Information
getting error
command run properly when i remove
-x submodules/**/*.js
Operating System: windows 8 (64 bit)
Environment Information: output.txt
The text was updated successfully, but these errors were encountered: