@testomatio/reporter 1.3.0-beta → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -54
- package/lib/adapter/codecept.js +96 -35
- package/lib/adapter/cucumber/current.js +18 -11
- package/lib/adapter/cucumber/legacy.js +6 -5
- package/lib/adapter/cucumber.js +2 -2
- package/lib/adapter/cypress-plugin/index.js +52 -25
- package/lib/adapter/jasmine.js +1 -1
- package/lib/adapter/jest.js +49 -16
- package/lib/adapter/mocha.js +103 -51
- package/lib/adapter/playwright.js +95 -33
- package/lib/adapter/webdriver.js +1 -1
- package/lib/bin/reportXml.js +22 -16
- package/lib/bin/startTest.js +27 -6
- package/lib/client.js +180 -61
- package/lib/config.js +34 -0
- package/lib/constants.js +32 -7
- package/lib/data-storage.js +203 -0
- package/lib/fileUploader.js +135 -54
- package/lib/junit-adapter/adapter.js +0 -2
- package/lib/junit-adapter/csharp.js +3 -4
- package/lib/junit-adapter/index.js +3 -3
- package/lib/junit-adapter/java.js +35 -17
- package/lib/junit-adapter/javascript.js +1 -2
- package/lib/junit-adapter/python.js +12 -14
- package/lib/junit-adapter/ruby.js +1 -2
- package/lib/pipe/csv.js +5 -3
- package/lib/pipe/github.js +27 -39
- package/lib/pipe/gitlab.js +22 -26
- package/lib/pipe/html.js +354 -0
- package/lib/pipe/index.js +3 -1
- package/lib/pipe/testomatio.js +259 -53
- package/lib/reporter-functions.js +46 -0
- package/lib/reporter.js +11 -9
- package/lib/services/artifacts.js +57 -0
- package/lib/services/index.js +13 -0
- package/lib/services/key-values.js +58 -0
- package/lib/services/logger.js +311 -0
- package/lib/template/testomatio.hbs +1236 -0
- package/lib/utils/pipe_utils.js +129 -0
- package/lib/{util.js → utils/utils.js} +144 -14
- package/lib/xmlReader.js +211 -122
- package/package.json +17 -8
- package/lib/_ArtifactStorageOld.js +0 -142
- package/lib/artifactStorage.js +0 -25
- package/lib/dataStorage.js +0 -244
- package/lib/logger.js +0 -294
package/lib/pipe/testomatio.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
const debug = require('debug')('@testomatio/reporter:pipe:testomatio');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
|
+
// Retry interceptor function
|
|
4
|
+
const axiosRetry = require('axios-retry');
|
|
5
|
+
// Default axios instance
|
|
3
6
|
const axios = require('axios');
|
|
4
7
|
const JsonCycle = require('json-cycle');
|
|
5
|
-
const { APP_PREFIX, STATUS } = require('../constants');
|
|
6
|
-
const { isValidUrl } = require('../util');
|
|
7
|
-
const { resetConfig } = require('../fileUploader');
|
|
8
8
|
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const { APP_PREFIX, STATUS, AXIOS_TIMEOUT, REPORTER_REQUEST_RETRIES } = require('../constants');
|
|
10
|
+
const { isValidUrl, foundedTestLog } = require('../utils/utils');
|
|
11
|
+
const { parseFilterParams, generateFilterRequestParams, setS3Credentials } = require('../utils/pipe_utils');
|
|
12
|
+
const config = require('../config');
|
|
13
|
+
|
|
14
|
+
if (process.env.TESTOMATIO_RUN) {
|
|
15
|
+
process.env.runId = process.env.TESTOMATIO_RUN;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
/**
|
|
@@ -19,25 +23,64 @@ if (TESTOMATIO_RUN) {
|
|
|
19
23
|
*/
|
|
20
24
|
class TestomatioPipe {
|
|
21
25
|
constructor(params, store) {
|
|
26
|
+
this.retriesTimestamps = [];
|
|
27
|
+
this.reportingCanceledDueToReqFailures = false;
|
|
28
|
+
this.notReportedTestsCount = 0;
|
|
29
|
+
|
|
22
30
|
this.isEnabled = false;
|
|
23
31
|
this.url = params.testomatioUrl || process.env.TESTOMATIO_URL || 'https://app.testomat.io';
|
|
24
|
-
this.apiKey = params.apiKey ||
|
|
32
|
+
this.apiKey = params.apiKey || config.TESTOMATIO;
|
|
25
33
|
debug('Testomatio Pipe: ', this.apiKey ? 'API KEY' : '*no api key*');
|
|
26
34
|
if (!this.apiKey) {
|
|
27
35
|
return;
|
|
28
36
|
}
|
|
29
37
|
debug('Testomatio Pipe: Enabled');
|
|
38
|
+
this.parallel = params.parallel;
|
|
30
39
|
this.store = store || {};
|
|
31
40
|
this.title = params.title || process.env.TESTOMATIO_TITLE;
|
|
32
41
|
this.sharedRun = !!process.env.TESTOMATIO_SHARED_RUN;
|
|
33
42
|
this.groupTitle = params.groupTitle || process.env.TESTOMATIO_RUNGROUP_TITLE;
|
|
34
43
|
this.env = process.env.TESTOMATIO_ENV;
|
|
35
|
-
this.
|
|
44
|
+
this.label = process.env.TESTOMATIO_LABEL;
|
|
45
|
+
// Create a new instance of axios with a custom config
|
|
46
|
+
this.axios = axios.create({
|
|
47
|
+
baseURL: `${this.url.trim()}`,
|
|
48
|
+
timeout: AXIOS_TIMEOUT,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Pass the axios instance to the retry function
|
|
52
|
+
axiosRetry(this.axios, {
|
|
53
|
+
// do not use retries for unit tests
|
|
54
|
+
retries: REPORTER_REQUEST_RETRIES.retriesPerRequest, // Number of retries
|
|
55
|
+
shouldResetTimeout: true,
|
|
56
|
+
retryCondition: error => {
|
|
57
|
+
if (!error.response) return false;
|
|
58
|
+
switch (error.response?.status) {
|
|
59
|
+
case 400: // Bad request (probably wrong API key)
|
|
60
|
+
case 404: // Test not matched
|
|
61
|
+
case 429: // Rate limit exceeded
|
|
62
|
+
case 500: // Internal server error
|
|
63
|
+
return false;
|
|
64
|
+
default:
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return error.response?.status >= 401; // Retry on 401+ and 5xx
|
|
68
|
+
},
|
|
69
|
+
retryDelay: () => REPORTER_REQUEST_RETRIES.retryTimeout, // sum = 15sec
|
|
70
|
+
onRetry: async (retryCount, error) => {
|
|
71
|
+
this.retriesTimestamps.push(Date.now());
|
|
72
|
+
|
|
73
|
+
debug(`${error.message || `Request failed ${error.status}`}. Retry #${retryCount} ...`);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
36
77
|
this.isEnabled = true;
|
|
37
78
|
// do not finish this run (for parallel testing)
|
|
38
79
|
this.proceed = process.env.TESTOMATIO_PROCEED;
|
|
80
|
+
this.jiraId = process.env.TESTOMATIO_JIRA_ID;
|
|
39
81
|
this.runId = params.runId || process.env.runId;
|
|
40
|
-
this.createNewTests = !!process.env.TESTOMATIO_CREATE;
|
|
82
|
+
this.createNewTests = params.createNewTests ?? !!process.env.TESTOMATIO_CREATE;
|
|
83
|
+
this.hasUnmatchedTests = false;
|
|
41
84
|
|
|
42
85
|
if (!isValidUrl(this.url.trim())) {
|
|
43
86
|
this.isEnabled = false;
|
|
@@ -45,92 +88,217 @@ class TestomatioPipe {
|
|
|
45
88
|
}
|
|
46
89
|
}
|
|
47
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Asynchronously prepares and retrieves the Testomat.io test grepList based on the provided options.
|
|
93
|
+
* @param {Object} opts - The options for preparing the test grepList.
|
|
94
|
+
* @returns {Promise<string[]>} - An array containing the retrieved
|
|
95
|
+
* test grepList, or an empty array if no tests are found or the request is disabled.
|
|
96
|
+
* @throws {Error} - Throws an error if there was a problem while making the request.
|
|
97
|
+
*/
|
|
98
|
+
async prepareRun(opts) {
|
|
99
|
+
if (!this.isEnabled) return [];
|
|
100
|
+
|
|
101
|
+
const { type, id } = parseFilterParams(opts);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const q = generateFilterRequestParams({
|
|
105
|
+
type,
|
|
106
|
+
id,
|
|
107
|
+
apiKey: this.apiKey.trim(),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (!q) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const resp = await this.axios.get('/api/test_grep', q);
|
|
115
|
+
const { data } = resp;
|
|
116
|
+
|
|
117
|
+
if (Array.isArray(data?.tests) && data?.tests?.length > 0) {
|
|
118
|
+
foundedTestLog(APP_PREFIX, data.tests);
|
|
119
|
+
return data.tests;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(APP_PREFIX, `⛔ No tests found for your --filter --> ${type}=${id}`);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
console.error(APP_PREFIX, `🚩 Error getting Testomat.io test grepList: ${err}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
48
128
|
/**
|
|
49
129
|
* @returns Promise<void>
|
|
50
130
|
*/
|
|
51
131
|
async createRun() {
|
|
132
|
+
debug('Creating run...');
|
|
52
133
|
if (!this.isEnabled) return;
|
|
53
134
|
|
|
135
|
+
let buildUrl = process.env.BUILD_URL || process.env.CI_JOB_URL || process.env.CIRCLE_BUILD_URL;
|
|
136
|
+
|
|
137
|
+
// GitHub Actions Url
|
|
138
|
+
if (!buildUrl && process.env.GITHUB_RUN_ID) {
|
|
139
|
+
// eslint-disable-next-line max-len
|
|
140
|
+
buildUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Azure DevOps Url
|
|
144
|
+
if (!buildUrl && process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI) {
|
|
145
|
+
const collectionUri = process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI;
|
|
146
|
+
const project = process.env.SYSTEM_TEAMPROJECT;
|
|
147
|
+
const buildId = process.env.BUILD_BUILDID;
|
|
148
|
+
buildUrl = `${collectionUri}/${project}/_build/results?buildId=${buildId}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (buildUrl && !buildUrl.startsWith('http')) buildUrl = undefined;
|
|
152
|
+
|
|
153
|
+
const accessEvent = process.env.TESTOMATIO_PUBLISH ? 'publish' : null;
|
|
154
|
+
|
|
54
155
|
const runParams = Object.fromEntries(
|
|
55
156
|
Object.entries({
|
|
157
|
+
ci_build_url: buildUrl,
|
|
158
|
+
parallel: this.parallel,
|
|
56
159
|
api_key: this.apiKey.trim(),
|
|
57
160
|
group_title: this.groupTitle,
|
|
161
|
+
access_event: accessEvent,
|
|
162
|
+
jira_id: this.jiraId,
|
|
58
163
|
env: this.env,
|
|
59
164
|
title: this.title,
|
|
165
|
+
label: this.label,
|
|
60
166
|
shared_run: this.sharedRun,
|
|
61
|
-
}).filter(([, value]) => !!value)
|
|
167
|
+
}).filter(([, value]) => !!value),
|
|
62
168
|
);
|
|
169
|
+
debug('Run params', JSON.stringify(runParams, null, 2));
|
|
63
170
|
|
|
64
171
|
if (this.runId) {
|
|
65
|
-
|
|
172
|
+
debug(`Run with id ${this.runId} already created, updating...`);
|
|
173
|
+
const resp = await this.axios.put(`/api/reporter/${this.runId}`, runParams);
|
|
66
174
|
if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
|
|
67
175
|
return;
|
|
68
176
|
}
|
|
69
177
|
|
|
70
178
|
try {
|
|
71
|
-
const resp = await this.axios.post(
|
|
179
|
+
const resp = await this.axios.post(`/api/reporter`, runParams, {
|
|
72
180
|
maxContentLength: Infinity,
|
|
73
181
|
maxBodyLength: Infinity,
|
|
74
182
|
});
|
|
183
|
+
|
|
75
184
|
this.runId = resp.data.uid;
|
|
76
185
|
this.runUrl = `${this.url}/${resp.data.url.split('/').splice(3).join('/')}`;
|
|
186
|
+
this.runPublicUrl = resp.data.public_url;
|
|
187
|
+
|
|
77
188
|
if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
|
|
189
|
+
|
|
78
190
|
this.store.runUrl = this.runUrl;
|
|
191
|
+
this.store.runPublicUrl = this.runPublicUrl;
|
|
79
192
|
this.store.runId = this.runId;
|
|
80
193
|
console.log(APP_PREFIX, '📊 Report created. Report ID:', this.runId);
|
|
81
194
|
process.env.runId = this.runId;
|
|
195
|
+
debug('Run created', this.runId);
|
|
82
196
|
} catch (err) {
|
|
83
197
|
console.error(
|
|
84
198
|
APP_PREFIX,
|
|
85
|
-
'Error creating Testomat.io report, please check if your API key is valid. Skipping report',
|
|
199
|
+
'Error creating Testomat.io report, please check if your API key is valid. Skipping report | ',
|
|
200
|
+
err?.response?.statusText || err?.status || err.message,
|
|
86
201
|
);
|
|
202
|
+
printCreateIssue(err);
|
|
87
203
|
}
|
|
204
|
+
debug('"createRun" function finished');
|
|
88
205
|
}
|
|
89
206
|
|
|
90
207
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @param testData
|
|
93
|
-
* @returns
|
|
208
|
+
* Decides whether to skip test reporting in case of too many request failures
|
|
209
|
+
* @param {TestData} testData
|
|
210
|
+
* @returns {boolean}
|
|
94
211
|
*/
|
|
212
|
+
#cancelTestReportingInCaseOfTooManyReqFailures(testData) {
|
|
213
|
+
if (this.reportingCanceledDueToReqFailures) return true;
|
|
214
|
+
|
|
215
|
+
const retriesCountWithinTime = this.retriesTimestamps.filter(
|
|
216
|
+
timestamp => Date.now() - timestamp < REPORTER_REQUEST_RETRIES.withinTimeSeconds * 1000,
|
|
217
|
+
).length;
|
|
218
|
+
debug(`${retriesCountWithinTime} failed requests within ${REPORTER_REQUEST_RETRIES.withinTimeSeconds}s`);
|
|
219
|
+
|
|
220
|
+
if (retriesCountWithinTime > REPORTER_REQUEST_RETRIES.maxTotalRetries) {
|
|
221
|
+
const errorMessage = chalk.yellow(
|
|
222
|
+
`${retriesCountWithinTime} requests were failed within ${REPORTER_REQUEST_RETRIES.withinTimeSeconds}s,\
|
|
223
|
+
reporting for test "${testData.title}" to Testomat is skipped`,
|
|
224
|
+
);
|
|
225
|
+
console.warn(`${APP_PREFIX} ${errorMessage}`);
|
|
226
|
+
|
|
227
|
+
this.reportingCanceledDueToReqFailures = true;
|
|
228
|
+
this.notReportedTestsCount++;
|
|
229
|
+
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
95
236
|
addTest(data) {
|
|
96
237
|
if (!this.isEnabled) return;
|
|
97
238
|
if (!this.runId) return;
|
|
239
|
+
if (this.#cancelTestReportingInCaseOfTooManyReqFailures(data)) return;
|
|
240
|
+
|
|
98
241
|
data.api_key = this.apiKey;
|
|
99
242
|
data.create = this.createNewTests;
|
|
243
|
+
|
|
244
|
+
if (!process.env.TESTOMATIO_STACK_PASSED && data.status === STATUS.PASSED) {
|
|
245
|
+
data.stack = null;
|
|
246
|
+
}
|
|
247
|
+
|
|
100
248
|
const json = JsonCycle.stringify(data);
|
|
101
249
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
250
|
+
debug('Adding test', json);
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
return this.axios
|
|
254
|
+
.post(`/api/reporter/${this.runId}/testrun`, json, {
|
|
255
|
+
maxContentLength: Infinity,
|
|
256
|
+
maxBodyLength: Infinity,
|
|
257
|
+
headers: {
|
|
258
|
+
// Overwrite Axios's automatically set Content-Type
|
|
259
|
+
'Content-Type': 'application/json',
|
|
260
|
+
},
|
|
261
|
+
})
|
|
262
|
+
.catch(err => {
|
|
263
|
+
if (err.response) {
|
|
264
|
+
if (err.response.status >= 400) {
|
|
265
|
+
const responseData = err.response.data || { message: '' };
|
|
266
|
+
console.log(
|
|
267
|
+
APP_PREFIX,
|
|
268
|
+
chalk.yellow(`Warning: ${responseData.message} (${err.response.status})`),
|
|
269
|
+
chalk.grey(data?.title || ''),
|
|
270
|
+
);
|
|
271
|
+
if (err.response?.data?.message?.includes('could not be matched')) {
|
|
272
|
+
this.hasUnmatchedTests = true;
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
114
276
|
console.log(
|
|
115
277
|
APP_PREFIX,
|
|
116
|
-
chalk.
|
|
117
|
-
`Report couldn't be processed:
|
|
278
|
+
chalk.yellow(`Warning: ${data?.title || ''} (${err.response?.status})`),
|
|
279
|
+
`Report couldn't be processed: ${err?.response?.data?.message}`,
|
|
118
280
|
);
|
|
119
|
-
|
|
281
|
+
printCreateIssue(err);
|
|
282
|
+
} else {
|
|
283
|
+
console.log(APP_PREFIX, chalk.blue(data?.title || ''), "Report couldn't be processed", err);
|
|
120
284
|
}
|
|
121
|
-
|
|
122
|
-
} else {
|
|
123
|
-
console.log(APP_PREFIX, chalk.blue(this.title), "Report couldn't be processed", err);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
285
|
+
});
|
|
126
286
|
}
|
|
127
287
|
|
|
128
288
|
/**
|
|
129
|
-
* @param {import('../../types').RunData} params
|
|
130
|
-
* @returns
|
|
289
|
+
* @param {import('../../types').RunData} params
|
|
290
|
+
* @returns
|
|
131
291
|
*/
|
|
132
292
|
async finishRun(params) {
|
|
133
293
|
if (!this.isEnabled) return;
|
|
294
|
+
debug('Finishing run...');
|
|
295
|
+
|
|
296
|
+
if (this.reportingCanceledDueToReqFailures) {
|
|
297
|
+
const errorMessage = chalk.red(
|
|
298
|
+
`⚠️ Due to request failures, ${this.notReportedTestsCount} test(s) were not reported to Testomat.io`,
|
|
299
|
+
);
|
|
300
|
+
console.warn(`${APP_PREFIX} ${errorMessage}`);
|
|
301
|
+
}
|
|
134
302
|
|
|
135
303
|
const { status, parallel } = params;
|
|
136
304
|
|
|
@@ -143,7 +311,7 @@ class TestomatioPipe {
|
|
|
143
311
|
|
|
144
312
|
try {
|
|
145
313
|
if (this.runId && !this.proceed) {
|
|
146
|
-
await this.axios.put(
|
|
314
|
+
await this.axios.put(`/api/reporter/${this.runId}`, {
|
|
147
315
|
api_key: this.apiKey,
|
|
148
316
|
status_event,
|
|
149
317
|
tests: params.tests,
|
|
@@ -151,15 +319,45 @@ class TestomatioPipe {
|
|
|
151
319
|
if (this.runUrl) {
|
|
152
320
|
console.log(APP_PREFIX, '📊 Report Saved. Report URL:', chalk.magenta(this.runUrl));
|
|
153
321
|
}
|
|
322
|
+
if (this.runPublicUrl) {
|
|
323
|
+
console.log(APP_PREFIX, '🌟 Public URL:', chalk.magenta(this.runPublicUrl));
|
|
324
|
+
}
|
|
154
325
|
}
|
|
155
326
|
if (this.runUrl && this.proceed) {
|
|
156
327
|
const notFinishedMessage = chalk.yellow.bold('Run was not finished because of $TESTOMATIO_PROCEED');
|
|
157
328
|
console.log(APP_PREFIX, `📊 ${notFinishedMessage}. Report URL: ${chalk.magenta(this.runUrl)}`);
|
|
158
329
|
console.log(APP_PREFIX, `🛬 Run to finish it: TESTOMATIO_RUN=${this.runId} npx start-test-run --finish`);
|
|
159
330
|
}
|
|
331
|
+
if (this.hasUnmatchedTests) {
|
|
332
|
+
console.log('');
|
|
333
|
+
// eslint-disable-next-line max-len
|
|
334
|
+
console.log(APP_PREFIX, chalk.yellow.bold('⚠️ Some reported tests were not found in Testomat.io project'));
|
|
335
|
+
// eslint-disable-next-line max-len
|
|
336
|
+
console.log(
|
|
337
|
+
APP_PREFIX,
|
|
338
|
+
`If you use Testomat.io as a reporter only, please re-run tests using ${chalk.bold('TESTOMATIO_CREATE=1')}`,
|
|
339
|
+
);
|
|
340
|
+
// eslint-disable-next-line max-len
|
|
341
|
+
console.log(
|
|
342
|
+
APP_PREFIX,
|
|
343
|
+
`But to keep your tests consistent it is recommended to ${chalk.bold('import tests first')}`,
|
|
344
|
+
);
|
|
345
|
+
console.log(APP_PREFIX, 'If tests were imported but still not matched, assign test IDs to your tests.');
|
|
346
|
+
console.log(APP_PREFIX, 'You can do that automatically via command line tools:');
|
|
347
|
+
console.log(APP_PREFIX, chalk.bold('npx check-tests ... --update-ids'), 'See: https://bit.ly/js-update-ids');
|
|
348
|
+
console.log(APP_PREFIX, 'or for Cucumber:');
|
|
349
|
+
// eslint-disable-next-line max-len
|
|
350
|
+
console.log(
|
|
351
|
+
APP_PREFIX,
|
|
352
|
+
chalk.bold('npx check-cucumber ... --update-ids'),
|
|
353
|
+
'See: https://bit.ly/bdd-update-ids',
|
|
354
|
+
);
|
|
355
|
+
}
|
|
160
356
|
} catch (err) {
|
|
161
357
|
console.log(APP_PREFIX, 'Error updating status, skipping...', err);
|
|
358
|
+
printCreateIssue(err);
|
|
162
359
|
}
|
|
360
|
+
debug('Run finished');
|
|
163
361
|
}
|
|
164
362
|
|
|
165
363
|
toString() {
|
|
@@ -167,19 +365,27 @@ class TestomatioPipe {
|
|
|
167
365
|
}
|
|
168
366
|
}
|
|
169
367
|
|
|
170
|
-
|
|
171
|
-
|
|
368
|
+
let registeredErrorHints = false;
|
|
369
|
+
function printCreateIssue(err) {
|
|
370
|
+
if (registeredErrorHints) return;
|
|
371
|
+
registeredErrorHints = true;
|
|
372
|
+
process.on('exit', () => {
|
|
373
|
+
console.log();
|
|
374
|
+
console.log(APP_PREFIX, 'There was an error reporting to Testomat.io:');
|
|
375
|
+
console.log(
|
|
376
|
+
APP_PREFIX,
|
|
377
|
+
'If you think this is a bug please create an issue: https://github.com/testomatio/reporter/issues/new',
|
|
378
|
+
); // eslint-disable-line max-len
|
|
379
|
+
console.log(APP_PREFIX, 'Provide this information:');
|
|
380
|
+
console.log('Error:', err.message || err.code);
|
|
381
|
+
if (!err.config) return;
|
|
172
382
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (artifacts.SECRET_ACCESS_KEY) process.env.S3_SECRET_ACCESS_KEY = artifacts.SECRET_ACCESS_KEY;
|
|
180
|
-
if (artifacts.REGION) process.env.S3_REGION = artifacts.REGION;
|
|
181
|
-
if (artifacts.BUCKET) process.env.S3_BUCKET = artifacts.BUCKET;
|
|
182
|
-
if (artifacts.ENDPOINT) process.env.S3_ENDPOINT = artifacts.ENDPOINT;
|
|
183
|
-
if (artifacts.presign) process.env.TESTOMATIO_PRIVATE_ARTIFACTS = '1';
|
|
184
|
-
resetConfig();
|
|
383
|
+
const time = new Date().toUTCString();
|
|
384
|
+
const { data, url, baseURL, method } = err?.config || {};
|
|
385
|
+
console.log('```js');
|
|
386
|
+
console.log({ data: data?.replace(/"(tstmt_[^"]+)"/g, 'tstmt_*'), url, baseURL, method, time });
|
|
387
|
+
console.log('```');
|
|
388
|
+
});
|
|
185
389
|
}
|
|
390
|
+
|
|
391
|
+
module.exports = TestomatioPipe;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { services } = require('./services');
|
|
2
|
+
const { initPlaywrightForStorage } = require('./adapter/playwright');
|
|
3
|
+
|
|
4
|
+
if (process.env.PLAYWRIGHT_TEST_BASE_URL) {
|
|
5
|
+
initPlaywrightForStorage();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stores path to file as artifact and uploads it to the S3 storage
|
|
10
|
+
* @param {string | {path: string, type: string, name: string}} data - path to file or object with path, type and name
|
|
11
|
+
*/
|
|
12
|
+
function saveArtifact(data, context = null) {
|
|
13
|
+
if (!data) return;
|
|
14
|
+
services.artifacts.put(data, context);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Attach log message(s) to the test report
|
|
19
|
+
* @param {...any} args
|
|
20
|
+
*/
|
|
21
|
+
function logMessage(...args) {
|
|
22
|
+
services.logger._templateLiteralLog(...args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Similar to "log" function but marks message in report as a step
|
|
27
|
+
* @param {*} message
|
|
28
|
+
*/
|
|
29
|
+
function addStep(message) {
|
|
30
|
+
services.logger.step(message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Add key-value pair(s) to the test report
|
|
35
|
+
* @param {*} keyValue
|
|
36
|
+
*/
|
|
37
|
+
function setKeyValue(keyValue) {
|
|
38
|
+
services.keyValues.put(keyValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
artifact: saveArtifact,
|
|
43
|
+
log: logMessage,
|
|
44
|
+
step: addStep,
|
|
45
|
+
keyValue: setKeyValue,
|
|
46
|
+
};
|
package/lib/reporter.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
const logger = require('./logger');
|
|
2
1
|
const TestomatClient = require('./client');
|
|
3
2
|
const TRConstants = require('./constants');
|
|
4
|
-
const
|
|
3
|
+
const { services } = require('./services');
|
|
5
4
|
|
|
6
|
-
const
|
|
7
|
-
const step = logger.step.bind(logger);
|
|
5
|
+
const reporterFunctions = require('./reporter-functions');
|
|
8
6
|
|
|
9
7
|
module.exports = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
// TODO: deprecate in future; use log or testomat.log
|
|
9
|
+
testomatioLogger: services.logger,
|
|
10
|
+
|
|
11
|
+
artifact: reporterFunctions.artifact,
|
|
12
|
+
log: reporterFunctions.log,
|
|
13
|
+
logger: services.logger,
|
|
14
|
+
meta: reporterFunctions.keyValue,
|
|
15
|
+
step: reporterFunctions.step,
|
|
16
|
+
|
|
13
17
|
TestomatClient,
|
|
14
18
|
TRConstants,
|
|
15
|
-
TRArtifacts,
|
|
16
|
-
addArtifact: TRArtifacts.artifact,
|
|
17
19
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const debug = require('debug')('@testomatio/reporter:services-artifacts');
|
|
2
|
+
const { dataStorage } = require('../data-storage');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Artifact storage is supposed to store file paths
|
|
6
|
+
*/
|
|
7
|
+
class ArtifactStorage {
|
|
8
|
+
static #instance;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Singleton
|
|
12
|
+
* @returns {ArtifactStorage}
|
|
13
|
+
*/
|
|
14
|
+
static getInstance() {
|
|
15
|
+
if (!this.#instance) {
|
|
16
|
+
this.#instance = new ArtifactStorage();
|
|
17
|
+
}
|
|
18
|
+
return this.#instance;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stores path to file as artifact and uploads it to the S3 storage
|
|
23
|
+
* @param {string | {path: string, type: string, name: string}} data - path to file or object with path, type and name
|
|
24
|
+
* @param {*} context testId or test title
|
|
25
|
+
*/
|
|
26
|
+
put(data, context = null) {
|
|
27
|
+
if (!data) return;
|
|
28
|
+
debug('Save artifact:', data);
|
|
29
|
+
dataStorage.putData('artifact', data, context);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns list of artifacts to upload
|
|
34
|
+
* @param {*} context testId or test context from test runner
|
|
35
|
+
* @returns {(string | {path: string, type: string, name: string})[]}
|
|
36
|
+
*/
|
|
37
|
+
get(context) {
|
|
38
|
+
let artifacts = dataStorage.getData('artifact', context);
|
|
39
|
+
if (!artifacts || !artifacts.length) return [];
|
|
40
|
+
|
|
41
|
+
artifacts = artifacts.map(artifactData => {
|
|
42
|
+
// artifact could be an object ({type, path, name} props) or string (just path)
|
|
43
|
+
let artifact;
|
|
44
|
+
try {
|
|
45
|
+
artifact = JSON.parse(artifactData);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
artifact = artifactData;
|
|
48
|
+
}
|
|
49
|
+
return artifact;
|
|
50
|
+
});
|
|
51
|
+
artifacts = artifacts.filter(artifact => !!artifact);
|
|
52
|
+
debug(`Artifacts for test ${context}:`, artifacts);
|
|
53
|
+
return artifacts.length ? artifacts : [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports.artifactStorage = ArtifactStorage.getInstance();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { logger } = require('./logger');
|
|
2
|
+
const { artifactStorage } = require('./artifacts');
|
|
3
|
+
const { keyValueStorage } = require('./key-values');
|
|
4
|
+
const { dataStorage } = require('../data-storage');
|
|
5
|
+
|
|
6
|
+
module.exports.services = {
|
|
7
|
+
logger,
|
|
8
|
+
artifacts: artifactStorage,
|
|
9
|
+
keyValues: keyValueStorage,
|
|
10
|
+
setContext: context => {
|
|
11
|
+
dataStorage.setContext(context);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const debug = require('debug')('@testomatio/reporter:services-key-value');
|
|
2
|
+
const { dataStorage } = require('../data-storage');
|
|
3
|
+
|
|
4
|
+
class KeyValueStorage {
|
|
5
|
+
static #instance;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @returns {KeyValueStorage}
|
|
10
|
+
*/
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!this.#instance) {
|
|
13
|
+
this.#instance = new KeyValueStorage();
|
|
14
|
+
}
|
|
15
|
+
return this.#instance;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Stores key-value pair and passes it to reporter
|
|
20
|
+
* @param {{key: string}} keyValue - key-value pair(s) as object
|
|
21
|
+
* @param {*} context - full test title
|
|
22
|
+
*/
|
|
23
|
+
put(keyValue, context = null) {
|
|
24
|
+
if (!keyValue) return;
|
|
25
|
+
dataStorage.putData('keyvalue', keyValue, context);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#isKeyValueObject(smth) {
|
|
29
|
+
return smth && typeof smth === 'object' && !Array.isArray(smth) && smth !== null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns key-values pairs for the test as object
|
|
34
|
+
* @param {*} context testId or test context from test runner
|
|
35
|
+
* @returns {{[key: string]: string} | {}} key-values pairs as object, e.g. {priority: 'high', browser: 'chrome'}
|
|
36
|
+
*/
|
|
37
|
+
get(context = null) {
|
|
38
|
+
const keyValuesList = dataStorage.getData('keyvalue', context);
|
|
39
|
+
if (!keyValuesList || !keyValuesList?.length) return {};
|
|
40
|
+
|
|
41
|
+
const keyValues = {};
|
|
42
|
+
for (const keyValue of keyValuesList) {
|
|
43
|
+
if (this.#isKeyValueObject(keyValue)) {
|
|
44
|
+
Object.assign(keyValues, keyValue);
|
|
45
|
+
} else if (typeof keyValue === 'string') {
|
|
46
|
+
try {
|
|
47
|
+
Object.assign(keyValues, JSON.parse(keyValue));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
debug(`Error parsing key-values for test ${context}`, keyValue);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return keyValues;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports.keyValueStorage = KeyValueStorage.getInstance();
|