-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
85 lines (69 loc) · 2.25 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var fs = require("fs"),
PACKAGE_KEY = "travis-cov",
THRESHOLD_KEY = "threshold",
GLOBAL_KEY = "global",
LOCAL_KEY = "local",
REMOVE_KEY = "removeKey",
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){
var scripts = userPkg.scripts
, config = userPkg.config
, userOpts;
if (scripts && scripts[PACKAGE_KEY]){
console.warn(path + ": `scripts[\"travis-cov\"]` is deprecated. Please migrate to `config[\"travis-cov\"]`.\n");
userOpts = scripts[PACKAGE_KEY];
} else if (config && config[PACKAGE_KEY]){
userOpts = config[PACKAGE_KEY];
}
if (userOpts){
options.threshold = userOpts[THRESHOLD_KEY] || options.threshold;
options.global = userOpts[GLOBAL_KEY] || options.global;
options.local = userOpts[LOCAL_KEY] || options.local;
options.removeKey = userOpts[REMOVE_KEY];
}
}
}
if (typeof options.removeKey != "undefined"){
//blanket specific
delete cov[options.removeKey];
}
travisCov.check(cov,options);
});
runner.on('fail', function(test,err){
console.log("Tests failed.\n");
if (err){
var message = err.message || ''
, stack = err.stack || message
, index = stack.indexOf(message) + message.length
, msg = stack.slice(0, index)
, actual = err.actual
, expected = err.expected
, escape = true;
console.log(msg + stack);
}
process.exit(1);
});
}