From 3fcca79f3bf684fbf617f9ddb950c1d951ca9481 Mon Sep 17 00:00:00 2001 From: Marko Martin Date: Fri, 13 Feb 2015 12:23:30 +0100 Subject: [PATCH] [FIX] checkModule and defaultCovIgnore shall work on Windows (MINGW) --- lib/patch.js | 15 +++++++++------ package.json | 30 +++++++++++++++++------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/patch.js b/lib/patch.js index 5cb9f7c..7bd061d 100644 --- a/lib/patch.js +++ b/lib/patch.js @@ -9,11 +9,12 @@ var path = require('path'); var fs = require('fs'); var argv = require('optimist').argv; var jscoverage = require('./jscoverage'); - +var escapeRe = require('escape-string-regexp'); var covInject = false; + var defaultCovIgnore = [ - new RegExp('^' + process.cwd() + '/node_modules/'), - new RegExp('^' + process.cwd() + '/test/') + new RegExp('^' + escapeRe(path.join(process.cwd(),"node_modules/"))), + new RegExp('^' + escapeRe(path.join(process.cwd(),"test/"))) ]; var covIgnore = defaultCovIgnore; @@ -68,7 +69,7 @@ exports.setCovIgnore = function (ignore, bool) { if (flagjsc && cachedModule && cachedModule.__coveraged__) { return cachedModule.exports; } - // console.log('jscoverage:', ff, 'cov', flagjsc, 'inject', needinject); + var module = new Module(filename, this); try { module.filename = filename; @@ -138,17 +139,19 @@ exports.setCovIgnore = function (ignore, bool) { })(); function checkModule(module) { - // native module - if (!/\//.test(module)) { + // native module does not contain / (or \ on windows) + if (!/[\/\\]/.test(module)) { return false; } // modules in node_modules var flagIgnore = false; covIgnore.forEach(function (v) { + if (v.test(module)) { flagIgnore = true; } + }); return !flagIgnore; } diff --git a/package.json b/package.json index b989bc2..dfcd175 100644 --- a/package.json +++ b/package.json @@ -10,20 +10,21 @@ "test": "./node_modules/mocha/bin/_mocha -t 60000 -r ./index.js -R spec --covinject true test/" }, "engines": { - "node" : ">=0.8" + "node": ">=0.8" }, - "dependencies" : { - "uglify-js" : "2.4.15", - "optimist" : "0.3.1", - "xfs" : "0.1.8", - "ejs": "1.0.0", + "dependencies": { + "coffee-script": "*", "debug": "1.0.3", - "coffee-script": "*" + "ejs": "1.0.0", + "escape-string-regexp": "^1.0.2", + "optimist": "0.3.1", + "uglify-js": "2.4.15", + "xfs": "0.1.8" }, - "devDependencies" : { - "mocha" : "*", - "expect.js" : "*", - "xfs" : "*" + "devDependencies": { + "mocha": "*", + "expect.js": "*", + "xfs": "*" }, "repository": { "type": "git", @@ -38,8 +39,11 @@ "tool" ], "author": "fish , kate.sf ", - "contributors":[ - { "name": "christineRR", "email": "rongkunli1215@gmail.com" } + "contributors": [ + { + "name": "christineRR", + "email": "rongkunli1215@gmail.com" + } ], "license": "MIT" }