-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
57 lines (56 loc) · 1.71 KB
/
worker.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
'use strict';
module.exports = {
init: function (config, job, context, cb) {
return cb(null, {
// any extra env variables. Will be available during all phases
env: {
error: false
},
listen: function (emitter, innercontext) {
emitter.on('job.status.tested', function () {
emitter.emit('plugin.strider-nyc.started', job);
});
},
test: function (context, done) {
var self = this;
context.cmd({
cmd: 'nyc --reporter=none --all _mocha -R json-cov'
}, function (err, stdout) {
if(err){
self.env.error = err;
self.env.error_true = true;
}
var beginOfJson = stdout.indexOf('{');
var jsonString = stdout.substr(beginOfJson, stdout.length);
var report;
try {
report = JSON.parse(jsonString);
} catch (e) {
return done(new Error('coverage report not json'));
}
job.test_results = {
stats: report.stats,
failures: report.failures
};
context.cmd({
cmd: 'nyc report --reporter=text-summary'
}, function (err, stdout) {
if(err){
self.env.error = true;
}
var index = stdout.indexOf('=');
var valid = stdout.substr(index, stdout.length);
valid = valid.replace(/=/g, '');
job.coverage_results = valid;
context.cmd({
cmd: 'nyc report --reporter=html'
}, function(err, stdout){
if(self.env.error_true) return done(self.env.error);
done();
});
});
});
}
});
}
};