@testomatio/reporter 2.0.1-beta.5-timestamp → 2.0.1-beta.7
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 +1 -0
- package/lib/adapter/codecept.d.ts +2 -0
- package/lib/adapter/codecept.js +297 -335
- package/lib/adapter/cucumber/current.d.ts +14 -0
- package/lib/adapter/cucumber/current.js +195 -203
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber/legacy.js +130 -155
- package/lib/adapter/cucumber.d.ts +2 -0
- package/lib/adapter/cucumber.js +5 -16
- package/lib/adapter/cypress-plugin/index.d.ts +2 -0
- package/lib/adapter/cypress-plugin/index.js +91 -105
- package/lib/adapter/jasmine.d.ts +11 -0
- package/lib/adapter/jasmine.js +54 -53
- package/lib/adapter/jest.d.ts +13 -0
- package/lib/adapter/jest.js +97 -99
- package/lib/adapter/mocha.d.ts +2 -0
- package/lib/adapter/mocha.js +112 -141
- package/lib/adapter/nightwatch.d.ts +4 -0
- package/lib/adapter/nightwatch.js +80 -0
- package/lib/adapter/playwright.d.ts +14 -0
- package/lib/adapter/playwright.js +208 -231
- package/lib/adapter/vitest.d.ts +35 -0
- package/lib/adapter/vitest.js +150 -149
- package/lib/adapter/webdriver.d.ts +24 -0
- package/lib/adapter/webdriver.js +144 -121
- package/lib/bin/cli.d.ts +2 -0
- package/lib/bin/cli.js +229 -211
- package/lib/bin/reportXml.d.ts +2 -0
- package/lib/bin/reportXml.js +51 -52
- package/lib/bin/startTest.d.ts +2 -0
- package/lib/bin/startTest.js +83 -95
- package/lib/bin/uploadArtifacts.d.ts +2 -0
- package/lib/bin/uploadArtifacts.js +56 -61
- package/lib/client.d.ts +76 -0
- package/lib/client.js +431 -465
- package/lib/config.d.ts +1 -0
- package/lib/config.js +18 -23
- package/lib/constants.d.ts +25 -0
- package/lib/constants.js +50 -44
- package/lib/data-storage.d.ts +34 -0
- package/lib/data-storage.js +216 -188
- package/lib/junit-adapter/adapter.d.ts +9 -0
- package/lib/junit-adapter/adapter.js +17 -20
- package/lib/junit-adapter/csharp.d.ts +5 -0
- package/lib/junit-adapter/csharp.js +28 -14
- package/lib/junit-adapter/index.d.ts +3 -0
- package/lib/junit-adapter/index.js +27 -25
- package/lib/junit-adapter/java.d.ts +5 -0
- package/lib/junit-adapter/java.js +41 -53
- package/lib/junit-adapter/javascript.d.ts +4 -0
- package/lib/junit-adapter/javascript.js +30 -27
- package/lib/junit-adapter/python.d.ts +5 -0
- package/lib/junit-adapter/python.js +38 -37
- package/lib/junit-adapter/ruby.d.ts +4 -0
- package/lib/junit-adapter/ruby.js +11 -8
- package/lib/output.d.ts +11 -0
- package/lib/output.js +44 -52
- package/lib/package.json +3 -0
- package/lib/pipe/bitbucket.d.ts +25 -0
- package/lib/pipe/bitbucket.js +223 -230
- package/lib/pipe/csv.d.ts +47 -0
- package/lib/pipe/csv.js +113 -126
- package/lib/pipe/debug.d.ts +29 -0
- package/lib/pipe/debug.js +125 -99
- package/lib/pipe/github.d.ts +30 -0
- package/lib/pipe/github.js +218 -213
- package/lib/pipe/gitlab.d.ts +25 -0
- package/lib/pipe/gitlab.js +183 -206
- package/lib/pipe/html.d.ts +35 -0
- package/lib/pipe/html.js +258 -321
- package/lib/pipe/index.d.ts +1 -0
- package/lib/pipe/index.js +94 -66
- package/lib/pipe/testomatio.d.ts +71 -0
- package/lib/pipe/testomatio.js +429 -474
- package/lib/replay.d.ts +31 -0
- package/lib/replay.js +255 -0
- package/lib/reporter-functions.d.ts +41 -0
- package/lib/reporter-functions.js +64 -26
- package/lib/reporter.d.ts +235 -0
- package/lib/reporter.js +37 -29
- package/lib/services/artifacts.d.ts +33 -0
- package/lib/services/artifacts.js +55 -51
- package/lib/services/index.d.ts +11 -0
- package/lib/services/index.js +16 -12
- package/lib/services/key-values.d.ts +27 -0
- package/lib/services/key-values.js +56 -53
- package/lib/services/labels.d.ts +22 -0
- package/lib/services/labels.js +62 -0
- package/lib/services/logger.d.ts +64 -0
- package/lib/services/logger.js +226 -245
- package/lib/template/testomatio.hbs +1026 -1366
- package/lib/uploader.d.ts +60 -0
- package/lib/uploader.js +295 -364
- package/lib/utils/pipe_utils.d.ts +41 -0
- package/lib/utils/pipe_utils.js +89 -85
- package/lib/utils/utils.d.ts +54 -0
- package/lib/utils/utils.js +398 -307
- package/lib/xmlReader.d.ts +92 -0
- package/lib/xmlReader.js +525 -532
- package/package.json +64 -21
- package/src/adapter/codecept.js +377 -0
- package/src/adapter/cucumber/current.js +228 -0
- package/src/adapter/cucumber/legacy.js +158 -0
- package/src/adapter/cucumber.js +4 -0
- package/src/adapter/cypress-plugin/index.js +110 -0
- package/src/adapter/jasmine.js +60 -0
- package/src/adapter/jest.js +107 -0
- package/src/adapter/mocha.cjs +2 -0
- package/src/adapter/mocha.js +156 -0
- package/src/adapter/nightwatch.js +88 -0
- package/src/adapter/playwright.js +258 -0
- package/src/adapter/vitest.js +183 -0
- package/src/adapter/webdriver.js +142 -0
- package/src/bin/cli.js +348 -0
- package/src/bin/reportXml.js +77 -0
- package/src/bin/startTest.js +124 -0
- package/src/bin/uploadArtifacts.js +91 -0
- package/src/client.js +519 -0
- package/src/config.js +30 -0
- package/src/constants.js +53 -0
- package/src/data-storage.js +204 -0
- package/src/junit-adapter/adapter.js +23 -0
- package/src/junit-adapter/csharp.js +28 -0
- package/src/junit-adapter/index.js +28 -0
- package/src/junit-adapter/java.js +58 -0
- package/src/junit-adapter/javascript.js +31 -0
- package/src/junit-adapter/python.js +42 -0
- package/src/junit-adapter/ruby.js +10 -0
- package/src/output.js +57 -0
- package/src/pipe/bitbucket.js +252 -0
- package/src/pipe/csv.js +140 -0
- package/src/pipe/debug.js +125 -0
- package/src/pipe/github.js +232 -0
- package/src/pipe/gitlab.js +247 -0
- package/src/pipe/html.js +373 -0
- package/src/pipe/index.js +71 -0
- package/src/pipe/testomatio.js +504 -0
- package/src/replay.js +262 -0
- package/src/reporter-functions.js +96 -0
- package/src/reporter.cjs_decprecated +21 -0
- package/src/reporter.js +36 -0
- package/src/services/artifacts.js +59 -0
- package/src/services/index.js +15 -0
- package/src/services/key-values.js +59 -0
- package/src/services/labels.js +59 -0
- package/src/services/logger.js +315 -0
- package/src/template/emptyData.svg +23 -0
- package/src/template/testomatio.hbs +1081 -0
- package/src/uploader.js +376 -0
- package/src/utils/pipe_utils.js +119 -0
- package/src/utils/utils.js +416 -0
- package/src/xmlReader.js +614 -0
package/src/uploader.js
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import createDebugMessages from 'debug';
|
|
2
|
+
import { S3 } from '@aws-sdk/client-s3';
|
|
3
|
+
import { Upload } from '@aws-sdk/lib-storage';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import promiseRetry from 'promise-retry';
|
|
8
|
+
import pc from 'picocolors';
|
|
9
|
+
import { APP_PREFIX } from './constants.js';
|
|
10
|
+
import { filesize as prettyBytes } from 'filesize';
|
|
11
|
+
|
|
12
|
+
const debug = createDebugMessages('@testomatio/reporter:file-uploader');
|
|
13
|
+
|
|
14
|
+
export class S3Uploader {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.isEnabled = undefined;
|
|
17
|
+
this.storeEnabled = true;
|
|
18
|
+
this.config = undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @type {{path: string, size: number}[]}
|
|
22
|
+
*/
|
|
23
|
+
this.skippedUploads = [];
|
|
24
|
+
this.failedUploads = [];
|
|
25
|
+
/**
|
|
26
|
+
* @type {{path: string, size: number, link: string}[]}
|
|
27
|
+
*/
|
|
28
|
+
this.successfulUploads = [];
|
|
29
|
+
|
|
30
|
+
this.configKeys = [
|
|
31
|
+
'S3_ENDPOINT',
|
|
32
|
+
'S3_REGION',
|
|
33
|
+
'S3_BUCKET',
|
|
34
|
+
'S3_ACCESS_KEY_ID',
|
|
35
|
+
'S3_SECRET_ACCESS_KEY',
|
|
36
|
+
'S3_SESSION_TOKEN',
|
|
37
|
+
'S3_FORCE_PATH_STYLE',
|
|
38
|
+
'TESTOMATIO_DISABLE_ARTIFACTS',
|
|
39
|
+
'TESTOMATIO_PRIVATE_ARTIFACTS',
|
|
40
|
+
'TESTOMATIO_ARTIFACT_MAX_SIZE_MB',
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
resetConfig() {
|
|
45
|
+
this.config = undefined;
|
|
46
|
+
this.isEnabled = undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @returns {Record<string, string>}
|
|
52
|
+
*/
|
|
53
|
+
getConfig() {
|
|
54
|
+
if (this.config) return this.config;
|
|
55
|
+
this.config = this.configKeys.reduce((acc, key) => {
|
|
56
|
+
acc[key] = process.env[key];
|
|
57
|
+
return acc;
|
|
58
|
+
}, {});
|
|
59
|
+
return this.config;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getMaskedConfig() {
|
|
63
|
+
return Object.fromEntries(
|
|
64
|
+
Object.entries(this.getConfig()).map(([key, value]) => [
|
|
65
|
+
key,
|
|
66
|
+
key === 'S3_SECRET_ACCESS_KEY' || key === 'S3_ACCESS_KEY_ID' ? '***' : value,
|
|
67
|
+
]),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
checkEnabled() {
|
|
72
|
+
if (this.isEnabled !== undefined) return this.isEnabled;
|
|
73
|
+
|
|
74
|
+
const { S3_BUCKET, TESTOMATIO_DISABLE_ARTIFACTS } = this.getConfig();
|
|
75
|
+
if (!S3_BUCKET) debug(`Artifacts uploading is disabled because S3_BUCKET is not set`);
|
|
76
|
+
this.isEnabled = !!(S3_BUCKET && !TESTOMATIO_DISABLE_ARTIFACTS);
|
|
77
|
+
|
|
78
|
+
if (this.isEnabled) debug('S3 uploader is enabled');
|
|
79
|
+
debug(this.getMaskedConfig());
|
|
80
|
+
|
|
81
|
+
return this.isEnabled;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
enableLogStorage() {
|
|
85
|
+
this.storeEnabled = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
disableLogStorage() {
|
|
89
|
+
this.storeEnabled = false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @param {*} Body
|
|
95
|
+
* @param {*} Key
|
|
96
|
+
* @param {{path: string, size?: number}} file
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
async #uploadToS3(Body, Key, file) {
|
|
100
|
+
const { S3_BUCKET, TESTOMATIO_PRIVATE_ARTIFACTS } = this.getConfig();
|
|
101
|
+
const ACL = TESTOMATIO_PRIVATE_ARTIFACTS ? 'private' : 'public-read';
|
|
102
|
+
|
|
103
|
+
if (!S3_BUCKET || !Body) {
|
|
104
|
+
console.log(
|
|
105
|
+
APP_PREFIX,
|
|
106
|
+
pc.bold(pc.red(`Failed uploading '${Key}'. Please check S3 credentials`)),
|
|
107
|
+
this.getMaskedConfig(),
|
|
108
|
+
);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
debug('Uploading to S3:', Key);
|
|
113
|
+
|
|
114
|
+
const s3Config = this.#getS3Config();
|
|
115
|
+
const s3 = new S3(s3Config);
|
|
116
|
+
const params = {
|
|
117
|
+
Bucket: S3_BUCKET,
|
|
118
|
+
Key,
|
|
119
|
+
Body,
|
|
120
|
+
};
|
|
121
|
+
// disable ACL for I AM roles
|
|
122
|
+
if (!s3Config.credentials.sessionToken) {
|
|
123
|
+
params.ACL = ACL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const upload = new Upload({ client: s3, params });
|
|
128
|
+
|
|
129
|
+
const link = await this.getS3LocationLink(upload);
|
|
130
|
+
this.successfulUploads.push({ path: file.path, size: file.size, link });
|
|
131
|
+
debug(`📤 Uploaded artifact. File: ${file.path}, size: ${prettyBytes(file.size || 0)}, link: ${link}`);
|
|
132
|
+
return link;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
this.failedUploads.push({ path: file.path, size: file.size });
|
|
135
|
+
debug('S3 uploading error:', e);
|
|
136
|
+
console.log(APP_PREFIX, 'Upload failed:', e.message, '\nConfig:\n', this.getMaskedConfig());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns an array of uploaded files
|
|
142
|
+
*
|
|
143
|
+
* @returns {{rid: string, file: string, uploaded: boolean}[]}
|
|
144
|
+
*/
|
|
145
|
+
readUploadedFiles(runId) {
|
|
146
|
+
const tempFilePath = this.#getFilePathWithUploadsList(runId);
|
|
147
|
+
|
|
148
|
+
debug('Reading file', tempFilePath);
|
|
149
|
+
|
|
150
|
+
if (!fs.existsSync(tempFilePath)) {
|
|
151
|
+
debug('File not found:', tempFilePath);
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const stats = fs.statSync(tempFilePath);
|
|
156
|
+
debug('Artifacts file stats:', +stats.mtime);
|
|
157
|
+
debug('Current time:', +new Date());
|
|
158
|
+
const diff = +new Date() - +stats.mtime;
|
|
159
|
+
debug('Diff:', diff);
|
|
160
|
+
const diffHours = diff / 1000 / 60 / 60;
|
|
161
|
+
debug('Diff hours:', diffHours);
|
|
162
|
+
if (diffHours > 3) {
|
|
163
|
+
console.log(APP_PREFIX, "Artifacts file is too old, can't process artifacts. Please re-run the tests.");
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const data = fs.readFileSync(tempFilePath, 'utf8');
|
|
168
|
+
debug('Artifacts file contents:', data);
|
|
169
|
+
const lines = data.split('\n').filter(Boolean);
|
|
170
|
+
return lines.map(line => JSON.parse(line));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#getFilePathWithUploadsList(runId) {
|
|
174
|
+
const tempFilePath = path.join(os.tmpdir(), `testomatio.run.${runId}.json`);
|
|
175
|
+
if (!fs.existsSync(tempFilePath)) {
|
|
176
|
+
debug('Creating artifacts file:', tempFilePath);
|
|
177
|
+
fs.writeFileSync(tempFilePath, '');
|
|
178
|
+
}
|
|
179
|
+
return tempFilePath;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
storeUploadedFile(filePath, runId, rid, uploaded = false) {
|
|
183
|
+
if (!this.storeEnabled) return;
|
|
184
|
+
|
|
185
|
+
if (!filePath || !runId || !rid) return;
|
|
186
|
+
|
|
187
|
+
const tempFilePath = this.#getFilePathWithUploadsList(runId);
|
|
188
|
+
|
|
189
|
+
if (typeof filePath === 'object') {
|
|
190
|
+
filePath = filePath.path;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (typeof filePath === 'string' && !path.isAbsolute(filePath)) {
|
|
194
|
+
filePath = path.join(process.cwd(), filePath);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const data = { rid, file: filePath, uploaded };
|
|
198
|
+
const jsonLine = `${JSON.stringify(data)}\n`;
|
|
199
|
+
fs.appendFileSync(tempFilePath, jsonLine);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {*} filePath
|
|
204
|
+
* @param {*} pathInS3 contains runId, rid and filename
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
async uploadFileByPath(filePath, pathInS3) {
|
|
208
|
+
/* WDIO: some artifacts uploading started before createRun function completion
|
|
209
|
+
probably, the reason is that run is NOT created in adapter (but via cli) */
|
|
210
|
+
this.isEnabled = this.isEnabled ?? this.checkEnabled();
|
|
211
|
+
|
|
212
|
+
const [runId, rid] = pathInS3;
|
|
213
|
+
|
|
214
|
+
if (!filePath) return;
|
|
215
|
+
|
|
216
|
+
let fileSize = null;
|
|
217
|
+
let fileSizeInMb = null;
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
// file may not exist
|
|
221
|
+
fileSize = fs.statSync(filePath).size || 0;
|
|
222
|
+
fileSizeInMb = Number((fileSize / (1024 * 1024)).toFixed(2));
|
|
223
|
+
} catch (e) {
|
|
224
|
+
debug(`File ${filePath} does not exist`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!this.isEnabled) {
|
|
228
|
+
this.storeUploadedFile(filePath, runId, rid, false);
|
|
229
|
+
this.skippedUploads.push({ path: filePath, size: fileSize });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const { S3_BUCKET, TESTOMATIO_ARTIFACT_MAX_SIZE_MB } = this.getConfig();
|
|
234
|
+
|
|
235
|
+
debug('Started upload', filePath, 'to', S3_BUCKET);
|
|
236
|
+
|
|
237
|
+
const isFileExist = await this.checkArtifactExistsInFileSystem(filePath, 20, 500);
|
|
238
|
+
|
|
239
|
+
if (!isFileExist) {
|
|
240
|
+
console.error(pc.yellow(`Artifacts file ${filePath} does not exist. Skipping...`));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// skipping artifact only if: 1. storing to file is enabled, 2. max size is set and 3. file size exceeds the limit
|
|
245
|
+
if (
|
|
246
|
+
this.storeEnabled &&
|
|
247
|
+
TESTOMATIO_ARTIFACT_MAX_SIZE_MB &&
|
|
248
|
+
fileSizeInMb > parseFloat(TESTOMATIO_ARTIFACT_MAX_SIZE_MB)
|
|
249
|
+
) {
|
|
250
|
+
const skippedArtifact = { path: filePath, size: fileSize };
|
|
251
|
+
this.storeUploadedFile(filePath, runId, rid, false);
|
|
252
|
+
this.skippedUploads.push(skippedArtifact);
|
|
253
|
+
debug(pc.yellow(`Artifacts file ${JSON.stringify(skippedArtifact)} exceeds the maximum allowed size. Skipping.`));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
debug('File:', filePath, 'exists, size:', prettyBytes(fileSize));
|
|
257
|
+
|
|
258
|
+
const fileStream = fs.createReadStream(filePath);
|
|
259
|
+
const Key = pathInS3.filter(p => !!p).join('/');
|
|
260
|
+
|
|
261
|
+
const link = await this.#uploadToS3(fileStream, Key, { path: filePath, size: fileSize });
|
|
262
|
+
|
|
263
|
+
this.storeUploadedFile(filePath, runId, rid, !!link);
|
|
264
|
+
|
|
265
|
+
return link;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @param {Buffer} buffer
|
|
270
|
+
* @param {string[]} pathInS3
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
async uploadFileAsBuffer(buffer, pathInS3) {
|
|
274
|
+
/* WDIO: some artifacts uploading started before createRun function completion
|
|
275
|
+
probably, the reason is that run is NOT created in adapter (but via cli) */
|
|
276
|
+
|
|
277
|
+
this.isEnabled = this.isEnabled ?? this.checkEnabled();
|
|
278
|
+
if (!this.isEnabled) return;
|
|
279
|
+
|
|
280
|
+
let Key = pathInS3.filter(p => !!p).join('/');
|
|
281
|
+
const ext = this.#getFileExtBase64(buffer.toString('base64'));
|
|
282
|
+
|
|
283
|
+
if (ext) {
|
|
284
|
+
Key = `${Key}.${ext}`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this.#uploadToS3(buffer, Key, { path: Key });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async checkArtifactExistsInFileSystem(filePath, attempts = 5, intervalMs = 500) {
|
|
291
|
+
return promiseRetry(
|
|
292
|
+
async (retry, number) => {
|
|
293
|
+
try {
|
|
294
|
+
fs.accessSync(filePath);
|
|
295
|
+
return true;
|
|
296
|
+
} catch (err) {
|
|
297
|
+
if (number === attempts) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
debug(`File not found, retrying (attempt ${number}/${attempts})`);
|
|
301
|
+
await new Promise(resolve => {
|
|
302
|
+
setTimeout(resolve, intervalMs);
|
|
303
|
+
});
|
|
304
|
+
retry(err);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
retries: attempts,
|
|
309
|
+
minTimeout: intervalMs,
|
|
310
|
+
maxTimeout: intervalMs,
|
|
311
|
+
},
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async getS3LocationLink(out) {
|
|
316
|
+
const response = await out.done();
|
|
317
|
+
|
|
318
|
+
let s3Location = response?.Location?.trim();
|
|
319
|
+
|
|
320
|
+
if (!s3Location) {
|
|
321
|
+
s3Location = out?.singleUploadResult?.Location;
|
|
322
|
+
debug('Uploaded singleUploadResult.Location', s3Location);
|
|
323
|
+
|
|
324
|
+
if (!s3Location) {
|
|
325
|
+
throw new Error("Problems getting the S3 artifact's link. Please check S3 permissions!");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Normalize the URL
|
|
330
|
+
if (!s3Location.startsWith('http')) {
|
|
331
|
+
s3Location = `https://${s3Location}`;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return s3Location;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
#getFileExtBase64(str) {
|
|
338
|
+
const type = str.charAt(0);
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
{
|
|
342
|
+
'/': 'jpg',
|
|
343
|
+
i: 'png',
|
|
344
|
+
R: 'gif',
|
|
345
|
+
U: 'webp',
|
|
346
|
+
}[type] || ''
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#getS3Config() {
|
|
351
|
+
const { S3_REGION, S3_SESSION_TOKEN, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_FORCE_PATH_STYLE, S3_ENDPOINT } =
|
|
352
|
+
this.getConfig();
|
|
353
|
+
|
|
354
|
+
const cfg = {
|
|
355
|
+
region: S3_REGION,
|
|
356
|
+
credentials: {
|
|
357
|
+
accessKeyId: S3_ACCESS_KEY_ID,
|
|
358
|
+
secretAccessKey: S3_SECRET_ACCESS_KEY,
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
if (S3_FORCE_PATH_STYLE) {
|
|
363
|
+
cfg.forcePathStyle = !['false', '0'].includes(String(S3_FORCE_PATH_STYLE || '').toLowerCase());
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (S3_SESSION_TOKEN) {
|
|
367
|
+
cfg.credentials.sessionToken = S3_SESSION_TOKEN;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (S3_ENDPOINT) {
|
|
371
|
+
cfg.endpoint = S3_ENDPOINT;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return cfg;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { APP_PREFIX } from '../constants.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Set S3 credentials from the provided artifacts object.
|
|
5
|
+
* @param {Object} artifacts - The artifacts object containing S3 credentials.
|
|
6
|
+
*/
|
|
7
|
+
function setS3Credentials(artifacts) {
|
|
8
|
+
if (!Object.keys(artifacts).length) return;
|
|
9
|
+
|
|
10
|
+
console.log(APP_PREFIX, 'S3 credentials obtained from Testomat.io...');
|
|
11
|
+
|
|
12
|
+
if (artifacts.ACCESS_KEY_ID) process.env.S3_ACCESS_KEY_ID = artifacts.ACCESS_KEY_ID;
|
|
13
|
+
if (artifacts.SECRET_ACCESS_KEY) process.env.S3_SECRET_ACCESS_KEY = artifacts.SECRET_ACCESS_KEY;
|
|
14
|
+
if (artifacts.REGION) process.env.S3_REGION = artifacts.REGION;
|
|
15
|
+
if (artifacts.BUCKET) process.env.S3_BUCKET = artifacts.BUCKET;
|
|
16
|
+
if (artifacts.SESSION_TOKEN) process.env.S3_SESSION_TOKEN = artifacts.SESSION_TOKEN;
|
|
17
|
+
if (artifacts.presign) process.env.TESTOMATIO_PRIVATE_ARTIFACTS = '1';
|
|
18
|
+
// endpoint is not received from the server; and shuld be empty if IAM used (credentails obtained from the testomat)
|
|
19
|
+
process.env.S3_ENDPOINT = artifacts.ENDPOINT || '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Generates mode request parameters based on the input params.
|
|
24
|
+
* @param {{type: string, id?: string, apiKey: string}} params - The input parameters for the request.
|
|
25
|
+
* @returns {Object|null} - An object containing the generated request parameters, or null if the type is invalid.
|
|
26
|
+
*/
|
|
27
|
+
function generateFilterRequestParams(params) {
|
|
28
|
+
const { type, id, apiKey } = params;
|
|
29
|
+
|
|
30
|
+
if (!type) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!id) {
|
|
35
|
+
console.error(APP_PREFIX, `Please make sure your settings "${type.toUpperCase()}"= "${id}" is correct!`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
params: {
|
|
41
|
+
type,
|
|
42
|
+
id: encodeURIComponent(id),
|
|
43
|
+
api_key: apiKey,
|
|
44
|
+
},
|
|
45
|
+
responseType: 'json',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Parse filter parameters from a string in the format "type=id".
|
|
51
|
+
* @param {string} opts - The input string containing the filter parameters.
|
|
52
|
+
* @returns {Object} An object containing the parsed filter parameters.
|
|
53
|
+
* The object has properties "type" and "id".
|
|
54
|
+
*/
|
|
55
|
+
function parseFilterParams(opts) {
|
|
56
|
+
const [type, id] = opts.split('=');
|
|
57
|
+
const validType = updateFilterType(type);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
type: validType,
|
|
61
|
+
id,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Update and validate the filter type.
|
|
67
|
+
* @param {string} type - The original filter type.
|
|
68
|
+
* @returns {string|undefined} The updated and validated filter type.
|
|
69
|
+
* Returns undefined if the type is not valid.
|
|
70
|
+
*/
|
|
71
|
+
function updateFilterType(type) {
|
|
72
|
+
const typeLowerCase = type.toLowerCase();
|
|
73
|
+
|
|
74
|
+
const filterTypes = ['tag-name', 'plan-id', 'label', 'jira-ticket'];
|
|
75
|
+
|
|
76
|
+
const filterApi = [
|
|
77
|
+
'tag',
|
|
78
|
+
'plan',
|
|
79
|
+
'label',
|
|
80
|
+
'jira',
|
|
81
|
+
// "ims-issue", //TODO: WIP
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
if (!filterTypes.includes(typeLowerCase)) {
|
|
85
|
+
console.log(APP_PREFIX, `❗❗❗ Invalid "filter=${type}" start settings! Available option list: ${filterTypes}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const index = filterTypes.indexOf(typeLowerCase);
|
|
90
|
+
|
|
91
|
+
return index !== -1 ? filterApi[index] : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Return an emoji based on the provided status.
|
|
96
|
+
* @param {string} status - The status value ('passed', 'failed', or 'skipped').
|
|
97
|
+
* @returns {string} - An emoji corresponding to the provided status.
|
|
98
|
+
*/
|
|
99
|
+
function statusEmoji(status) {
|
|
100
|
+
if (status === 'passed') return '🟢';
|
|
101
|
+
if (status === 'failed') return '🔴';
|
|
102
|
+
if (status === 'skipped') return '🟡';
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Generate a full name string based on the provided test object.
|
|
108
|
+
* @param {object} t - The test object.
|
|
109
|
+
* @returns {string} - A formatted full name string for the test object.
|
|
110
|
+
*/
|
|
111
|
+
function fullName(t) {
|
|
112
|
+
let line = '';
|
|
113
|
+
if (t.suite_title) line = `${t.suite_title}: `;
|
|
114
|
+
line += `**${t.title}**`;
|
|
115
|
+
if (t.example) line += ` \`[${Object.values(t.example)}]\``;
|
|
116
|
+
return line;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { updateFilterType, parseFilterParams, generateFilterRequestParams, setS3Credentials, statusEmoji, fullName };
|