forked from BorisOsipov/agent-js-jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·121 lines (98 loc) · 3.14 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const getOptions = require('./utils/getOptions');
const RPClient = require('reportportal-client');
const reportTests = (client, launchObj, suiteObj, tests) => {
tests.forEach((test) => {
const {
ancestorTitles,
duration,
failureMessages,
fullName,
location,
numPassingAsserts,
status,
title,
} = test;
const testObj = client.startTestItem({
name: title,
type: 'TEST'
}, launchObj.tempId, suiteObj.tempId);
// Change status from 'pending' to 'skipped' so the launch finish
// the ran, instead of stay in running status forever.
const testStatus = test.status === 'pending' ? 'skipped' : test.status;
const testFinishObj = client.finishTestItem(testObj.tempId, {
status: testStatus,
end_time: client.helpers.now(),
issue: test.issue
});
});
};
const reportSuites = (client, launchObj, suites) => {
const appDirectory = process.cwd();
suites.forEach((suite) => {
const {
console,
failureMessage,
numFailingTests,
numPassingTests,
numPendingTests,
perfStats,
snapshot,
testFilePath,
testResults,
coverage,
sourceMaps,
skipped,
displayName,
leaks,
} = suite;
const suiteObj = client.startTestItem({
name: testFilePath.replace(appDirectory, ''),
start_time: perfStats.start,
type: 'SUITE',
}, launchObj.tempId);
reportTests(client, launchObj, suiteObj, testResults);
const suiteFinishObj = client.finishTestItem(suiteObj.tempId, {
end_time: perfStats.end,
});
});
};
const processor = (report, reporterOptions = {}) => {
// If jest-junit is used as a reporter allow for reporter options
// to be used. Env and package.json will override.
const options = getOptions.options(reporterOptions);
const rpClient = new RPClient({
token: process.env.RP_TOKEN,
endpoint: options.endpoint,
launch: process.env.RP_LAUNCH_NAME || options.launchname || 'Unit Tests',
project: process.env.RP_PROJECT_NAME || options.project,
description: 'Description of the suite'
});
const endTime = rpClient.helpers.now();
const launchObj = rpClient.startLaunch({
name: process.env.RP_LAUNCH_NAME || options.launchname || 'Unit Tests',
tags: options.tags,
start_time: report.startTime,
});
reportSuites(rpClient, launchObj, report.testResults);
const launchFinishObj = rpClient.finishLaunch(launchObj.tempId, {
end_time: endTime,
});
// Jest 18 compatibility
return report;
};
// This is an old school "class" in order
// for the constructor to be invoked statically and via "new"
// so we can support both testResultsProcessor and reporters
// TODO: refactor to es6 class after testResultsProcessor support is removed
function JestReportPortal (globalConfig, options) {
this.globalConfig = globalConfig;
this.options = options;
this.onRunComplete = (contexts, results) => {
if (process.env.RP_TOKEN === undefined) {
console.log('No ReportPortal token (RP_TOKEN) set. Skipping upload.');
} else {
processor(results, this.options);
}
};
}
module.exports = JestReportPortal;