-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest-reporter-simple-dispatcher.js
45 lines (41 loc) · 1.31 KB
/
jest-reporter-simple-dispatcher.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
const fetch = require('node-fetch');
class JestReporterSimplePostData {
/**
* constructor for the reporter
*
* @param {Object} globalConfig - Jest configuration object
* @param {Object} options - Options object defined in jest config
*/
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
}
/**
* Hook to process the test run results after all the test suites have been
* executed
*
* @param {string} test - The Test last run
* @param {JestTestRunResult} - Results from the test run
*/
onRunComplete(test, runResults) {
return this.report(runResults);
}
report(data) {
return fetch(this._options.url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
})
.then(response => {
if (!response.ok) {
console.log(`ERROR in response of jest reporter: ${response.statusText}`);
}
})
.catch(e =>
console.log(`ERROR during run of jest reporter: ${e.stack}`)
);
}
}
module.exports = JestReporterSimplePostData;