Skip to content
This repository
Browse code

Make it work on Windows!

  • Loading branch information...
commit 2224aada4b0345bf7cbbb66a8c51c7ae253b5393 1 parent 0d851b9
Itay Neeman authored

Showing 3 changed files with 10 additions and 7 deletions. Show diff stats Hide diff stats

  1. +2 2 bin/cover
  2. +6 3 index.js
  3. +2 2 reporters/html.js
4 bin/cover
@@ -446,7 +446,7 @@
446 446 // For each HTML file, use the template to generate an HTML file,
447 447 // and write it out to disk
448 448 _.each(htmls, function(html, filename) {
449   - var outputPath = path.join(htmlDirectory, filename.replace(/\//g, "_") + ".html");
  449 + var outputPath = path.join(htmlDirectory, filename.replace(/[\/|\:|\\]/g, "_") + ".html");
450 450
451 451 var htmlTemplateString = fs.readFileSync(path.join(templateDir, "file.html")).toString("utf-8");
452 452 var htmlTemplate = _.template(htmlTemplateString);
@@ -465,7 +465,7 @@
465 465 var headers = ["Filename", "% Covered", "Missed Lines", "# Lines", "% Blocks", "Missed Blocks", "# Blocks"];
466 466 var fileUrls = {};
467 467 _.each(files, function(file) {
468   - fileUrls[path.relative(CWD, file)] = file.replace(/\//g, "_") + ".html";
  468 + fileUrls[path.relative(CWD, file)] = file.replace(/[\/|\:|\\]/g, "_") + ".html";
469 469 });
470 470
471 471 var indexHtml = indexTemplate({ headers: headers, data: allStats, fileUrls: fileUrls });
9 index.js
@@ -354,11 +354,14 @@ var cover = function(fileRegex, ignore, debugDirectory) {
354 354 match = new RegExp(fileRegex ? (fileRegex.replace(/\//g, '\\/').replace(/\./g, '\\.')) : ".*", '');
355 355 }
356 356
357   - var pathToCoverageStore = path.resolve(path.resolve(__dirname), "coverage_store.js");
  357 + var pathToCoverageStore = path.resolve(path.resolve(__dirname), "coverage_store.js").replace(/\\/g, "/");
358 358 var templatePath = path.resolve(path.resolve(__dirname), "templates", "instrumentation_header.js");
359 359 var template = fs.readFileSync(templatePath, 'utf-8');
360 360
361 361 require.extensions['.js'] = function(module, filename) {
  362 +
  363 + filename = filename.replace(/\\/g, "/");
  364 +
362 365 if(!match.test(filename)) return originalRequire(module, filename);
363 366 if(filename === pathToCoverageStore) return originalRequire(module, filename);
364 367
@@ -375,7 +378,7 @@ var cover = function(fileRegex, ignore, debugDirectory) {
375 378 return originalRequire(module, filename);
376 379 }
377 380 } while(full !== path.dirname(full));
378   -
  381 +
379 382 var data = stripBOM(fs.readFileSync(filename, 'utf8').trim());
380 383 data = data.replace(/^\#\!.*/, '');
381 384
@@ -385,7 +388,7 @@ var cover = function(fileRegex, ignore, debugDirectory) {
385 388 var newCode = addInstrumentationHeader(template, filename, instrumented, pathToCoverageStore);
386 389
387 390 if (debugDirectory) {
388   - var outputPath = path.join(debugDirectory, filename.replace(/\//g, "_") + ".js");
  391 + var outputPath = path.join(debugDirectory, filename.replace(/[\/|\:|\\]/g, "_") + ".js");
389 392 fs.writeFileSync(outputPath, newCode);
390 393 }
391 394
4 reporters/html.js
@@ -64,11 +64,11 @@ module.exports = {
64 64 finalOutput.push("</td>");
65 65 finalOutput.push("<td class='text' valign='top'>");
66 66 finalOutput.push("<pre class='prettyprint lang-js'>");
67   - finalOutput.push(fileOutput.join("\n"));
  67 + finalOutput.push(fileOutput.join(""));
68 68 finalOutput.push("</pre>");
69 69 finalOutput.push("</td>");
70 70
71   - var outputString = finalOutput.join("\n");
  71 + var outputString = finalOutput.join("");
72 72
73 73 return outputString;
74 74 }

0 comments on commit 2224aad

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