-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 1.17 KB
/
index.js
File metadata and controls
39 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var helper = require('./libs/helper');
var istanbul = require('istanbul');
var instrumenter = new istanbul.Instrumenter();
var through = require('through');
function instrument(file, content) {
return instrumenter.instrumentSync(content, file);
}
module.exports = function (file, options) {
var config = options || {};
var content = '';
var ignoredFile = false;
var patternsToBeIgnored = config.ignores || [];
var patternsToBeContained = config.contains || [];
if (patternsToBeIgnored.length) {
ignoredFile = (helper.containsPatterns(file, patternsToBeIgnored) || ignoredFile);
}
if (patternsToBeContained.length) {
ignoredFile = (helper.doNotContainsPatterns(file, patternsToBeContained) || ignoredFile);
}
function write (buffer) {
content += buffer;
}
function end () {
var code = helper.getCode(content);
var ignoredInCoverage = helper.hasCommentWith(code, new RegExp('ignored +by +test +coverage'));
var src = (ignoredInCoverage) ? content : instrument(file, content);
this.queue(src);
this.queue(null);
}
return (ignoredFile) ? through() : through(write, end);
};