forked from avajs/ava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
86 lines (66 loc) · 1.55 KB
/
logger.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
85
86
'use strict';
function Logger() {
if (!(this instanceof Logger)) {
return new Logger();
}
Object.keys(Logger.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);
}
module.exports = Logger;
Logger.prototype.use = function (reporter) {
this.reporter = reporter;
this.reporter.api = this.api;
};
Logger.prototype.start = function () {
if (!this.reporter.start) {
return;
}
this.write(this.reporter.start());
};
Logger.prototype.test = function (test) {
this.write(this.reporter.test(test));
};
Logger.prototype.unhandledError = function (err) {
if (!this.reporter.unhandledError) {
return;
}
this.write(this.reporter.unhandledError(err));
};
Logger.prototype.finish = function () {
if (!this.reporter.finish) {
return;
}
this.write(this.reporter.finish());
};
Logger.prototype.write = function (str) {
if (typeof str === 'undefined') {
return;
}
this.reporter.write(str);
};
Logger.prototype.stdout = function (data) {
if (!this.reporter.stdout) {
return;
}
this.reporter.stdout(data);
};
Logger.prototype.stderr = function (data) {
if (!this.reporter.stderr) {
return;
}
this.reporter.stderr(data);
};
Logger.prototype.exit = function (code) {
// TODO: figure out why this needs to be here to
// correctly flush the output when multiple test files
process.stdout.write('');
process.stderr.write('');
if (this.watch) {
return;
}
// timeout required to correctly flush IO on Node.js 0.10 on Windows
setTimeout(function () {
process.exit(code);
}, process.env.AVA_APPVEYOR ? 500 : 0);
};