Permalink
Browse files

Make it work on Windows!

  • Loading branch information...
1 parent 0d851b9 commit 2224aada4b0345bf7cbbb66a8c51c7ae253b5393 @itay committed Mar 25, 2012
Showing with 10 additions and 7 deletions.
  1. +2 −2 bin/cover
  2. +6 −3 index.js
  3. +2 −2 reporters/html.js
View
4 bin/cover
@@ -446,7 +446,7 @@
// For each HTML file, use the template to generate an HTML file,
// and write it out to disk
_.each(htmls, function(html, filename) {
- var outputPath = path.join(htmlDirectory, filename.replace(/\//g, "_") + ".html");
+ var outputPath = path.join(htmlDirectory, filename.replace(/[\/|\:|\\]/g, "_") + ".html");
var htmlTemplateString = fs.readFileSync(path.join(templateDir, "file.html")).toString("utf-8");
var htmlTemplate = _.template(htmlTemplateString);
@@ -465,7 +465,7 @@
var headers = ["Filename", "% Covered", "Missed Lines", "# Lines", "% Blocks", "Missed Blocks", "# Blocks"];
var fileUrls = {};
_.each(files, function(file) {
- fileUrls[path.relative(CWD, file)] = file.replace(/\//g, "_") + ".html";
+ fileUrls[path.relative(CWD, file)] = file.replace(/[\/|\:|\\]/g, "_") + ".html";
});
var indexHtml = indexTemplate({ headers: headers, data: allStats, fileUrls: fileUrls });
View
9 index.js
@@ -354,11 +354,14 @@ var cover = function(fileRegex, ignore, debugDirectory) {
match = new RegExp(fileRegex ? (fileRegex.replace(/\//g, '\\/').replace(/\./g, '\\.')) : ".*", '');
}
- var pathToCoverageStore = path.resolve(path.resolve(__dirname), "coverage_store.js");
+ var pathToCoverageStore = path.resolve(path.resolve(__dirname), "coverage_store.js").replace(/\\/g, "/");
var templatePath = path.resolve(path.resolve(__dirname), "templates", "instrumentation_header.js");
var template = fs.readFileSync(templatePath, 'utf-8');
require.extensions['.js'] = function(module, filename) {
+
+ filename = filename.replace(/\\/g, "/");
+
if(!match.test(filename)) return originalRequire(module, filename);
if(filename === pathToCoverageStore) return originalRequire(module, filename);
@@ -375,7 +378,7 @@ var cover = function(fileRegex, ignore, debugDirectory) {
return originalRequire(module, filename);
}
} while(full !== path.dirname(full));
-
+
var data = stripBOM(fs.readFileSync(filename, 'utf8').trim());
data = data.replace(/^\#\!.*/, '');
@@ -385,7 +388,7 @@ var cover = function(fileRegex, ignore, debugDirectory) {
var newCode = addInstrumentationHeader(template, filename, instrumented, pathToCoverageStore);
if (debugDirectory) {
- var outputPath = path.join(debugDirectory, filename.replace(/\//g, "_") + ".js");
+ var outputPath = path.join(debugDirectory, filename.replace(/[\/|\:|\\]/g, "_") + ".js");
fs.writeFileSync(outputPath, newCode);
}
View
4 reporters/html.js
@@ -64,11 +64,11 @@ module.exports = {
finalOutput.push("</td>");
finalOutput.push("<td class='text' valign='top'>");
finalOutput.push("<pre class='prettyprint lang-js'>");
- finalOutput.push(fileOutput.join("\n"));
+ finalOutput.push(fileOutput.join(""));
finalOutput.push("</pre>");
finalOutput.push("</td>");
- var outputString = finalOutput.join("\n");
+ var outputString = finalOutput.join("");
return outputString;
}

0 comments on commit 2224aad

Please sign in to comment.