/
index.js
58 lines (47 loc) · 1.51 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var fs = require("fs"),
PACKAGE_KEY = "travis-cov",
THRESHOLD_KEY = "threshold",
GLOBAL_KEY = "global",
LOCAL_KEY = "local",
travisCov = require("./travisCov").travisCov;
/**
* Expose `TrvsCov`.
*/
exports = module.exports = TrvsCov;
/**
* Initialize a new TrvsCov reporter.
* Threshold defaults to 50, but you can pass it a custom threshold
* by putting "blanketThreshold<number>" as a global variable
* in the runner. The value of the global variable is not used,
* but rather we parse the variable name itself
* Not ideal, but it works.
*
* @param {Runner} runner
* @api public
*/
function TrvsCov(runner) {
runner.on('end', function(){
var cov = global._$jscoverage || {},
options = {};
var path = process.cwd() + '/package.json';
var exists = fs.existsSync(path);
if (exists){
var userPkg = JSON.parse(fs.readFileSync(path, 'utf8'));
if (userPkg && userPkg.scripts && userPkg.scripts[PACKAGE_KEY]){
var userOpts = userPkg.scripts[PACKAGE_KEY];
options.threshold = userOpts[THRESHOLD_KEY] || options.threshold;
options.global = userOpts[GLOBAL_KEY] || options.global;
options.local = userOpts[LOCAL_KEY] || options.local;
}
}
travisCov.check(cov,options);
});
runner.on('fail', function(test,err){
process.stdout.write("Tests failed.\n");
if (err){
process.stdout.write(err.message.toString());
process.stdout.write(err.stack.toString());
}
process.exit(1);
});
}