summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-04-14 23:33:43 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-04-14 23:42:08 -0700
commitb4ff36a41b242c0b379d3c27fb30818de54fe2d4 (patch)
tree32e388da2e4e00ad16682579431d96bd1f36cc49 /lib/module.js
parent80711b0ff90cede610365cba65e46c3128b57bfd (diff)
downloadnode-new-b4ff36a41b242c0b379d3c27fb30818de54fe2d4.tar.gz
Add --cov code coverage option
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/module.js b/lib/module.js
index d806a4ae82..308fd4e8e3 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -347,6 +347,22 @@ Module.prototype._compile = function(content, filename) {
// remove shebang
content = content.replace(/^\#\!.*/, '');
+ // add coverage
+ if (process.cov) {
+ var lines = content.split('\n');
+
+ if (lines.length > 0) {
+ lines[0] = '__cov[__filename] = { 0: true}; ' + lines[0];
+ }
+
+ for (var i = 0; i < lines.length; i++) {
+ lines[i] =
+ lines[i].replace(/;$/, '; __cov[__filename][' + i + '] = true;');
+ }
+
+ content = lines.join('\n');
+ }
+
function require(path) {
return Module._load(path, self);
}