-
Notifications
You must be signed in to change notification settings - Fork 660
/
reporter.js
86 lines (71 loc) · 2.31 KB
/
reporter.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
const baseReport = {
async reportTaskStart () {
},
async reportFixtureStart () {
},
async reportTestDone () {
},
async reportTaskDone () {
}
};
function generateReporter (log, options = {}) {
const {
emitOnStart = true,
emitOnDone = true,
includeBrowserInfo = false,
includeTestInfo = false
} = options;
return function () {
return Object.assign({}, baseReport, {
async reportTestActionStart (name, { browser, test, fixture }) {
if (!emitOnStart)
return;
const item = { action: 'start', name };
if (includeBrowserInfo)
item.browser = browser.alias.split(':')[0];
if (includeTestInfo) {
if (test.id) {
item.test = {
id: 'test-id',
name: test.name,
phase: test.phase
};
}
if (fixture.id) {
item.fixture = {
id: 'fixture-id',
name: fixture.name
};
}
}
log.push(item);
},
async reportTestActionDone (name, { command, test, fixture, err }) {
if (!emitOnDone)
return;
if (command.selector)
command.selector = command.selector.expression;
const item = { name, action: 'done', command };
if (err)
item.err = err.code;
if (includeTestInfo) {
if (test.id) {
item.test = {
id: 'test-id',
name: test.name,
phase: test.phase
};
}
if (fixture.id) {
item.fixture = {
id: 'fixture-id',
name: fixture.name
};
}
}
log.push(item);
}
});
};
}
module.exports = generateReporter;