@testomatio/reporter 2.0.0-beta-esm → 2.0.0-beta.1-gaxios

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.
Files changed (121) hide show
  1. package/lib/adapter/codecept.d.ts +2 -0
  2. package/lib/adapter/codecept.js +31 -26
  3. package/lib/adapter/cucumber/current.d.ts +14 -0
  4. package/lib/adapter/cucumber/legacy.d.ts +0 -0
  5. package/lib/adapter/cucumber.d.ts +2 -0
  6. package/lib/adapter/cypress-plugin/index.d.ts +2 -0
  7. package/lib/adapter/cypress-plugin/index.js +10 -10
  8. package/lib/adapter/jasmine.d.ts +11 -0
  9. package/lib/adapter/jest.d.ts +13 -0
  10. package/lib/adapter/mocha.d.ts +2 -0
  11. package/lib/adapter/mocha.js +4 -4
  12. package/lib/adapter/nightwatch.d.ts +4 -0
  13. package/lib/adapter/nightwatch.js +80 -0
  14. package/lib/adapter/playwright.d.ts +14 -0
  15. package/lib/adapter/playwright.js +58 -33
  16. package/lib/adapter/vitest.d.ts +35 -0
  17. package/lib/adapter/vitest.js +6 -6
  18. package/lib/adapter/webdriver.d.ts +24 -0
  19. package/lib/adapter/webdriver.js +51 -14
  20. package/lib/bin/cli.d.ts +2 -0
  21. package/lib/bin/cli.js +249 -0
  22. package/lib/bin/reportXml.d.ts +2 -0
  23. package/lib/bin/reportXml.js +11 -9
  24. package/lib/bin/startTest.d.ts +2 -0
  25. package/lib/bin/startTest.js +9 -5
  26. package/lib/bin/uploadArtifacts.d.ts +2 -0
  27. package/lib/bin/uploadArtifacts.js +81 -0
  28. package/lib/client.d.ts +76 -0
  29. package/lib/client.js +128 -53
  30. package/lib/config.d.ts +1 -0
  31. package/lib/config.js +2 -2
  32. package/lib/constants.d.ts +25 -0
  33. package/lib/constants.js +5 -1
  34. package/lib/data-storage.d.ts +34 -0
  35. package/lib/data-storage.js +19 -9
  36. package/lib/junit-adapter/adapter.d.ts +9 -0
  37. package/lib/junit-adapter/csharp.d.ts +4 -0
  38. package/lib/junit-adapter/index.d.ts +3 -0
  39. package/lib/junit-adapter/java.d.ts +5 -0
  40. package/lib/junit-adapter/javascript.d.ts +4 -0
  41. package/lib/junit-adapter/python.d.ts +5 -0
  42. package/lib/junit-adapter/ruby.d.ts +4 -0
  43. package/lib/output.d.ts +11 -0
  44. package/lib/package.json +3 -1
  45. package/lib/pipe/bitbucket.d.ts +25 -0
  46. package/lib/pipe/bitbucket.js +40 -28
  47. package/lib/pipe/csv.d.ts +47 -0
  48. package/lib/pipe/csv.js +2 -2
  49. package/lib/pipe/debug.d.ts +29 -0
  50. package/lib/pipe/debug.js +108 -0
  51. package/lib/pipe/github.d.ts +30 -0
  52. package/lib/pipe/github.js +37 -5
  53. package/lib/pipe/gitlab.d.ts +25 -0
  54. package/lib/pipe/gitlab.js +29 -11
  55. package/lib/pipe/html.d.ts +35 -0
  56. package/lib/pipe/html.js +9 -4
  57. package/lib/pipe/index.d.ts +1 -0
  58. package/lib/pipe/index.js +20 -10
  59. package/lib/pipe/testomatio.d.ts +71 -0
  60. package/lib/pipe/testomatio.js +117 -92
  61. package/lib/reporter-functions.d.ts +34 -0
  62. package/lib/reporter-functions.js +17 -7
  63. package/lib/reporter.d.ts +232 -0
  64. package/lib/reporter.js +19 -33
  65. package/lib/services/artifacts.d.ts +33 -0
  66. package/lib/services/index.d.ts +9 -0
  67. package/lib/services/key-values.d.ts +27 -0
  68. package/lib/services/key-values.js +1 -1
  69. package/lib/services/logger.d.ts +64 -0
  70. package/lib/services/logger.js +1 -2
  71. package/lib/template/testomatio.hbs +651 -1366
  72. package/lib/uploader.d.ts +60 -0
  73. package/lib/uploader.js +312 -0
  74. package/lib/utils/pipe_utils.d.ts +41 -0
  75. package/lib/utils/pipe_utils.js +3 -5
  76. package/lib/utils/utils.d.ts +45 -0
  77. package/lib/utils/utils.js +81 -10
  78. package/lib/xmlReader.d.ts +92 -0
  79. package/lib/xmlReader.js +28 -16
  80. package/package.json +19 -14
  81. package/src/adapter/codecept.js +30 -26
  82. package/src/adapter/cypress-plugin/index.js +5 -5
  83. package/src/adapter/mocha.cjs +1 -1
  84. package/src/adapter/mocha.js +4 -4
  85. package/src/adapter/nightwatch.js +88 -0
  86. package/src/adapter/playwright.js +59 -31
  87. package/src/adapter/vitest.js +6 -6
  88. package/src/adapter/webdriver.js +41 -11
  89. package/src/bin/cli.js +302 -0
  90. package/src/bin/reportXml.js +15 -8
  91. package/src/bin/startTest.js +7 -3
  92. package/src/bin/uploadArtifacts.js +90 -0
  93. package/src/client.js +137 -57
  94. package/src/config.js +2 -2
  95. package/src/constants.js +5 -1
  96. package/src/data-storage.js +2 -2
  97. package/src/pipe/bitbucket.js +24 -26
  98. package/src/pipe/csv.js +3 -3
  99. package/src/pipe/debug.js +104 -0
  100. package/src/pipe/github.js +3 -5
  101. package/src/pipe/gitlab.js +33 -15
  102. package/src/pipe/html.js +14 -7
  103. package/src/pipe/index.js +5 -7
  104. package/src/pipe/testomatio.js +156 -158
  105. package/src/reporter-functions.js +18 -7
  106. package/src/reporter.cjs_decprecated +21 -0
  107. package/src/reporter.js +20 -11
  108. package/src/services/key-values.js +1 -1
  109. package/src/services/logger.js +5 -4
  110. package/src/template/testomatio.hbs +651 -1366
  111. package/src/uploader.js +371 -0
  112. package/src/utils/pipe_utils.js +4 -12
  113. package/src/utils/utils.js +50 -14
  114. package/src/xmlReader.js +32 -18
  115. package/lib/adapter/jasmine/jasmine.js +0 -63
  116. package/lib/adapter/mocha/mocha.js +0 -125
  117. package/lib/fileUploader.js +0 -245
  118. package/lib/utils/chalk.js +0 -10
  119. package/src/fileUploader.js +0 -307
  120. package/src/reporter.cjs +0 -22
  121. package/src/utils/chalk.js +0 -13
@@ -15,21 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- // eslint-disable-next-line
30
39
  const reporter_1 = __importStar(require("@wdio/reporter"));
31
40
  const client_js_1 = __importDefault(require("../client.js"));
32
41
  const utils_js_1 = require("../utils/utils.js");
42
+ const index_js_1 = require("../services/index.js");
43
+ const constants_js_1 = require("../constants.js");
33
44
  class WebdriverReporter extends reporter_1.default {
34
45
  constructor(options) {
35
46
  super(options);
@@ -51,18 +62,30 @@ class WebdriverReporter extends reporter_1.default {
51
62
  this._isSynchronising = true;
52
63
  await Promise.all(this._addTestPromises);
53
64
  this._isSynchronising = false;
54
- // NOTE: new functionality; may break everything
65
+ // NOTE: new functionality; may break everything
55
66
  // also this may require additional status mapping
56
67
  await this.client.updateRunStatus(runData.failures ? 'failed' : 'passed');
57
68
  }
69
+ onRunnerStart() {
70
+ // clear dir with artifacts/logs
71
+ //
72
+ utils_js_1.fileSystem.clearDir(constants_js_1.TESTOMAT_TMP_STORAGE_DIR);
73
+ }
74
+ onTestStart(test) {
75
+ index_js_1.services.setContext(test.fullTitle);
76
+ }
58
77
  onTestEnd(test) {
78
+ test.suite = test.parent;
79
+ const logs = getTestLogs(test.fullTitle);
80
+ // TODO: FIX: artifacts for some reason leads to empty report on Testomat.io
81
+ // const artifacts = services.artifacts.get(test.fullTitle);
82
+ // const keyValues = services.keyValues.get(test.fullTitle);
83
+ test.logs = logs;
84
+ // test.artifacts = artifacts;
85
+ // test.meta = keyValues;
59
86
  this._addTestPromises.push(this.addTest(test));
60
87
  }
61
88
  // wdio-cucumber does not trigger onTestEnd hook, thus, using this one
62
- /**
63
- *
64
- * @returns
65
- */
66
89
  onSuiteEnd(scerario) {
67
90
  if (scerario.type === 'scenario') {
68
91
  this._addTestPromises.push(this.addBddScenario(scerario));
@@ -78,7 +101,10 @@ class WebdriverReporter extends reporter_1.default {
78
101
  .filter(el => el.endpoint === screenshotEndpoint && el.result && el.result.value)
79
102
  .map(el => Buffer.from(el.result.value, 'base64'));
80
103
  await this.client.addTestRun(state, {
104
+ manuallyAttachedArtifacts: test.artifacts,
81
105
  error,
106
+ logs: test.logs,
107
+ meta: test.meta,
82
108
  title,
83
109
  test_id: testId,
84
110
  time: duration,
@@ -86,7 +112,7 @@ class WebdriverReporter extends reporter_1.default {
86
112
  });
87
113
  }
88
114
  /**
89
- * @param {import('../../types').WebdriverIOScenario} scenario
115
+ * @param {import('../../types/types.js').WebdriverIOScenario} scenario
90
116
  */
91
117
  addBddScenario(scenario) {
92
118
  if (!this.client)
@@ -114,4 +140,15 @@ class WebdriverReporter extends reporter_1.default {
114
140
  });
115
141
  }
116
142
  }
143
+ /**
144
+ *
145
+ * @param {*} fullTestTitle
146
+ * @returns string
147
+ */
148
+ function getTestLogs(fullTestTitle) {
149
+ const logsArr = index_js_1.services.logger.getLogs(fullTestTitle);
150
+ // remove duplicates (for some reason, logs are duplicated several times)
151
+ const logs = logsArr ? Array.from(new Set(logsArr)).join('\n').trim() : '';
152
+ return logs;
153
+ }
117
154
  module.exports = WebdriverReporter;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin/cli.js ADDED
@@ -0,0 +1,249 @@
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 = 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) javaTests = 'src/test/java';
126
+ // lang = lang?.toLowerCase();
127
+ // const runReader = new XmlReader({ javaTests, lang });
128
+ // const files = glob.sync(pattern, { cwd: opts.dir || process.cwd() });
129
+ // if (!files.length) {
130
+ // console.log(APP_PREFIX, `Report can't be created. No XML files found 😥`);
131
+ // process.exit(1);
132
+ // }
133
+ program
134
+ .command('xml')
135
+ .description('Parse XML reports and upload to Testomat.io')
136
+ .argument('<pattern>', 'XML file pattern')
137
+ .option('-d, --dir <dir>', 'Project directory')
138
+ .option('--java-tests [java-path]', 'Load Java tests from path, by default: src/test/java')
139
+ .option('--lang <lang>', 'Language used (python, ruby, java)')
140
+ .option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
141
+ .action(async (pattern, opts) => {
142
+ if (!pattern.endsWith('.xml')) {
143
+ pattern += '.xml';
144
+ }
145
+ let { javaTests, lang } = opts;
146
+ if (javaTests === true)
147
+ javaTests = 'src/test/java';
148
+ lang = lang?.toLowerCase();
149
+ const runReader = new xmlReader_js_1.default({ javaTests, lang });
150
+ const files = glob_1.glob.sync(pattern, { cwd: opts.dir || process.cwd() });
151
+ if (!files.length) {
152
+ console.log(constants_js_1.APP_PREFIX, `Report can't be created. No XML files found 😥`);
153
+ process.exit(1);
154
+ }
155
+ for (const file of files) {
156
+ console.log(constants_js_1.APP_PREFIX, `Parsed ${file}`);
157
+ runReader.parse(file);
158
+ }
159
+ let timeoutTimer;
160
+ if (opts.timelimit) {
161
+ timeoutTimer = setTimeout(() => {
162
+ console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
163
+ process.exit(0);
164
+ }, parseInt(opts.timelimit, 10) * 1000);
165
+ }
166
+ try {
167
+ await runReader.createRun();
168
+ await runReader.uploadData();
169
+ }
170
+ catch (err) {
171
+ console.log(constants_js_1.APP_PREFIX, 'Error updating status, skipping...', err);
172
+ }
173
+ if (timeoutTimer)
174
+ clearTimeout(timeoutTimer);
175
+ });
176
+ program
177
+ .command('upload-artifacts')
178
+ .description('Upload artifacts to Testomat.io')
179
+ .option('--force', 'Re-upload artifacts even if they were uploaded before')
180
+ .action(async (opts) => {
181
+ const apiKey = config_js_1.config.TESTOMATIO;
182
+ process.env.TESTOMATIO_DISABLE_ARTIFACTS = '';
183
+ const runId = process.env.TESTOMATIO_RUN || process.env.runId || (0, utils_js_1.readLatestRunId)();
184
+ if (!runId) {
185
+ console.log('TESTOMATIO_RUN environment variable must be set or restored from a previous run.');
186
+ return process.exit(1);
187
+ }
188
+ const client = new client_js_1.default({
189
+ apiKey,
190
+ runId,
191
+ isBatchEnabled: false,
192
+ });
193
+ let testruns = client.uploader.readUploadedFiles(runId);
194
+ const numTotalArtifacts = testruns.length;
195
+ debug('Found testruns:', testruns);
196
+ if (!opts.force)
197
+ testruns = testruns.filter(tr => !tr.uploaded);
198
+ if (!testruns.length) {
199
+ console.log(constants_js_1.APP_PREFIX, '🗄️ Total artifacts:', numTotalArtifacts);
200
+ if (numTotalArtifacts) {
201
+ console.log(constants_js_1.APP_PREFIX, 'No new artifacts to upload');
202
+ console.log(constants_js_1.APP_PREFIX, 'To re-upload artifacts run this command with --force flag');
203
+ }
204
+ process.exit(0);
205
+ }
206
+ const testrunsByRid = testruns.reduce((acc, { rid, file }) => {
207
+ if (!acc[rid]) {
208
+ acc[rid] = [];
209
+ }
210
+ if (!acc[rid].includes(file))
211
+ acc[rid].push(file);
212
+ return acc;
213
+ }, {});
214
+ await client.createRun();
215
+ client.uploader.checkEnabled();
216
+ client.uploader.disableLogStorage();
217
+ for (const rid in testrunsByRid) {
218
+ const files = testrunsByRid[rid];
219
+ await client.addTestRun(undefined, { rid, files });
220
+ }
221
+ console.log(constants_js_1.APP_PREFIX, '🗄️', client.uploader.successfulUploads.length, 'artifacts 🟢uploaded');
222
+ if (client.uploader.successfulUploads.length) {
223
+ debug('\n', constants_js_1.APP_PREFIX, `🗄️ ${client.uploader.successfulUploads.length} artifacts uploaded to S3 bucket`);
224
+ const uploadedArtifacts = client.uploader.successfulUploads.map(file => ({
225
+ relativePath: file.path.replace(process.cwd(), ''),
226
+ link: file.link,
227
+ sizePretty: (0, filesize_1.filesize)(file.size, { round: 0 }).toString(),
228
+ }));
229
+ uploadedArtifacts.forEach(upload => {
230
+ debug(`🟢Uploaded artifact`, `${upload.relativePath},`, 'size:', `${upload.sizePretty},`, 'link:', `${upload.link}`);
231
+ });
232
+ }
233
+ const filesizeStrMaxLength = 7;
234
+ if (client.uploader.failedUploads.length) {
235
+ console.log('\n', constants_js_1.APP_PREFIX, '🗄️', client.uploader.failedUploads.length, `artifacts 🔴${picocolors_1.default.bold('failed')} to upload`);
236
+ const failedUploads = client.uploader.failedUploads.map(({ path, size }) => ({
237
+ relativePath: path.replace(process.cwd(), ''),
238
+ sizePretty: (0, filesize_1.filesize)(size, { round: 0 }).toString(),
239
+ }));
240
+ const pathPadding = Math.max(...failedUploads.map(upload => upload.relativePath.length)) + 1;
241
+ failedUploads.forEach(upload => {
242
+ console.log(` ${picocolors_1.default.gray('|')} 🔴 ${upload.relativePath.padEnd(pathPadding)} ${picocolors_1.default.gray(`| ${upload.sizePretty.padStart(filesizeStrMaxLength)} |`)}`);
243
+ });
244
+ }
245
+ });
246
+ program.parse(process.argv);
247
+ if (!process.argv.slice(2).length) {
248
+ program.outputHelp();
249
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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 = __importDefault(require("commander"));
7
+ const commander_1 = require("commander");
8
8
  const picocolors_1 = __importDefault(require("picocolors"));
9
- const glob_1 = __importDefault(require("glob"));
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.default
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
- require('dotenv').config({ path: opts.envFile }); // eslint-disable-line
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.default.sync(pattern, { cwd: opts.dir || process.cwd() });
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
- commander_1.default.outputHelp();
67
+ program.outputHelp();
66
68
  }
67
- commander_1.default.parse(process.argv);
69
+ program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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 = __importDefault(require("commander"));
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.default
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
- require('dotenv').config(opts.envFile); // eslint-disable-line
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
- commander_1.default.outputHelp();
103
+ program.outputHelp();
100
104
  }
101
- commander_1.default.parse(process.argv);
105
+ program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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);
@@ -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';