-
Notifications
You must be signed in to change notification settings - Fork 63
/
base.js
82 lines (64 loc) · 2.24 KB
/
base.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
"use strict";
const chalk = require("chalk");
const { MasterEvents } = require("../events");
const icons = require("./utils/icons");
const helpers = require("./utils/helpers");
const { initInformer } = require("./informers");
module.exports = class BaseReporter {
static async create(opts = {}) {
const informer = await initInformer(opts);
return new this(informer, opts);
}
constructor(informer) {
this.informer = informer;
}
attachRunner(runner) {
runner.on(MasterEvents.TEST_PASS, test => this._onTestPass(test));
runner.on(MasterEvents.TEST_FAIL, test => this._onTestFail(test));
runner.on(MasterEvents.RETRY, test => this._onRetry(test));
runner.on(MasterEvents.TEST_PENDING, test => this._onTestPending(test));
runner.on(MasterEvents.RUNNER_END, stats => this._onRunnerEnd(stats));
runner.on(MasterEvents.WARNING, info => this._onWarning(info));
runner.on(MasterEvents.ERROR, error => this._onError(error));
runner.on(MasterEvents.INFO, info => this._onInfo(info));
}
_onTestPass(test) {
this._logTestInfo(test, icons.SUCCESS);
}
_onTestFail(test) {
this._logTestInfo(test, icons.FAIL);
}
_onRetry(test) {
this._logTestInfo(test, icons.RETRY);
this.informer.log(`Will be retried. Retries left: ${chalk.yellow(test.retriesLeft)}`);
}
_onTestPending(test) {
this._logTestInfo(test, icons.WARN);
}
_onBeforeRunnerEnd(stats) {
const message = [
`Total: ${chalk.underline(stats.total)}`,
`Passed: ${chalk.green(stats.passed)}`,
`Failed: ${chalk.red(stats.failed)}`,
`Skipped: ${chalk.cyan(stats.skipped)}`,
`Retries: ${chalk.yellow(stats.retries)}`,
];
this.informer.log(message.join(" "));
}
_onRunnerEnd(stats) {
this._onBeforeRunnerEnd(stats);
this.informer.end();
}
_onWarning(info) {
this.informer.warn(info);
}
_onError(error) {
this.informer.error(chalk.red(error));
}
_onInfo(info) {
this.informer.log(info);
}
_logTestInfo(test, icon) {
this.informer.log(`${icon}${helpers.formatTestInfo(test)}`);
}
};