-
Notifications
You must be signed in to change notification settings - Fork 18
/
SilentReporter.js
73 lines (65 loc) · 2.04 KB
/
SilentReporter.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
const jestUtils = require('jest-util');
const helpers = require('./helpers');
const StdIo = require('./StdIo');
class SilentReporter {
constructor(globalConfig, options = {}) {
this._globalConfig = globalConfig;
this.stdio = new StdIo();
this.useDots = !!process.env.JEST_SILENT_REPORTER_DOTS || !!options.useDots;
this.showPaths =
!!process.env.JEST_SILENT_REPORTER_SHOW_PATHS || !!options.showPaths;
this.showWarnings =
!!process.env.JEST_SILENT_REPORTER_SHOW_WARNINGS ||
!!options.showWarnings;
this.showSeed = !!globalConfig.showSeed
}
onRunStart() {
if (jestUtils.isInteractive) {
jestUtils.clearLine(process.stderr);
}
}
onRunComplete() {
if (this.useDots) {
this.stdio.log('\n');
}
if (this.showSeed) {
this.stdio.log(`Seed: ${this._globalConfig.seed}`)
}
this.stdio.close();
}
onTestResult(test, testResult) {
if (this.useDots) {
this.stdio.logInline('.');
}
if (!testResult.skipped) {
const didUpdate = this._globalConfig.updateSnapshot === 'all';
let hasSnapshotFailures = false;
if (testResult.snapshot) {
if (!didUpdate && testResult.snapshot.unchecked) {
hasSnapshotFailures = true;
}
if (testResult.snapshot.unmatched) {
hasSnapshotFailures = true;
}
}
const hasFailures = testResult.failureMessage || hasSnapshotFailures;
if (this.showPaths && hasFailures) {
this.stdio.log('\n' + test.path);
}
if (testResult.failureMessage)
this.stdio.log('\n' + testResult.failureMessage);
if (testResult.console && this.showWarnings) {
testResult.console
.filter(entry => ['error', 'warn'].includes(entry.type) && entry.message)
.map(entry => entry.message)
.forEach(this.stdio.log);
}
const snapshotStatuses = helpers.getSnapshotStatus(
testResult.snapshot,
didUpdate
);
snapshotStatuses.forEach(this.stdio.log);
}
}
}
module.exports = SilentReporter;