1 | 'use strict';
|
2 |
|
3 | function Logger(reporter) {
|
4 | if (!(this instanceof Logger)) {
|
5 | throw new TypeError('Class constructor Logger cannot be invoked without \'new\'');
|
6 | }
|
7 |
|
8 | Object.keys(Logger.prototype).forEach(function (key) {
|
9 | this[key] = this[key].bind(this);
|
10 | }, this);
|
11 |
|
12 | this.reporter = reporter;
|
13 | }
|
14 |
|
15 | module.exports = Logger;
|
16 |
|
17 | Logger.prototype.start = function () {
|
18 | if (!this.reporter.start) {
|
19 | return;
|
20 | }
|
21 |
|
22 | this.write(this.reporter.start());
|
23 | };
|
24 |
|
25 | Logger.prototype.reset = function () {
|
26 | if (!this.reporter.reset) {
|
27 | return;
|
28 | }
|
29 |
|
30 | this.write(this.reporter.reset());
|
31 | };
|
32 |
|
33 | Logger.prototype.test = function (test) {
|
34 | this.write(this.reporter.test(test));
|
35 | };
|
36 |
|
37 | Logger.prototype.unhandledError = function (err) {
|
38 | if (!this.reporter.unhandledError) {
|
39 | return;
|
40 | }
|
41 |
|
42 | this.write(this.reporter.unhandledError(err));
|
43 | };
|
44 |
|
45 | Logger.prototype.finish = function () {
|
46 | if (!this.reporter.finish) {
|
47 | return;
|
48 | }
|
49 |
|
50 | this.write(this.reporter.finish());
|
51 | };
|
52 |
|
53 | Logger.prototype.write = function (str) {
|
54 | if (typeof str === 'undefined') {
|
55 | return;
|
56 | }
|
57 |
|
58 | this.reporter.write(str);
|
59 | };
|
60 |
|
61 | Logger.prototype.stdout = function (data) {
|
62 | if (!this.reporter.stdout) {
|
63 | return;
|
64 | }
|
65 |
|
66 | this.reporter.stdout(data);
|
67 | };
|
68 |
|
69 | Logger.prototype.stderr = function (data) {
|
70 | if (!this.reporter.stderr) {
|
71 | return;
|
72 | }
|
73 |
|
74 | this.reporter.stderr(data);
|
75 | };
|
76 |
|
77 | Logger.prototype.exit = function (code) {
|
78 |
|
79 |
|
80 | process.stdout.write('');
|
81 | process.stderr.write('');
|
82 |
|
83 |
|
84 | setTimeout(function () {
|
85 | process.exit(code);
|
86 | }, process.env.AVA_APPVEYOR ? 500 : 0);
|
87 | };
|