Permalink
Browse files

Add -d/--debug option to output instrumented files

  • Loading branch information...
itay committed Mar 1, 2012
1 parent 3198613 commit 6cc35721609a137446f75436ad64aca4db7becfe
Showing with 27 additions and 9 deletions.
  1. +2 −1 .gitignore
  2. +2 −0 bin/.coverrc
  3. +16 −7 bin/cover
  4. +6 −1 index.js
  5. +1 −0 templates/instrumentation_header.js
View
@@ -3,4 +3,5 @@
node_modules/*
.coverignore
npm-debug.log
-cover_html/*
+cover_html/*
+.coverage_debug/*
View
@@ -5,6 +5,8 @@
"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
+
// Formatter-specific info
"html" : {
"directory": "cover_html", // Directory to write HTML files too
View
@@ -159,11 +159,11 @@
/* ====== Context and Execution Handling ====== */
- // Run a file with coverage enabled in a new context
- var runFile = function(file, options, ignore) {
+ // Run a file with coverage enabled
+ var runFile = function(file, options, ignore, debug) {
var file = path.resolve(file);
- var coverage = cover.cover(null, ignore);
+ var coverage = cover.cover(null, ignore, debug);
process.nextTick(function() {
try {
@@ -513,9 +513,16 @@
/* ====== Commands ====== */
- var run = function(file, cmdline, config, ignore) {
+ var run = function(file, cmdline, config, ignore, debug) {
+ if (debug) {
+ var debugDirectory = config.debugDirectory;
+ if (!path.existsSync(debugDirectory)) {
+ fs.mkdirSync(debugDirectory, "0755");
+ }
+ }
+
// Run the file
- var coverage = runFile(file, cmdline, ignore);
+ var coverage = runFile(file, cmdline, ignore, debug ? config.debugDirectory : null);
// Setup the on exit listener
process.on(
@@ -635,15 +642,17 @@
commander.command("run <file>")
.description("Run a file and collect code coverage information for it")
- .action(function(file) {
+ .option("-d, --debug", "Enable debugging")
+ .action(function(file, options) {
var configs = getOptionsAndIgnore(this);
var config = configs.config;
var ignore = configs.ignore;
+ var debug = options.debug;
// Remove the command itself
var cmdline = this.args.slice(1);
- run(file, cmdline, config, ignore);
+ run(file, cmdline, config, ignore, debug);
});
commander.command("report [reporter] [file]")
View
@@ -339,7 +339,7 @@ var load = function(datas) {
return combinedCoverage;
}
-var cover = function(fileRegex, ignore) {
+var cover = function(fileRegex, ignore, debugDirectory) {
var originalRequire = require.extensions['.js'];
var coverageData = {};
var match = null;
@@ -383,6 +383,11 @@ var cover = function(fileRegex, ignore) {
var newCode = addInstrumentationHeader(template, filename, instrumented, pathToCoverageStore);
+ if (debugDirectory) {
+ var outputPath = path.join(debugDirectory, filename.replace(/\//g, "_") + ".js");
+ fs.writeFileSync(outputPath, newCode);
+ }
+
return module._compile(newCode, filename);
};
@@ -24,4 +24,5 @@
};
////////////////////////
+// Instrumented Code

0 comments on commit 6cc3572

Please sign in to comment.