testomatio-reporter-cli 2.14.0 → 2.15.0-beta.1-json-output
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/package.json +1 -1
- package/src/bin/cli.js +17 -6
- package/src/utils/pipe_utils.js +22 -0
package/package.json
CHANGED
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 } from '../utils/pipe_utils.js';
|
|
19
|
+
import { formatFilterListIds, formatRunOutput } from '../utils/pipe_utils.js';
|
|
20
20
|
import fs from 'fs';
|
|
21
21
|
import path from 'path';
|
|
22
22
|
|
|
@@ -53,7 +53,7 @@ program
|
|
|
53
53
|
.description('Start a new run and return its ID')
|
|
54
54
|
.option('--kind <type>', 'Specify run type: automated, manual, mixed, or detect')
|
|
55
55
|
.option('--filter <filter>', 'Scope the prepared run to tests matching the filter (no execution)')
|
|
56
|
-
.option('--format <format>', 'Machine-readable output:
|
|
56
|
+
.option('--format <format>', 'Machine-readable output: the run id (--format id) or run details (--format json)')
|
|
57
57
|
.option('--warn', 'Exit 0 instead of 1 when the filter matches no tests (warn only)')
|
|
58
58
|
.action(async opts => {
|
|
59
59
|
cleanLatestRunId();
|
|
@@ -93,8 +93,8 @@ program
|
|
|
93
93
|
const plannedTests = (client.pipeStore.preparedTestIds || []).map(id => ({ test_id: id, title: id }));
|
|
94
94
|
await client.updateRunStatus('pending', { tests: plannedTests });
|
|
95
95
|
|
|
96
|
-
// stdout carries ONLY the run
|
|
97
|
-
console.log(runId);
|
|
96
|
+
// stdout carries ONLY the run data so it can be captured: RUN_ID=$(reporter start)
|
|
97
|
+
console.log(formatRunOutput({ ...client.pipeStore, runId }, opts.format));
|
|
98
98
|
process.exit(0);
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -129,7 +129,10 @@ program
|
|
|
129
129
|
.argument('[command]', 'Test runner command')
|
|
130
130
|
.option('--filter <filter>', 'Additional execution filter')
|
|
131
131
|
.option('--filter-list <filter>', 'Get a list of all tests by filter before running')
|
|
132
|
-
.option(
|
|
132
|
+
.option(
|
|
133
|
+
'--format <format>',
|
|
134
|
+
'Machine-readable output: test ids for --filter-list (grep, json, newline, ids), or the run created (id, json)',
|
|
135
|
+
)
|
|
133
136
|
.option('--kind <type>', 'Specify run type: automated, manual, mixed, or detect')
|
|
134
137
|
.option('--remote <profile>', 'Trigger run on the named Testomat.io CI profile instead of executing locally')
|
|
135
138
|
.option(
|
|
@@ -230,6 +233,8 @@ program
|
|
|
230
233
|
|
|
231
234
|
log.info(`🚀 CI build triggered on profile ${pc.cyan(opts.remote)}`);
|
|
232
235
|
log.info(`📊 Report URL: ${pc.magenta(client.pipeStore.runUrl)}`);
|
|
236
|
+
const remoteOutput = formatRunOutput(client.pipeStore, opts.format);
|
|
237
|
+
if (opts.format && remoteOutput) console.log(remoteOutput);
|
|
233
238
|
return process.exit(0);
|
|
234
239
|
}
|
|
235
240
|
|
|
@@ -252,6 +257,8 @@ program
|
|
|
252
257
|
log.info( `No command passed, so you need to run tests yourself:`);
|
|
253
258
|
log.info( `TESTOMATIO_RUN=${runId} <command>`);
|
|
254
259
|
}
|
|
260
|
+
const runOutput = formatRunOutput({ ...client.pipeStore, runId }, opts.format);
|
|
261
|
+
if (opts.format && runOutput) console.log(runOutput);
|
|
255
262
|
} else {
|
|
256
263
|
log.info( '⚠️ No API key provided. Cannot create run without TESTOMATIO key.');
|
|
257
264
|
process.exit(1);
|
|
@@ -288,7 +295,11 @@ program
|
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
if (apiKey) {
|
|
291
|
-
await client.createRun(createRunParams)
|
|
298
|
+
await client.createRun(createRunParams);
|
|
299
|
+
// the runner inherits stdout, so the run data is printed first, on its own line
|
|
300
|
+
const createdOutput = formatRunOutput(client.pipeStore, opts.format);
|
|
301
|
+
if (opts.format && createdOutput) console.log(createdOutput);
|
|
302
|
+
await runTests();
|
|
292
303
|
} else {
|
|
293
304
|
await runTests();
|
|
294
305
|
}
|
package/src/utils/pipe_utils.js
CHANGED
|
@@ -304,6 +304,27 @@ function plannedTestsLabel(tests, testsCount) {
|
|
|
304
304
|
return `**${knownTestsCount}** tests and **${suitesCount}** suites planned`;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Format the created run for machine-readable output of `start` and `run`.
|
|
309
|
+
* `json` prints an object with the run details, any other format prints the bare run id.
|
|
310
|
+
*
|
|
311
|
+
* @param {{runId?: string, runUrl?: string, runPublicUrl?: string}} store - Pipe store of the client.
|
|
312
|
+
* @param {string} [format] - Value of the CLI `--format` option.
|
|
313
|
+
* @returns {string} Empty string if there is no run id.
|
|
314
|
+
*/
|
|
315
|
+
function formatRunOutput(store, format) {
|
|
316
|
+
const runId = store?.runId;
|
|
317
|
+
if (!runId) return '';
|
|
318
|
+
|
|
319
|
+
if (format !== 'json') return runId;
|
|
320
|
+
|
|
321
|
+
const output = { runId };
|
|
322
|
+
if (store.runUrl) output.runUrl = store.runUrl;
|
|
323
|
+
if (store.runPublicUrl) output.runPublicUrl = store.runPublicUrl;
|
|
324
|
+
|
|
325
|
+
return JSON.stringify(output);
|
|
326
|
+
}
|
|
327
|
+
|
|
307
328
|
export {
|
|
308
329
|
updateFilterType,
|
|
309
330
|
parseFilterParams,
|
|
@@ -317,6 +338,7 @@ export {
|
|
|
317
338
|
plannedTestsLabel,
|
|
318
339
|
parsePipeOptions,
|
|
319
340
|
formatFilterListIds,
|
|
341
|
+
formatRunOutput,
|
|
320
342
|
getObjectSize,
|
|
321
343
|
splitTestsIntoChunks,
|
|
322
344
|
};
|