-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (45 loc) · 1.61 KB
/
index.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
import WDIOReporter from '@wdio/reporter';
import { Mailer } from './src/mailer.js';
import { getFeatures, addScenarioStatus, closeFeature } from './src/dataHandler';
export default class ReportMailer extends WDIOReporter {
constructor(options) {
/*
* make reporter to write to the output stream by default
*/
options = Object.assign(options, { stdout: true});
super(options);
this.mailer = new Mailer(options['mail']);
this.isWaiting = false;
}
get isSynchronised() {
return !this.isWaiting
}
onSuiteEnd(suite) {
if(suite.type === 'scenario') {
const state = suite.tests.map(el => el.state);
if (state.includes('failed')) {
addScenarioStatus(suite.title, 'fail');
} else if(state.includes('skipped')) {
addScenarioStatus(suite.title, 'skip');
} else {
addScenarioStatus(suite.title, 'pass');
}
} else if(suite.type === 'feature') {
closeFeature(suite.title);
}
}
async onRunnerEnd(runner) {
const lastSpec = runner.config.specs[runner.config.specs.length - 1];
const currentSpec = runner.specs[0];
if(lastSpec.slice(1, lastSpec.length) === currentSpec) {
this.isWaiting = true;
try{
await this.mailer.sendMail(getFeatures());
} catch(err) {
this.write(`Sorry, an error was throw: ${err}`)
}
this.write(JSON.stringify(getFeatures()));
this.isWaiting = false;
}
}
};