@testomatio/reporter 2.0.0-beta-esm → 2.0.1-beta-esm
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.d.ts +2 -0
- package/lib/adapter/codecept.js +31 -24
- package/lib/adapter/cucumber/current.d.ts +14 -0
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber.d.ts +2 -0
- package/lib/adapter/cypress-plugin/index.d.ts +2 -0
- package/lib/adapter/cypress-plugin/index.js +11 -9
- package/lib/adapter/jasmine.d.ts +11 -0
- package/lib/adapter/jest.d.ts +13 -0
- package/lib/adapter/mocha.d.ts +2 -0
- package/lib/adapter/mocha.js +4 -3
- package/lib/adapter/playwright.d.ts +14 -0
- package/lib/adapter/playwright.js +58 -33
- package/lib/adapter/vitest.d.ts +35 -0
- package/lib/adapter/vitest.js +6 -6
- package/lib/adapter/webdriver.d.ts +24 -0
- package/lib/adapter/webdriver.js +34 -6
- package/lib/bin/cli.d.ts +2 -0
- package/lib/bin/cli.js +228 -0
- package/lib/bin/reportXml.d.ts +2 -0
- package/lib/bin/reportXml.js +11 -9
- package/lib/bin/startTest.d.ts +2 -0
- package/lib/bin/startTest.js +9 -5
- package/lib/bin/uploadArtifacts.d.ts +2 -0
- package/lib/bin/uploadArtifacts.js +81 -0
- package/lib/client.d.ts +76 -0
- package/lib/client.js +111 -45
- package/lib/config.d.ts +1 -0
- package/lib/constants.d.ts +25 -0
- package/lib/constants.js +5 -1
- package/lib/data-storage.d.ts +34 -0
- package/lib/data-storage.js +2 -2
- package/lib/junit-adapter/adapter.d.ts +9 -0
- package/lib/junit-adapter/csharp.d.ts +4 -0
- package/lib/junit-adapter/index.d.ts +3 -0
- package/lib/junit-adapter/java.d.ts +5 -0
- package/lib/junit-adapter/javascript.d.ts +4 -0
- package/lib/junit-adapter/python.d.ts +5 -0
- package/lib/junit-adapter/ruby.d.ts +4 -0
- package/lib/output.d.ts +11 -0
- package/lib/package.json +3 -1
- package/lib/pipe/bitbucket.d.ts +23 -0
- package/lib/pipe/bitbucket.js +2 -2
- package/lib/pipe/csv.d.ts +47 -0
- package/lib/pipe/csv.js +2 -2
- package/lib/pipe/debug.d.ts +29 -0
- package/lib/pipe/debug.js +108 -0
- package/lib/pipe/github.d.ts +30 -0
- package/lib/pipe/github.js +2 -2
- package/lib/pipe/gitlab.d.ts +23 -0
- package/lib/pipe/gitlab.js +2 -2
- package/lib/pipe/html.d.ts +34 -0
- package/lib/pipe/html.js +8 -1
- package/lib/pipe/index.d.ts +1 -0
- package/lib/pipe/index.js +3 -3
- package/lib/pipe/testomatio.d.ts +70 -0
- package/lib/pipe/testomatio.js +50 -30
- package/lib/reporter-functions.d.ts +34 -0
- package/lib/reporter-functions.js +17 -7
- package/lib/reporter.d.ts +232 -0
- package/lib/reporter.js +19 -33
- package/lib/services/artifacts.d.ts +33 -0
- package/lib/services/index.d.ts +9 -0
- package/lib/services/key-values.d.ts +27 -0
- package/lib/services/key-values.js +1 -1
- package/lib/services/logger.d.ts +64 -0
- package/lib/template/testomatio.hbs +651 -1366
- package/lib/uploader.d.ts +60 -0
- package/lib/uploader.js +312 -0
- package/lib/utils/pipe_utils.d.ts +41 -0
- package/lib/utils/pipe_utils.js +3 -5
- package/lib/utils/utils.d.ts +45 -0
- package/lib/utils/utils.js +69 -2
- package/lib/xmlReader.d.ts +92 -0
- package/lib/xmlReader.js +22 -12
- package/package.json +15 -9
- package/src/adapter/codecept.js +30 -24
- package/src/adapter/cypress-plugin/index.js +5 -3
- package/src/adapter/mocha.cjs +1 -1
- package/src/adapter/mocha.js +4 -3
- package/src/adapter/playwright.js +59 -31
- package/src/adapter/vitest.js +6 -6
- package/src/adapter/webdriver.js +41 -10
- package/src/bin/cli.js +280 -0
- package/src/bin/reportXml.js +15 -8
- package/src/bin/startTest.js +7 -3
- package/src/bin/uploadArtifacts.js +90 -0
- package/src/client.js +137 -56
- package/src/constants.js +5 -1
- package/src/data-storage.js +2 -2
- package/src/pipe/bitbucket.js +2 -2
- package/src/pipe/csv.js +3 -3
- package/src/pipe/debug.js +104 -0
- package/src/pipe/github.js +2 -3
- package/src/pipe/gitlab.js +6 -6
- package/src/pipe/html.js +11 -3
- package/src/pipe/index.js +5 -7
- package/src/pipe/testomatio.js +72 -67
- package/src/reporter-functions.js +18 -7
- package/src/reporter.cjs_decprecated +21 -0
- package/src/reporter.js +20 -11
- package/src/services/key-values.js +1 -1
- package/src/services/logger.js +4 -2
- package/src/template/testomatio.hbs +651 -1366
- package/src/uploader.js +371 -0
- package/src/utils/pipe_utils.js +4 -12
- package/src/utils/utils.js +48 -6
- package/src/xmlReader.js +26 -15
- package/lib/adapter/jasmine/jasmine.js +0 -63
- package/lib/adapter/mocha/mocha.js +0 -125
- package/lib/fileUploader.js +0 -245
- package/lib/utils/chalk.js +0 -10
- package/src/fileUploader.js +0 -307
- package/src/reporter.cjs +0 -22
- package/src/utils/chalk.js +0 -13
package/lib/bin/cli.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const cross_spawn_1 = require("cross-spawn");
|
|
9
|
+
const glob_1 = __importDefault(require("glob"));
|
|
10
|
+
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const client_js_1 = __importDefault(require("../client.js"));
|
|
12
|
+
const xmlReader_js_1 = __importDefault(require("../xmlReader.js"));
|
|
13
|
+
const constants_js_1 = require("../constants.js");
|
|
14
|
+
const package_json_1 = require("../../package.json");
|
|
15
|
+
const config_js_1 = require("../config.js");
|
|
16
|
+
const utils_js_1 = require("../utils/utils.js");
|
|
17
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
18
|
+
const filesize_1 = require("filesize");
|
|
19
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
20
|
+
const debug = (0, debug_1.default)('@testomatio/reporter:xml-cli');
|
|
21
|
+
console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io Reporter v${package_json_1.version}`)));
|
|
22
|
+
const program = new commander_1.Command();
|
|
23
|
+
program
|
|
24
|
+
.version(package_json_1.version)
|
|
25
|
+
.option('--env-file <envfile>', 'Load environment variables from env file')
|
|
26
|
+
.hook('preAction', thisCommand => {
|
|
27
|
+
const opts = thisCommand.opts();
|
|
28
|
+
if (opts.envFile) {
|
|
29
|
+
dotenv_1.default.config({ path: opts.envFile });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
dotenv_1.default.config();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
program
|
|
36
|
+
.command('start')
|
|
37
|
+
.description('Start a new run and return its ID')
|
|
38
|
+
.action(async () => {
|
|
39
|
+
console.log('Starting a new Run on Testomat.io...');
|
|
40
|
+
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config_js_1.config.TESTOMATIO;
|
|
41
|
+
const client = new client_js_1.default({ apiKey });
|
|
42
|
+
client.createRun().then(() => {
|
|
43
|
+
console.log(process.env.runId);
|
|
44
|
+
process.exit(0);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
program
|
|
48
|
+
.command('finish')
|
|
49
|
+
.description('Finish Run by its ID')
|
|
50
|
+
.action(async () => {
|
|
51
|
+
process.env.TESTOMATIO_RUN ||= (0, utils_js_1.readLatestRunId)();
|
|
52
|
+
if (!process.env.TESTOMATIO_RUN) {
|
|
53
|
+
console.log('TESTOMATIO_RUN environment variable must be set or restored from a previous run.');
|
|
54
|
+
return process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
console.log('Finishing Run on Testomat.io...');
|
|
57
|
+
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config_js_1.config.TESTOMATIO;
|
|
58
|
+
const client = new client_js_1.default({ apiKey });
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
client.updateRunStatus(constants_js_1.STATUS.FINISHED).then(() => {
|
|
61
|
+
console.log(picocolors_1.default.yellow(`Run ${process.env.TESTOMATIO_RUN} was finished`));
|
|
62
|
+
process.exit(0);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command('run')
|
|
67
|
+
.description('Run tests with the specified command')
|
|
68
|
+
.argument('<command>', 'Test runner command')
|
|
69
|
+
.option('--filter <filter>', 'Additional execution filter')
|
|
70
|
+
.action(async (command, opts) => {
|
|
71
|
+
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config_js_1.config.TESTOMATIO;
|
|
72
|
+
const title = process.env.TESTOMATIO_TITLE;
|
|
73
|
+
if (!command || !command.split) {
|
|
74
|
+
console.log(constants_js_1.APP_PREFIX, `No command provided. Use -c option to launch a test runner.`);
|
|
75
|
+
return process.exit(255);
|
|
76
|
+
}
|
|
77
|
+
const client = new client_js_1.default({ apiKey, title, parallel: true });
|
|
78
|
+
if (opts.filter) {
|
|
79
|
+
const [pipe, ...optsArray] = opts.filter.split(':');
|
|
80
|
+
const pipeOptions = optsArray.join(':');
|
|
81
|
+
try {
|
|
82
|
+
const tests = await client.prepareRun({ pipe, pipeOptions });
|
|
83
|
+
if (tests && tests.length > 0) {
|
|
84
|
+
command += ` --grep (${tests.join('|')})`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.log(constants_js_1.APP_PREFIX, err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
console.log(constants_js_1.APP_PREFIX, `🚀 Running`, picocolors_1.default.green(command));
|
|
92
|
+
const runTests = () => {
|
|
93
|
+
const testCmds = command.split(' ');
|
|
94
|
+
const cmd = (0, cross_spawn_1.spawn)(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
|
|
95
|
+
cmd.on('close', code => {
|
|
96
|
+
const emoji = code === 0 ? '🟢' : '🔴';
|
|
97
|
+
console.log(constants_js_1.APP_PREFIX, emoji, `Runner exited with ${picocolors_1.default.bold(code)}`);
|
|
98
|
+
if (apiKey) {
|
|
99
|
+
const status = code === 0 ? 'passed' : 'failed';
|
|
100
|
+
client.updateRunStatus(status, true);
|
|
101
|
+
}
|
|
102
|
+
process.exit(code);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
if (apiKey) {
|
|
106
|
+
client.createRun().then(runTests);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
runTests();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
program
|
|
113
|
+
.command('xml')
|
|
114
|
+
.description('Parse XML reports and upload to Testomat.io')
|
|
115
|
+
.argument('<pattern>', 'XML file pattern')
|
|
116
|
+
.option('-d, --dir <dir>', 'Project directory')
|
|
117
|
+
.option('--java-tests [java-path]', 'Load Java tests from path, by default: src/test/java')
|
|
118
|
+
.option('--lang <lang>', 'Language used (python, ruby, java)')
|
|
119
|
+
.option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
|
|
120
|
+
.action(async (pattern, opts) => {
|
|
121
|
+
if (!pattern.endsWith('.xml')) {
|
|
122
|
+
pattern += '.xml';
|
|
123
|
+
}
|
|
124
|
+
let { javaTests, lang } = opts;
|
|
125
|
+
if (javaTests === true)
|
|
126
|
+
javaTests = 'src/test/java';
|
|
127
|
+
lang = lang?.toLowerCase();
|
|
128
|
+
const runReader = new xmlReader_js_1.default({ javaTests, lang });
|
|
129
|
+
const files = glob_1.default.sync(pattern, { cwd: opts.dir || process.cwd() });
|
|
130
|
+
if (!files.length) {
|
|
131
|
+
console.log(constants_js_1.APP_PREFIX, `Report can't be created. No XML files found 😥`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
for (const file of files) {
|
|
135
|
+
console.log(constants_js_1.APP_PREFIX, `Parsed ${file}`);
|
|
136
|
+
runReader.parse(file);
|
|
137
|
+
}
|
|
138
|
+
let timeoutTimer;
|
|
139
|
+
if (opts.timelimit) {
|
|
140
|
+
timeoutTimer = setTimeout(() => {
|
|
141
|
+
console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
|
|
142
|
+
process.exit(0);
|
|
143
|
+
}, parseInt(opts.timelimit, 10) * 1000);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await runReader.createRun();
|
|
147
|
+
await runReader.uploadData();
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
console.log(constants_js_1.APP_PREFIX, 'Error updating status, skipping...', err);
|
|
151
|
+
}
|
|
152
|
+
if (timeoutTimer)
|
|
153
|
+
clearTimeout(timeoutTimer);
|
|
154
|
+
});
|
|
155
|
+
program
|
|
156
|
+
.command('upload-artifacts')
|
|
157
|
+
.description('Upload artifacts to Testomat.io')
|
|
158
|
+
.option('--force', 'Re-upload artifacts even if they were uploaded before')
|
|
159
|
+
.action(async (opts) => {
|
|
160
|
+
const apiKey = config_js_1.config.TESTOMATIO;
|
|
161
|
+
process.env.TESTOMATIO_DISABLE_ARTIFACTS = '';
|
|
162
|
+
const runId = process.env.TESTOMATIO_RUN || process.env.runId || (0, utils_js_1.readLatestRunId)();
|
|
163
|
+
if (!runId) {
|
|
164
|
+
console.log('TESTOMATIO_RUN environment variable must be set or restored from a previous run.');
|
|
165
|
+
return process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
const client = new client_js_1.default({
|
|
168
|
+
apiKey,
|
|
169
|
+
runId,
|
|
170
|
+
isBatchEnabled: false,
|
|
171
|
+
});
|
|
172
|
+
let testruns = client.uploader.readUploadedFiles(runId);
|
|
173
|
+
const numTotalArtifacts = testruns.length;
|
|
174
|
+
debug('Found testruns:', testruns);
|
|
175
|
+
if (!opts.force)
|
|
176
|
+
testruns = testruns.filter(tr => !tr.uploaded);
|
|
177
|
+
if (!testruns.length) {
|
|
178
|
+
console.log(constants_js_1.APP_PREFIX, '🗄️ Total artifacts:', numTotalArtifacts);
|
|
179
|
+
if (numTotalArtifacts) {
|
|
180
|
+
console.log(constants_js_1.APP_PREFIX, 'No new artifacts to upload');
|
|
181
|
+
console.log(constants_js_1.APP_PREFIX, 'To re-upload artifacts run this command with --force flag');
|
|
182
|
+
}
|
|
183
|
+
process.exit(0);
|
|
184
|
+
}
|
|
185
|
+
const testrunsByRid = testruns.reduce((acc, { rid, file }) => {
|
|
186
|
+
if (!acc[rid]) {
|
|
187
|
+
acc[rid] = [];
|
|
188
|
+
}
|
|
189
|
+
if (!acc[rid].includes(file))
|
|
190
|
+
acc[rid].push(file);
|
|
191
|
+
return acc;
|
|
192
|
+
}, {});
|
|
193
|
+
await client.createRun();
|
|
194
|
+
client.uploader.checkEnabled();
|
|
195
|
+
client.uploader.disableLogStorage();
|
|
196
|
+
for (const rid in testrunsByRid) {
|
|
197
|
+
const files = testrunsByRid[rid];
|
|
198
|
+
await client.addTestRun(undefined, { rid, files });
|
|
199
|
+
}
|
|
200
|
+
console.log(constants_js_1.APP_PREFIX, '🗄️', client.uploader.successfulUploads.length, 'artifacts 🟢uploaded');
|
|
201
|
+
if (client.uploader.successfulUploads.length) {
|
|
202
|
+
debug('\n', constants_js_1.APP_PREFIX, `🗄️ ${client.uploader.successfulUploads.length} artifacts uploaded to S3 bucket`);
|
|
203
|
+
const uploadedArtifacts = client.uploader.successfulUploads.map(file => ({
|
|
204
|
+
relativePath: file.path.replace(process.cwd(), ''),
|
|
205
|
+
link: file.link,
|
|
206
|
+
sizePretty: (0, filesize_1.filesize)(file.size, { round: 0 }).toString(),
|
|
207
|
+
}));
|
|
208
|
+
uploadedArtifacts.forEach(upload => {
|
|
209
|
+
debug(`🟢Uploaded artifact`, `${upload.relativePath},`, 'size:', `${upload.sizePretty},`, 'link:', `${upload.link}`);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const filesizeStrMaxLength = 7;
|
|
213
|
+
if (client.uploader.failedUploads.length) {
|
|
214
|
+
console.log('\n', constants_js_1.APP_PREFIX, '🗄️', client.uploader.failedUploads.length, `artifacts 🔴${picocolors_1.default.bold('failed')} to upload`);
|
|
215
|
+
const failedUploads = client.uploader.failedUploads.map(({ path, size }) => ({
|
|
216
|
+
relativePath: path.replace(process.cwd(), ''),
|
|
217
|
+
sizePretty: (0, filesize_1.filesize)(size, { round: 0 }).toString(),
|
|
218
|
+
}));
|
|
219
|
+
const pathPadding = Math.max(...failedUploads.map(upload => upload.relativePath.length)) + 1;
|
|
220
|
+
failedUploads.forEach(upload => {
|
|
221
|
+
console.log(` ${picocolors_1.default.gray('|')} 🔴 ${upload.relativePath.padEnd(pathPadding)} ${picocolors_1.default.gray(`| ${upload.sizePretty.padStart(filesizeStrMaxLength)} |`)}`);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
program.parse(process.argv);
|
|
226
|
+
if (!process.argv.slice(2).length) {
|
|
227
|
+
program.outputHelp();
|
|
228
|
+
}
|
package/lib/bin/reportXml.js
CHANGED
|
@@ -4,16 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const commander_1 =
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
8
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
-
const glob_1 =
|
|
9
|
+
const glob_1 = require("glob");
|
|
10
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
11
|
const constants_js_1 = require("../constants.js");
|
|
12
12
|
const xmlReader_js_1 = __importDefault(require("../xmlReader.js"));
|
|
13
13
|
const package_json_1 = require("../../package.json");
|
|
14
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
14
15
|
const debug = (0, debug_1.default)('@testomatio/reporter:xml-cli');
|
|
15
16
|
console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io XML Reporter v${package_json_1.version}`)));
|
|
16
|
-
commander_1.
|
|
17
|
+
const program = new commander_1.Command();
|
|
18
|
+
program
|
|
17
19
|
.arguments('<pattern>')
|
|
18
20
|
.option('-d, --dir <dir>', 'Project directory')
|
|
19
21
|
.option('--java-tests [java-path]', 'Load Java tests from path, by default: src/test/java')
|
|
@@ -28,13 +30,13 @@ commander_1.default
|
|
|
28
30
|
if (opts.envFile) {
|
|
29
31
|
console.log(constants_js_1.APP_PREFIX, 'Loading env file:', opts.envFile);
|
|
30
32
|
debug('Loading env file: %s', opts.envFile);
|
|
31
|
-
|
|
33
|
+
dotenv_1.default.config({ path: opts.envFile });
|
|
32
34
|
}
|
|
33
|
-
if (javaTests === true)
|
|
34
|
-
javaTests = 'src/test/java';
|
|
35
35
|
lang = lang?.toLowerCase();
|
|
36
|
+
if (javaTests === true || (lang === 'java' && !javaTests))
|
|
37
|
+
javaTests = 'src/test/java';
|
|
36
38
|
const runReader = new xmlReader_js_1.default({ javaTests, lang });
|
|
37
|
-
const files = glob_1.
|
|
39
|
+
const files = glob_1.glob.sync(pattern, { cwd: opts.dir || process.cwd() });
|
|
38
40
|
if (!files.length) {
|
|
39
41
|
console.log(constants_js_1.APP_PREFIX, `Report can't be created. No XML files found 😥`);
|
|
40
42
|
process.exitCode = 1;
|
|
@@ -62,6 +64,6 @@ commander_1.default
|
|
|
62
64
|
clearTimeout(timeoutTimer);
|
|
63
65
|
});
|
|
64
66
|
if (process.argv.length < 3) {
|
|
65
|
-
|
|
67
|
+
program.outputHelp();
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
program.parse(process.argv);
|
package/lib/bin/startTest.js
CHANGED
|
@@ -5,14 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const cross_spawn_1 = require("cross-spawn");
|
|
8
|
-
const commander_1 =
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
9
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
10
|
const client_js_1 = __importDefault(require("../client.js"));
|
|
11
11
|
const constants_js_1 = require("../constants.js");
|
|
12
12
|
const package_json_1 = require("../../package.json");
|
|
13
13
|
const config_js_1 = require("../config.js");
|
|
14
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
14
15
|
console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io Reporter v${package_json_1.version}`)));
|
|
15
|
-
commander_1.
|
|
16
|
+
const program = new commander_1.Command();
|
|
17
|
+
program
|
|
16
18
|
.option('-c, --command <cmd>', 'Test runner command')
|
|
17
19
|
.option('--launch', 'Start a new run and return its ID')
|
|
18
20
|
.option('--finish', 'Finish Run by its ID')
|
|
@@ -22,7 +24,7 @@ commander_1.default
|
|
|
22
24
|
const { launch, finish, filter } = opts;
|
|
23
25
|
let { command } = opts;
|
|
24
26
|
if (opts.envFile)
|
|
25
|
-
|
|
27
|
+
dotenv_1.default.config({ path: opts.envFile });
|
|
26
28
|
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config_js_1.config.TESTOMATIO;
|
|
27
29
|
const title = process.env.TESTOMATIO_TITLE;
|
|
28
30
|
if (launch) {
|
|
@@ -35,6 +37,8 @@ commander_1.default
|
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
39
|
if (finish) {
|
|
40
|
+
// TODO: add error in case of TESTOMATIO environment variable is not set
|
|
41
|
+
// because command is fine in console, but actually (on testomat.io) run is not finished
|
|
38
42
|
if (!process.env.TESTOMATIO_RUN) {
|
|
39
43
|
console.log('TESTOMATIO_RUN environment variable must be set.');
|
|
40
44
|
return process.exit(1);
|
|
@@ -96,6 +100,6 @@ commander_1.default
|
|
|
96
100
|
});
|
|
97
101
|
});
|
|
98
102
|
if (process.argv.length <= 2) {
|
|
99
|
-
|
|
103
|
+
program.outputHelp();
|
|
100
104
|
}
|
|
101
|
-
|
|
105
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const client_js_1 = __importDefault(require("../client.js"));
|
|
11
|
+
const constants_js_1 = require("../constants.js");
|
|
12
|
+
const package_json_1 = require("../../package.json");
|
|
13
|
+
const config_js_1 = require("../config.js");
|
|
14
|
+
const utils_js_1 = require("../utils/utils.js");
|
|
15
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
16
|
+
const debug = (0, debug_1.default)('@testomatio/reporter:upload-cli');
|
|
17
|
+
console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io Reporter v${package_json_1.version}`)));
|
|
18
|
+
const program = new commander_1.Command();
|
|
19
|
+
program
|
|
20
|
+
.option('--env-file <envfile>', 'Load environment variables from env file')
|
|
21
|
+
.option('--force', 'Re-upload artifacts even if they were uploaded before')
|
|
22
|
+
.action(async (opts) => {
|
|
23
|
+
if (opts.envFile) {
|
|
24
|
+
dotenv_1.default.config({ path: opts.envFile });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
dotenv_1.default.config();
|
|
28
|
+
}
|
|
29
|
+
const apiKey = config_js_1.config.TESTOMATIO;
|
|
30
|
+
process.env.TESTOMATIO_DISABLE_ARTIFACTS = '';
|
|
31
|
+
const runId = process.env.TESTOMATIO_RUN || process.env.runId || (0, utils_js_1.readLatestRunId)();
|
|
32
|
+
if (!runId) {
|
|
33
|
+
console.log('TESTOMATIO_RUN environment variable must be set or restored from a previous run.');
|
|
34
|
+
return process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
const client = new client_js_1.default({
|
|
37
|
+
apiKey,
|
|
38
|
+
runId,
|
|
39
|
+
isBatchEnabled: false,
|
|
40
|
+
});
|
|
41
|
+
let testruns = client.uploader.readUploadedFiles(process.env.TESTOMATIO_RUN);
|
|
42
|
+
const numTotalArtifacts = testruns.length;
|
|
43
|
+
debug('Found testruns:', testruns);
|
|
44
|
+
if (!opts.force)
|
|
45
|
+
testruns = testruns.filter(tr => !tr.uploaded);
|
|
46
|
+
if (!testruns.length) {
|
|
47
|
+
console.log(constants_js_1.APP_PREFIX, 'Total artifacts:', numTotalArtifacts);
|
|
48
|
+
if (numTotalArtifacts) {
|
|
49
|
+
console.log(constants_js_1.APP_PREFIX, 'No new artifacts to upload');
|
|
50
|
+
console.log(constants_js_1.APP_PREFIX, 'To re-upload artifacts run this command with --force flag');
|
|
51
|
+
}
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
const testrunsByRid = testruns.reduce((acc, { rid, file }) => {
|
|
55
|
+
if (!acc[rid]) {
|
|
56
|
+
acc[rid] = [];
|
|
57
|
+
}
|
|
58
|
+
if (!acc[rid].includes(file))
|
|
59
|
+
acc[rid].push(file);
|
|
60
|
+
return acc;
|
|
61
|
+
}, {});
|
|
62
|
+
// we need to obtain S3 credentials
|
|
63
|
+
await client.createRun();
|
|
64
|
+
client.uploader.checkEnabled();
|
|
65
|
+
client.uploader.disableLogStorage();
|
|
66
|
+
for (const rid in testrunsByRid) {
|
|
67
|
+
const files = testrunsByRid[rid];
|
|
68
|
+
await client.addTestRun(undefined, {
|
|
69
|
+
rid,
|
|
70
|
+
files,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
console.log(constants_js_1.APP_PREFIX, client.uploader.successfulUploads.length, 'artifacts uploaded');
|
|
74
|
+
if (client.uploader.failedUploads.length) {
|
|
75
|
+
console.log(constants_js_1.APP_PREFIX, client.uploader.failedUploads.length, 'artifacts failed to upload');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (process.argv.length <= 1) {
|
|
79
|
+
program.outputHelp();
|
|
80
|
+
}
|
|
81
|
+
program.parse(process.argv);
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export default Client;
|
|
2
|
+
export type TestData = import("../types/types.js").TestData;
|
|
3
|
+
export type PipeResult = import("../types/types.js").PipeResult;
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../types/types.js').TestData} TestData
|
|
6
|
+
* @typedef {import('../types/types.js').PipeResult} PipeResult
|
|
7
|
+
*/
|
|
8
|
+
export class Client {
|
|
9
|
+
/**
|
|
10
|
+
* Create a Testomat client instance
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
constructor(params?: {});
|
|
14
|
+
paramsForPipesFactory: {};
|
|
15
|
+
pipeStore: {};
|
|
16
|
+
runId: `${string}-${string}-${string}-${string}-${string}`;
|
|
17
|
+
queue: Promise<void>;
|
|
18
|
+
version: any;
|
|
19
|
+
executionList: Promise<void>;
|
|
20
|
+
uploader: S3Uploader;
|
|
21
|
+
/**
|
|
22
|
+
* Asynchronously prepares the execution list for running tests through various pipes.
|
|
23
|
+
* Each pipe in the client is checked for enablement,
|
|
24
|
+
* and if all pipes are disabled, the function returns a resolved Promise.
|
|
25
|
+
* Otherwise, it executes the `prepareRun` method for each enabled pipe and collects the results.
|
|
26
|
+
* The results are then filtered to remove any undefined values.
|
|
27
|
+
* If no valid results are found, the function returns undefined.
|
|
28
|
+
* Otherwise, it returns the first non-empty array from the filtered results.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} params - The options for preparing the test execution list.
|
|
31
|
+
* @param {string} params.pipe - Name of the executed pipe.
|
|
32
|
+
* @param {string} params.pipeOptions - Filter option.
|
|
33
|
+
* @returns {Promise<any>} - A Promise that resolves to an
|
|
34
|
+
* array containing the prepared execution list,
|
|
35
|
+
* or resolves to undefined if no valid results are found or if all pipes are disabled.
|
|
36
|
+
*/
|
|
37
|
+
prepareRun(params: {
|
|
38
|
+
pipe: string;
|
|
39
|
+
pipeOptions: string;
|
|
40
|
+
}): Promise<any>;
|
|
41
|
+
pipes: any[];
|
|
42
|
+
/**
|
|
43
|
+
* Used to create a new Test run
|
|
44
|
+
*
|
|
45
|
+
* @returns {Promise<any>} - resolves to Run id which should be used to update / add test
|
|
46
|
+
*/
|
|
47
|
+
createRun(params: any): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Updates test status and its data
|
|
50
|
+
*
|
|
51
|
+
* @param {string|undefined} status
|
|
52
|
+
* @param {TestData} [testData]
|
|
53
|
+
* @returns {Promise<PipeResult[]>}
|
|
54
|
+
*/
|
|
55
|
+
addTestRun(status: string | undefined, testData?: TestData): Promise<PipeResult[]>;
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* Updates the status of the current test run and finishes the run.
|
|
59
|
+
* @param {'passed' | 'failed' | 'skipped' | 'finished'} status - The status of the current test run.
|
|
60
|
+
* Must be one of "passed", "failed", or "finished"
|
|
61
|
+
* @param {boolean} [isParallel] - Whether the current test run was executed in parallel with other tests.
|
|
62
|
+
* @returns {Promise<any>} - A Promise that resolves when finishes the run.
|
|
63
|
+
*/
|
|
64
|
+
updateRunStatus(status: "passed" | "failed" | "skipped" | "finished", isParallel?: boolean): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the formatted stack including the stack trace, steps, and logs.
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
formatLogs({ error, steps, logs }: {
|
|
70
|
+
error: any;
|
|
71
|
+
steps: any;
|
|
72
|
+
logs: any;
|
|
73
|
+
}): string;
|
|
74
|
+
formatError(error: any, message: any): string;
|
|
75
|
+
}
|
|
76
|
+
import { S3Uploader } from './uploader.js';
|