Skip to content
Browse files

Ignore node_modules by default

Add that specific case as an option in .coverrc, or as a --module
options to the run command
  • Loading branch information...
1 parent 2559bf2 commit e5032bcb2a0a93d45c66c6a5ba3510bd90391ac2 @itay committed Mar 24, 2012
Showing with 35 additions and 19 deletions.
  1. +19 −15 README.markdown
  2. +2 −0 bin/.coverrc
  3. +14 −4 bin/cover
View
34 README.markdown
@@ -57,21 +57,25 @@ Cover reads from a `.coverrc` file in your project directory, and it comes
with sensible defaults. Here are the defaults that it uses:
{
- "formatter": "cli",
- "ignore": ".coverignore",
-
- "prefix": "coveragefile_", // Prefix for coverage data files
- "dataDirectory": ".coverage_data", // Directory to put coverage files in
-
- // Formatter-specific info
- "html" : {
- "directory": "cover_html", // Directory to write HTML files too
- "generateIndex": true // Whether to generate an index.html file
- },
-
- "json": {
- }
- }
+ "formatter": "cli",
+ "ignore": ".coverignore",
+
+ "prefix": "coveragefile_", // Prefix for coverage data files
+ "dataDirectory": ".coverage_data", // Directory to put coverage files in
+
+ "debugDirectory": ".coverage_debug", // Directory to put instrumented files in
+
+ "modules": false, // Whether or not to cover node_modules directory
+
+ // Formatter-specific info
+ "html" : {
+ "directory": "cover_html", // Directory to write HTML files too
+ "generateIndex": true // Whether to generate an index.html file
+ },
+
+ "json": {
+ }
+ }
You can also specify which files to ignore using .coverignore. Here is the one used
for Cover itself:
View
2 bin/.coverrc
@@ -7,6 +7,8 @@
"debugDirectory": ".coverage_debug", // Directory to put instrumented files in
+ "modules": false, // Whether or not to cover node_modules directory
+
// Formatter-specific info
"html" : {
"directory": "cover_html", // Directory to write HTML files too
View
18 bin/cover
@@ -62,7 +62,7 @@
return str;
};
- var readIgnoreFile = function(ignorePath) {
+ var readIgnoreFile = function(ignorePath, ignoreModules) {
var ignore = {};
// Get the full path relative to the CWD
@@ -72,7 +72,7 @@
var ignoreContents = fs.readFileSync(fullIgnorePath, "utf-8");
try {
// Note that directory fo the ignore path
- var dir = path.dirname(path.resolve(ignorePath));
+ var dir = path.dirname(fullIgnorePath);
var ignores = ignoreContents.split("\n");
// For each line (ignoring blank ones), get the full path,
@@ -130,7 +130,9 @@
return config;
};
- var getOptionsAndIgnore = function(cmdline) {
+ var getOptionsAndIgnore = function(cmdline, options) {
+ options = options || {};
+
// Get configuration
var config = {};
if (cmdline.config || ".coverrc") {
@@ -153,6 +155,13 @@
}
}
+ // If we didn't override it on the command line and the
+ // coverrc file says to ingore node_modules, then ignore
+ // it
+ if (options.modules !== true && config.modules === false) {
+ ignore[path.resolve(CWD, "node_modules")] = true;
+ }
+
return {
config: config,
ignore: ignore
@@ -655,8 +664,9 @@
commander.command("run <file>")
.description("Run a file and collect code coverage information for it")
.option("-d, --debug", "Enable debugging")
+ .option("-m, --modules", "Enable coverage for node_modules")
.action(function(file, options) {
- var configs = getOptionsAndIgnore(this);
+ var configs = getOptionsAndIgnore(this, options);
var config = configs.config;
var ignore = configs.ignore;
var debug = options.debug;

0 comments on commit e5032bc

Please sign in to comment.
Something went wrong with that request. Please try again.