@testomatio/reporter 2.19.0 → 2.20.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/lib/adapter/codecept.js +1 -0
- package/lib/adapter/cucumber/current.js +1 -0
- package/lib/adapter/cypress-plugin/index.js +1 -0
- package/lib/adapter/e2e.d.ts +49 -0
- package/lib/adapter/e2e.js +250 -0
- package/lib/adapter/jasmine.js +1 -0
- package/lib/adapter/jest.js +1 -0
- package/lib/adapter/mocha.d.ts +4 -1
- package/lib/adapter/mocha.js +123 -122
- package/lib/adapter/nightwatch.js +1 -0
- package/lib/adapter/playwright.js +1 -0
- package/lib/adapter/vitest.js +1 -0
- package/lib/adapter/webdriver.js +1 -0
- package/lib/allureReader.d.ts +4 -1
- package/lib/allureReader.js +2 -1
- package/lib/bin/cli.js +32 -13
- package/lib/client.d.ts +1 -0
- package/lib/client.js +12 -3
- package/lib/data-storage.js +4 -3
- package/lib/pipe/testomatio.js +17 -1
- package/lib/replay.js +1 -0
- package/lib/uploader.d.ts +1 -0
- package/lib/uploader.js +21 -1
- package/lib/utils/pipe_utils.d.ts +16 -3
- package/lib/utils/pipe_utils.js +45 -4
- package/lib/xmlReader.js +2 -0
- package/package.json +7 -2
- package/src/adapter/codecept.js +2 -0
- package/src/adapter/cucumber/current.js +2 -0
- package/src/adapter/cypress-plugin/index.js +2 -0
- package/src/adapter/e2e.js +245 -0
- package/src/adapter/jasmine.js +2 -0
- package/src/adapter/jest.js +2 -0
- package/src/adapter/mocha.js +146 -145
- package/src/adapter/nightwatch.js +2 -0
- package/src/adapter/playwright.js +2 -0
- package/src/adapter/vitest.js +2 -0
- package/src/adapter/webdriver.js +2 -0
- package/src/allureReader.js +2 -1
- package/src/bin/cli.js +30 -11
- package/src/client.js +11 -3
- package/src/data-storage.js +4 -3
- package/src/pipe/testomatio.js +27 -1
- package/src/replay.js +1 -0
- package/src/uploader.js +30 -1
- package/src/utils/pipe_utils.js +45 -4
- package/src/xmlReader.js +3 -0
- package/types/types.d.ts +1 -0
package/src/bin/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ import { filesize as prettyBytes } from 'filesize';
|
|
|
16
16
|
import dotenv from 'dotenv';
|
|
17
17
|
import Replay from '../replay.js';
|
|
18
18
|
import { log } from '../utils/log.js';
|
|
19
|
-
import { formatFilterListIds, formatRunOutput, formatFetchRunsOutput } from '../utils/pipe_utils.js';
|
|
19
|
+
import { formatFilterListIds, formatRunOutput, formatFetchRunsOutput, parseRunsUrl } from '../utils/pipe_utils.js';
|
|
20
20
|
import fs from 'fs';
|
|
21
21
|
import path from 'path';
|
|
22
22
|
|
|
@@ -130,7 +130,9 @@ program
|
|
|
130
130
|
program
|
|
131
131
|
.command('fetch')
|
|
132
132
|
.description('Fetch runs from Testomat.io API v2')
|
|
133
|
+
.argument('[url]', 'URL of a run or of a (filtered) runs page in Testomat.io')
|
|
133
134
|
.option('--project <slug>', 'Project slug (or set TESTOMATIO_PROJECT)')
|
|
135
|
+
.option('--run <id>', 'Fetch a single run by its id')
|
|
134
136
|
.option('--title <text>', 'Filter by run title')
|
|
135
137
|
.option('--tql <query>', 'Filter using Testomat Query Language')
|
|
136
138
|
.option('--rungroup <uid>', 'Filter by rungroup id')
|
|
@@ -144,27 +146,44 @@ program
|
|
|
144
146
|
'--format <format>',
|
|
145
147
|
'Machine-readable output: run ids, one per line (--format id) or run details (--format json)',
|
|
146
148
|
)
|
|
147
|
-
.action(async opts => {
|
|
149
|
+
.action(async (pageUrl, opts) => {
|
|
148
150
|
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
|
|
149
151
|
if (!apiKey) {
|
|
150
152
|
log.error(pc.red('⚠️ TESTOMATIO API key required'));
|
|
151
153
|
process.exit(1);
|
|
152
154
|
}
|
|
153
155
|
|
|
154
|
-
|
|
156
|
+
let page = {};
|
|
157
|
+
if (pageUrl) {
|
|
158
|
+
page = parseRunsUrl(pageUrl);
|
|
159
|
+
if (!page) {
|
|
160
|
+
log.error(pc.red(`⚠️ Not a Testomat.io run or runs page URL: ${pageUrl}`));
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const project = opts.project || page.project || process.env.TESTOMATIO_PROJECT;
|
|
155
166
|
if (!project) {
|
|
156
167
|
log.error(pc.red('⚠️ --project (or TESTOMATIO_PROJECT) is required'));
|
|
157
168
|
process.exit(1);
|
|
158
169
|
}
|
|
159
170
|
|
|
160
|
-
const baseUrl = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
const baseUrl = page.baseUrl || process.env.TESTOMATIO_URL || 'https://app.testomat.io';
|
|
172
|
+
const runId = opts.run || page.runId;
|
|
173
|
+
let url;
|
|
174
|
+
|
|
175
|
+
if (runId) {
|
|
176
|
+
url = new URL(`/api/v2/${project}/runs/${runId}`, baseUrl);
|
|
177
|
+
} else {
|
|
178
|
+
url = new URL(`/api/v2/${project}/runs`, baseUrl);
|
|
179
|
+
for (const [key, value] of page.params || []) url.searchParams.append(key, value);
|
|
180
|
+
if (opts.title) url.searchParams.set('search', opts.title);
|
|
181
|
+
if (opts.tql) url.searchParams.set('tql', opts.tql);
|
|
182
|
+
if (opts.rungroup) url.searchParams.set('groupId', opts.rungroup);
|
|
183
|
+
const requestedLimit = opts.latest ? 1 : parseInt(opts.limit, 10) || FETCH_RUNS_DEFAULT_LIMIT;
|
|
184
|
+
const limit = Math.min(Math.max(requestedLimit, 1), FETCH_RUNS_MAX_LIMIT);
|
|
185
|
+
url.searchParams.set('per_page', String(limit));
|
|
186
|
+
}
|
|
168
187
|
|
|
169
188
|
const response = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` } });
|
|
170
189
|
const body = await response.json();
|
package/src/client.js
CHANGED
|
@@ -36,6 +36,8 @@ class Client {
|
|
|
36
36
|
this.pipeStore = {};
|
|
37
37
|
this.runId = '';
|
|
38
38
|
this.queue = Promise.resolve();
|
|
39
|
+
// adapter name is set by the adapter module itself on load (global.TESTOMATIO_ADAPTER)
|
|
40
|
+
this.adapterName = params.adapter || global.TESTOMATIO_ADAPTER;
|
|
39
41
|
|
|
40
42
|
// @ts-ignore this line will be removed in compiled code, because __dirname is defined in commonjs
|
|
41
43
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -244,7 +246,9 @@ class Client {
|
|
|
244
246
|
overwrite,
|
|
245
247
|
tags,
|
|
246
248
|
} = testData;
|
|
247
|
-
let { files = [], manuallyAttachedArtifacts, message = ''
|
|
249
|
+
let { files = [], manuallyAttachedArtifacts, message = '' } = testData;
|
|
250
|
+
/** @type {Record<string, any>} */
|
|
251
|
+
let meta = testData.meta || {};
|
|
248
252
|
|
|
249
253
|
if (stepArtifactPaths.size) {
|
|
250
254
|
const isStepArtifact = item => stepArtifactPaths.has(typeof item === 'object' ? item?.path : item);
|
|
@@ -261,6 +265,10 @@ class Client {
|
|
|
261
265
|
return acc;
|
|
262
266
|
}, {});
|
|
263
267
|
|
|
268
|
+
// meta must always include reporter version and adapter used
|
|
269
|
+
if (this.version) meta.reporterVersion = this.version;
|
|
270
|
+
if (this.adapterName) meta.adapter = this.adapterName;
|
|
271
|
+
|
|
264
272
|
const testContext = suite_title ? `${suite_title} ${title}` : title;
|
|
265
273
|
|
|
266
274
|
let errorFormatted = '';
|
|
@@ -389,8 +397,8 @@ class Client {
|
|
|
389
397
|
this.queue = this.queue
|
|
390
398
|
.then(() => Promise.all(this.pipes.map(p => p.finishRun(runParams))))
|
|
391
399
|
.then(() => {
|
|
392
|
-
|
|
393
|
-
|
|
400
|
+
// no early return when uploading is disabled:
|
|
401
|
+
// skipped artifacts (e.g. no S3 credentials obtained) must still be reported to the user
|
|
394
402
|
const filesizeStrMaxLength = 7;
|
|
395
403
|
|
|
396
404
|
if (this.uploader.successfulUploads.length) {
|
package/src/data-storage.js
CHANGED
|
@@ -190,9 +190,10 @@ class DataStorage {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
function stringToMD5Hash(str) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
// sha256 instead of md5 for FIPS-enabled hosts compatibility
|
|
194
|
+
const sha256 = crypto.createHash('sha256');
|
|
195
|
+
sha256.update(str);
|
|
196
|
+
const hash = sha256.digest('hex');
|
|
196
197
|
return `${process.env.runId || 'run'}_${hash}`;
|
|
197
198
|
}
|
|
198
199
|
|
package/src/pipe/testomatio.js
CHANGED
|
@@ -352,6 +352,8 @@ class TestomatioPipe {
|
|
|
352
352
|
if (resp.data.artifacts) {
|
|
353
353
|
setS3Credentials(resp.data.artifacts);
|
|
354
354
|
this.#startS3CredentialsRefresh(runParams);
|
|
355
|
+
} else {
|
|
356
|
+
this.#warnNoS3Credentials();
|
|
355
357
|
}
|
|
356
358
|
if (resp.data.url) {
|
|
357
359
|
const respUrl = new URL(resp.data.url);
|
|
@@ -383,6 +385,8 @@ class TestomatioPipe {
|
|
|
383
385
|
if (resp.data.artifacts) {
|
|
384
386
|
setS3Credentials(resp.data.artifacts);
|
|
385
387
|
this.#startS3CredentialsRefresh(runParams);
|
|
388
|
+
} else {
|
|
389
|
+
this.#warnNoS3Credentials();
|
|
386
390
|
}
|
|
387
391
|
|
|
388
392
|
this.store.runUrl = this.runUrl;
|
|
@@ -442,10 +446,32 @@ class TestomatioPipe {
|
|
|
442
446
|
debug('S3 credentials refreshed');
|
|
443
447
|
}
|
|
444
448
|
} catch (err) {
|
|
445
|
-
|
|
449
|
+
log.warn(
|
|
450
|
+
'⚠️ Failed to refresh S3 credentials:',
|
|
451
|
+
err.message || err,
|
|
452
|
+
'\nArtifact uploads may fail once the current credentials expire.',
|
|
453
|
+
);
|
|
446
454
|
}
|
|
447
455
|
};
|
|
448
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Warns the user when Testomat.io did not return S3 credentials for artifacts upload.
|
|
459
|
+
* Skipped when artifacts uploading was intentionally disabled or a custom S3 storage is configured via env.
|
|
460
|
+
*/
|
|
461
|
+
#warnNoS3Credentials() {
|
|
462
|
+
if (process.env.TESTOMATIO_DISABLE_ARTIFACTS || process.env.S3_BUCKET) return;
|
|
463
|
+
|
|
464
|
+
const command = `TESTOMATIO=<your_api_key> TESTOMATIO_RUN=${
|
|
465
|
+
this.runId || '<run_id>'
|
|
466
|
+
} npx @testomatio/reporter upload-artifacts`;
|
|
467
|
+
log.warn(
|
|
468
|
+
`⚠️ ${pc.yellow('Testomat.io did not return S3 credentials for artifacts upload.')}`,
|
|
469
|
+
'Artifacts will not be uploaded.',
|
|
470
|
+
'Please check the artifact sharing settings of your project.',
|
|
471
|
+
`\nRun "${pc.magenta(command)}" later with valid S3 credentials to re-upload artifacts to this run.`,
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
449
475
|
#stopS3CredentialsRefresh() {
|
|
450
476
|
if (this.s3CredentialsRefreshTimer) {
|
|
451
477
|
clearInterval(this.s3CredentialsRefreshTimer);
|
package/src/replay.js
CHANGED
package/src/uploader.js
CHANGED
|
@@ -23,6 +23,7 @@ export class S3Uploader {
|
|
|
23
23
|
*/
|
|
24
24
|
this.skippedUploads = [];
|
|
25
25
|
this.failedUploads = [];
|
|
26
|
+
this.warnedDisabledUpload = false;
|
|
26
27
|
/**
|
|
27
28
|
* @type {{path: string, size: number, link: string}[]}
|
|
28
29
|
*/
|
|
@@ -90,6 +91,30 @@ export class S3Uploader {
|
|
|
90
91
|
this.storeEnabled = false;
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Warns once when artifact uploading is disabled not intentionally by the user,
|
|
96
|
+
* e.g. S3 credentials were not obtained from Testomat.io and no custom S3 storage is configured.
|
|
97
|
+
* Without this warning artifacts are skipped silently.
|
|
98
|
+
*/
|
|
99
|
+
#warnDisabledUpload(runId) {
|
|
100
|
+
if (this.warnedDisabledUpload) return;
|
|
101
|
+
|
|
102
|
+
const { S3_BUCKET, TESTOMATIO_DISABLE_ARTIFACTS } = this.getConfig();
|
|
103
|
+
// uploading was intentionally disabled by the user or a custom S3 storage is used, nothing to warn about
|
|
104
|
+
if (TESTOMATIO_DISABLE_ARTIFACTS || S3_BUCKET) return;
|
|
105
|
+
|
|
106
|
+
this.warnedDisabledUpload = true;
|
|
107
|
+
const command = `TESTOMATIO=<your_api_key> TESTOMATIO_RUN=${
|
|
108
|
+
runId || '<run_id>'
|
|
109
|
+
} npx @testomatio/reporter upload-artifacts`;
|
|
110
|
+
log.warn(
|
|
111
|
+
`🗄️ ${pc.yellow('Artifacts uploading is disabled: S3 credentials were not obtained from Testomat.io')}`,
|
|
112
|
+
pc.yellow('(and no custom S3 storage is configured).'),
|
|
113
|
+
'Artifacts will not be uploaded.',
|
|
114
|
+
`\nRun "${pc.magenta(command)}" later with valid S3 credentials to re-upload artifacts to this run.`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
93
118
|
/**
|
|
94
119
|
*
|
|
95
120
|
* @param {*} Body
|
|
@@ -231,6 +256,7 @@ export class S3Uploader {
|
|
|
231
256
|
}
|
|
232
257
|
|
|
233
258
|
if (!this.isEnabled) {
|
|
259
|
+
this.#warnDisabledUpload(runId);
|
|
234
260
|
this.storeUploadedFile(filePath, runId, rid, false);
|
|
235
261
|
this.skippedUploads.push({ path: filePath, size: fileSize });
|
|
236
262
|
return;
|
|
@@ -281,7 +307,10 @@ export class S3Uploader {
|
|
|
281
307
|
probably, the reason is that run is NOT created in adapter (but via cli) */
|
|
282
308
|
|
|
283
309
|
this.isEnabled = this.isEnabled ?? this.checkEnabled();
|
|
284
|
-
if (!this.isEnabled)
|
|
310
|
+
if (!this.isEnabled) {
|
|
311
|
+
this.#warnDisabledUpload(pathInS3[0]);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
285
314
|
|
|
286
315
|
let Key = pathInS3.filter(p => !!p).join('/');
|
|
287
316
|
const ext = this.#getFileExtBase64(buffer.toString('base64'));
|
package/src/utils/pipe_utils.js
CHANGED
|
@@ -366,17 +366,18 @@ function formatRunOutput(store, format) {
|
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
368
|
* Format the runs fetched via the `fetch` command for machine-readable output.
|
|
369
|
-
* `json` prints the full array of run objects; `id` prints one run id per line;
|
|
369
|
+
* `json` prints the full array of run objects (a single object for one run); `id` prints one run id per line;
|
|
370
370
|
* any other format prints a human-readable multi-line summary per run.
|
|
371
371
|
*
|
|
372
|
-
* @param {{data?: Array}} body - Parsed response body from GET /api/v2/:project/runs.
|
|
372
|
+
* @param {{data?: Array|Object}} body - Parsed response body from GET /api/v2/:project/runs[/:id].
|
|
373
373
|
* @param {string} [format] - Value of the CLI `--format` option.
|
|
374
374
|
* @returns {string}
|
|
375
375
|
*/
|
|
376
376
|
function formatFetchRunsOutput(body, format) {
|
|
377
|
-
const
|
|
377
|
+
const data = body?.data || [];
|
|
378
|
+
const runs = [data].flat();
|
|
378
379
|
|
|
379
|
-
if (format === 'json') return JSON.stringify(
|
|
380
|
+
if (format === 'json') return JSON.stringify(data, null, 2);
|
|
380
381
|
|
|
381
382
|
if (format === 'id') return runs.map(run => run.id).filter(Boolean).join('\n');
|
|
382
383
|
|
|
@@ -384,6 +385,7 @@ function formatFetchRunsOutput(body, format) {
|
|
|
384
385
|
.map(run => {
|
|
385
386
|
const lines = [`* ID: ${run.id}`];
|
|
386
387
|
if (run.title) lines.push(` title: ${run.title}`);
|
|
388
|
+
if (run.rungroup_id) lines.push(` rungroup: ${run.rungroup_id}`);
|
|
387
389
|
if (run.launched_at) lines.push(` started at: ${run.launched_at}`);
|
|
388
390
|
if (run.finished_at) lines.push(` finished at: ${run.finished_at}`);
|
|
389
391
|
if (run.passed_count != null) lines.push(` passed: ${run.passed_count} tests`);
|
|
@@ -397,6 +399,44 @@ function formatFetchRunsOutput(body, format) {
|
|
|
397
399
|
.join('\n');
|
|
398
400
|
}
|
|
399
401
|
|
|
402
|
+
// filterParam keys of the runs page which are API params on their own; the rest go under filter[...]
|
|
403
|
+
const RUNS_PAGE_PARAMS = ['search', 'tql', 'groupId'];
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Parse a Testomat.io app URL of a run (/projects/:project/runs/:id)
|
|
407
|
+
* or of a runs page (/projects/:project/runs?filterParam=...) into API v2 request parts.
|
|
408
|
+
*
|
|
409
|
+
* @param {string} pageUrl
|
|
410
|
+
* @returns {{baseUrl: string, project: string, runId?: string, params: string[][]}|null}
|
|
411
|
+
*/
|
|
412
|
+
function parseRunsUrl(pageUrl) {
|
|
413
|
+
let url;
|
|
414
|
+
try {
|
|
415
|
+
url = new URL(pageUrl);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const match = url.pathname.match(/\/projects\/([^/]+)\/runs(?:\/([^/]+))?\/?$/);
|
|
421
|
+
if (!match) return null;
|
|
422
|
+
|
|
423
|
+
const [, project, runId] = match;
|
|
424
|
+
const params = [];
|
|
425
|
+
|
|
426
|
+
for (const [key, value] of new URLSearchParams(url.searchParams.get('filterParam') || '')) {
|
|
427
|
+
// "groups" only switches the page to the grouped view
|
|
428
|
+
if (!value || key === 'groups') continue;
|
|
429
|
+
if (RUNS_PAGE_PARAMS.includes(key)) {
|
|
430
|
+
params.push([key, value]);
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const [name, ...nested] = key.split('[');
|
|
434
|
+
params.push([`filter[${name}]${nested.map(part => `[${part}`).join('')}`, value]);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return { baseUrl: url.origin, project, runId, params };
|
|
438
|
+
}
|
|
439
|
+
|
|
400
440
|
export {
|
|
401
441
|
updateFilterType,
|
|
402
442
|
parseFilterParams,
|
|
@@ -413,6 +453,7 @@ export {
|
|
|
413
453
|
formatFilterListIds,
|
|
414
454
|
formatRunOutput,
|
|
415
455
|
formatFetchRunsOutput,
|
|
456
|
+
parseRunsUrl,
|
|
416
457
|
getObjectSize,
|
|
417
458
|
splitTestsIntoChunks,
|
|
418
459
|
};
|
package/src/xmlReader.js
CHANGED