@testomatio/reporter 1.6.0-beta-1-artifacts → 2.0.0-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.
Files changed (97) hide show
  1. package/lib/adapter/codecept.js +288 -330
  2. package/lib/adapter/cucumber/current.js +195 -203
  3. package/lib/adapter/cucumber/legacy.js +130 -155
  4. package/lib/adapter/cucumber.js +5 -16
  5. package/lib/adapter/cypress-plugin/index.js +91 -105
  6. package/lib/adapter/jasmine/jasmine.js +63 -0
  7. package/lib/adapter/jasmine.js +54 -53
  8. package/lib/adapter/jest.js +97 -99
  9. package/lib/adapter/mocha/mocha.js +125 -0
  10. package/lib/adapter/mocha.js +111 -140
  11. package/lib/adapter/playwright.js +168 -200
  12. package/lib/adapter/vitest.js +144 -143
  13. package/lib/adapter/webdriver.js +113 -97
  14. package/lib/bin/reportXml.js +49 -49
  15. package/lib/bin/startTest.js +80 -97
  16. package/lib/client.js +344 -385
  17. package/lib/config.js +16 -21
  18. package/lib/constants.js +49 -43
  19. package/lib/data-storage.js +206 -188
  20. package/lib/fileUploader.js +245 -0
  21. package/lib/junit-adapter/adapter.js +17 -20
  22. package/lib/junit-adapter/csharp.js +18 -14
  23. package/lib/junit-adapter/index.js +27 -25
  24. package/lib/junit-adapter/java.js +41 -53
  25. package/lib/junit-adapter/javascript.js +30 -27
  26. package/lib/junit-adapter/python.js +38 -37
  27. package/lib/junit-adapter/ruby.js +11 -8
  28. package/lib/output.js +44 -52
  29. package/lib/package.json +1 -0
  30. package/lib/pipe/bitbucket.js +208 -227
  31. package/lib/pipe/csv.js +111 -124
  32. package/lib/pipe/github.js +184 -211
  33. package/lib/pipe/gitlab.js +164 -205
  34. package/lib/pipe/html.js +253 -312
  35. package/lib/pipe/index.js +83 -63
  36. package/lib/pipe/testomatio.js +391 -454
  37. package/lib/reporter-functions.js +16 -20
  38. package/lib/reporter.js +47 -17
  39. package/lib/services/artifacts.js +55 -51
  40. package/lib/services/index.js +14 -12
  41. package/lib/services/key-values.js +56 -53
  42. package/lib/services/logger.js +227 -245
  43. package/lib/utils/chalk.js +10 -0
  44. package/lib/utils/pipe_utils.js +91 -86
  45. package/lib/utils/utils.js +289 -273
  46. package/lib/xmlReader.js +480 -519
  47. package/package.json +57 -19
  48. package/src/adapter/codecept.js +369 -0
  49. package/src/adapter/cucumber/current.js +228 -0
  50. package/src/adapter/cucumber/legacy.js +158 -0
  51. package/src/adapter/cucumber.js +4 -0
  52. package/src/adapter/cypress-plugin/index.js +110 -0
  53. package/src/adapter/jasmine.js +60 -0
  54. package/src/adapter/jest.js +107 -0
  55. package/src/adapter/mocha.cjs +2 -0
  56. package/src/adapter/mocha.js +156 -0
  57. package/src/adapter/playwright.js +222 -0
  58. package/src/adapter/vitest.js +183 -0
  59. package/src/adapter/webdriver.js +111 -0
  60. package/src/bin/reportXml.js +67 -0
  61. package/src/bin/startTest.js +119 -0
  62. package/src/client.js +423 -0
  63. package/src/config.js +30 -0
  64. package/src/constants.js +49 -0
  65. package/src/data-storage.js +204 -0
  66. package/src/fileUploader.js +307 -0
  67. package/src/junit-adapter/adapter.js +23 -0
  68. package/src/junit-adapter/csharp.js +16 -0
  69. package/src/junit-adapter/index.js +28 -0
  70. package/src/junit-adapter/java.js +58 -0
  71. package/src/junit-adapter/javascript.js +31 -0
  72. package/src/junit-adapter/python.js +42 -0
  73. package/src/junit-adapter/ruby.js +10 -0
  74. package/src/output.js +57 -0
  75. package/src/pipe/bitbucket.js +254 -0
  76. package/src/pipe/csv.js +140 -0
  77. package/src/pipe/github.js +234 -0
  78. package/src/pipe/gitlab.js +229 -0
  79. package/src/pipe/html.js +366 -0
  80. package/src/pipe/index.js +73 -0
  81. package/src/pipe/testomatio.js +498 -0
  82. package/src/reporter-functions.js +44 -0
  83. package/src/reporter.cjs +22 -0
  84. package/src/reporter.js +24 -0
  85. package/src/services/artifacts.js +59 -0
  86. package/src/services/index.js +13 -0
  87. package/src/services/key-values.js +59 -0
  88. package/src/services/logger.js +314 -0
  89. package/src/template/emptyData.svg +23 -0
  90. package/src/template/testomatio.hbs +1421 -0
  91. package/src/utils/chalk.js +13 -0
  92. package/src/utils/pipe_utils.js +127 -0
  93. package/src/utils/utils.js +341 -0
  94. package/src/xmlReader.js +551 -0
  95. package/lib/bin/cli.js +0 -220
  96. package/lib/bin/uploadArtifacts.js +0 -91
  97. package/lib/uploader.js +0 -308
@@ -1,364 +1,322 @@
1
- const debug = require('debug')('@testomatio/reporter:adapter:codeceptjs');
2
- const chalk = require('chalk');
3
- const TestomatClient = require('../client');
4
- const { STATUS, APP_PREFIX, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
5
- const { getTestomatIdFromTestTitle, fileSystem } = require('../utils/utils');
6
- const { services } = require('../services');
7
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CodeceptReporter = CodeceptReporter;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
9
+ const client_js_1 = __importDefault(require("../client.js"));
10
+ const constants_js_1 = require("../constants.js");
11
+ const utils_js_1 = require("../utils/utils.js");
12
+ const index_js_1 = require("../services/index.js");
13
+ const fileUploader_js_1 = require("../fileUploader.js");
14
+ // eslint-disable-next-line
15
+ const codeceptjs_1 = __importDefault(require("codeceptjs"));
16
+ const debug = (0, debug_1.default)('@testomatio/reporter:adapter:codeceptjs');
17
+ // @ts-ignore
8
18
  if (!global.codeceptjs) {
9
- // eslint-disable-next-line global-require, import/no-extraneous-dependencies
10
- global.codeceptjs = require('codeceptjs');
19
+ // @ts-ignore
20
+ global.codeceptjs = codeceptjs_1.default;
11
21
  }
12
-
22
+ // @ts-ignore
13
23
  const { event, recorder, codecept } = global.codeceptjs;
14
-
15
24
  let currentMetaStep = [];
16
25
  let error;
17
26
  let stepShift = 0;
18
-
19
27
  // const output = new Output({
20
28
  // filterFn: stack => !stack.includes('codeceptjs/lib/output'), // output from codeceptjs
21
29
  // });
22
-
23
30
  let stepStart = new Date();
24
-
25
31
  const MAJOR_VERSION = parseInt(codecept.version().match(/\d/)[0], 10);
26
-
27
32
  const DATA_REGEXP = /[|\s]+?(\{".*\}|\[.*\])/;
28
-
29
33
  if (MAJOR_VERSION < 3) {
30
- console.log('🔴 This reporter works with CodeceptJS 3+, please update your tests');
34
+ console.log('🔴 This reporter works with CodeceptJS 3+, please update your tests');
31
35
  }
32
-
33
36
  function CodeceptReporter(config) {
34
- let failedTests = [];
35
- let videos = [];
36
- let traces = [];
37
- const reportTestPromises = [];
38
-
39
- const testTimeMap = {};
40
- const { apiKey } = config;
41
-
42
- const getDuration = test => {
43
- if (testTimeMap[test.id]) {
44
- return Date.now() - testTimeMap[test.id];
45
- }
46
-
47
- return 0;
48
- };
49
-
50
- const client = new TestomatClient({ apiKey });
51
-
52
- recorder.startUnlessRunning();
53
-
54
- // Listening to events
55
- event.dispatcher.on(event.all.before, () => {
56
- // clear tmp dir
57
- fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
58
-
59
- // recorder.add('Creating new run', () => );
60
- client.createRun();
61
- videos = [];
62
- traces = [];
63
-
64
- if (!global.testomatioDataStore) global.testomatioDataStore = {};
65
- });
66
-
67
- let hookSteps = [];
68
- let suiteHookRunning = false;
69
-
70
- event.dispatcher.on(event.suite.before, suite => {
71
- suiteHookRunning = true;
72
- hookSteps = [];
73
- global.testomatioDataStore.steps = [];
74
-
75
- services.setContext(suite.fullTitle());
76
- });
77
-
78
- event.dispatcher.on(event.suite.after, () => {
79
- services.setContext(null);
80
- });
81
-
82
- event.dispatcher.on(event.hook.started, () => {
83
- // global.testomatioDataStore.steps = [];
84
- });
85
-
86
- event.dispatcher.on(event.hook.passed, () => {
87
- if (suiteHookRunning) {
88
- hookSteps.push(...global.testomatioDataStore.steps);
89
- services.setContext(null);
90
- }
91
- });
92
-
93
- event.dispatcher.on(event.hook.failed, () => {
94
- if (suiteHookRunning) {
95
- hookSteps.push(...global.testomatioDataStore.steps);
96
- services.setContext(null);
97
- }
98
- });
99
-
100
- event.dispatcher.on(event.test.before, test => {
101
- suiteHookRunning = false;
102
- global.testomatioDataStore.steps = [];
103
-
104
- recorder.add(() => {
105
- currentMetaStep = [];
106
- // output.reset();
107
- // output.start();
108
- stepShift = 0;
37
+ let failedTests = [];
38
+ let videos = [];
39
+ let traces = [];
40
+ const reportTestPromises = [];
41
+ const testTimeMap = {};
42
+ const { apiKey } = config;
43
+ const getDuration = test => {
44
+ if (testTimeMap[test.id]) {
45
+ return Date.now() - testTimeMap[test.id];
46
+ }
47
+ return 0;
48
+ };
49
+ const client = new client_js_1.default({ apiKey });
50
+ recorder.startUnlessRunning();
51
+ // Listening to events
52
+ event.dispatcher.on(event.all.before, () => {
53
+ // clear tmp dir
54
+ utils_js_1.fileSystem.clearDir(constants_js_1.TESTOMAT_TMP_STORAGE_DIR);
55
+ // recorder.add('Creating new run', () => );
56
+ client.createRun();
57
+ videos = [];
58
+ traces = [];
59
+ if (!global.testomatioDataStore)
60
+ global.testomatioDataStore = {};
109
61
  });
110
-
111
- if (!global.testomatioDataStore) global.testomatioDataStore = {};
112
- // reset steps
113
- global.testomatioDataStore.steps = [];
114
-
115
- services.setContext(test.fullTitle());
116
- });
117
-
118
- event.dispatcher.on(event.test.started, test => {
119
- services.setContext(test.fullTitle());
120
-
121
- testTimeMap[test.id] = Date.now();
122
- // start logging
123
- });
124
-
125
- event.dispatcher.on(event.all.result, async () => {
126
- debug('waiting for all tests to be reported');
127
- // all tests were reported and we can upload videos
128
- await Promise.all(reportTestPromises);
129
-
130
- await uploadAttachments(client, videos, '🎞️ Uploading', 'video');
131
- await uploadAttachments(client, traces, '📁 Uploading', 'trace');
132
-
133
- const status = failedTests.length === 0 ? STATUS.PASSED : STATUS.FAILED;
134
- client.updateRunStatus(status);
135
- });
136
-
137
- event.dispatcher.on(event.test.passed, test => {
138
- const { id, tags, title } = test;
139
- if (id && failedTests.includes(id)) {
140
- failedTests = failedTests.filter(failed => id !== failed);
141
- }
142
- const testObj = getTestAndMessage(title);
143
-
144
- const logs = getTestLogs(test);
145
- const manuallyAttachedArtifacts = services.artifacts.get(test.fullTitle());
146
- const keyValues = services.keyValues.get(test.fullTitle());
147
- services.setContext(null);
148
-
149
- client.addTestRun(STATUS.PASSED, {
150
- ...stripExampleFromTitle(title),
151
- rid: id,
152
- suite_title: test.parent && test.parent.title,
153
- message: testObj.message,
154
- time: getDuration(test),
155
- steps: global.testomatioDataStore.steps.join('\n') || null,
156
- test_id: getTestomatIdFromTestTitle(`${title} ${tags?.join(' ')}`),
157
- logs,
158
- manuallyAttachedArtifacts,
159
- meta: keyValues,
62
+ let hookSteps = [];
63
+ let suiteHookRunning = false;
64
+ event.dispatcher.on(event.suite.before, suite => {
65
+ suiteHookRunning = true;
66
+ hookSteps = [];
67
+ global.testomatioDataStore.steps = [];
68
+ index_js_1.services.setContext(suite.fullTitle());
160
69
  });
161
- // output.stop();
162
- });
163
-
164
- event.dispatcher.on(event.test.failed, (test, err) => {
165
- error = err;
166
- });
167
-
168
- event.dispatcher.on(event.hook.failed, (suite, err) => {
169
- error = err;
170
-
171
- if (!suite) return;
172
- if (!suite.tests) return;
173
- for (const test of suite.tests) {
174
- const { id, tags, title } = test;
175
- failedTests.push(id || title);
176
- const testId = getTestomatIdFromTestTitle(`${title} ${tags?.join(' ')}`);
177
-
178
- client.addTestRun(STATUS.FAILED, {
179
- rid: id,
180
- ...stripExampleFromTitle(title),
181
- suite_title: suite.title,
182
- test_id: testId,
183
- error,
184
- time: 0,
185
- });
186
- }
187
- // output.stop();
188
- });
189
-
190
- event.dispatcher.on(event.test.after, test => {
191
- if (test.state && test.state !== STATUS.FAILED) return;
192
- if (test.err) error = test.err;
193
- const { id, tags, title, artifacts } = test;
194
- failedTests.push(id || title);
195
- const testObj = getTestAndMessage(title);
196
-
197
- const files = [];
198
- if (artifacts.screenshot) files.push({ path: artifacts.screenshot, type: 'image/png' });
199
- // todo: video must be uploaded later....
200
-
201
- const logs = getTestLogs(test);
202
- const manuallyAttachedArtifacts = services.artifacts.get(test.fullTitle());
203
- const keyValues = services.keyValues.get(test.fullTitle());
204
- services.setContext(null);
205
-
206
- client.addTestRun(STATUS.FAILED, {
207
- ...stripExampleFromTitle(title),
208
- rid: id,
209
- test_id: getTestomatIdFromTestTitle(`${title} ${tags?.join(' ')}`),
210
- suite_title: test.parent && test.parent.title,
211
- error,
212
- message: testObj.message,
213
- time: getDuration(test),
214
- files,
215
- steps: global.testomatioDataStore?.steps?.join('\n') || null,
216
- logs,
217
- manuallyAttachedArtifacts,
218
- meta: keyValues,
70
+ event.dispatcher.on(event.suite.after, () => {
71
+ index_js_1.services.setContext(null);
219
72
  });
220
-
221
- debug('artifacts', artifacts);
222
-
223
- for (const aid in artifacts) {
224
- if (aid.startsWith('video')) videos.push({ rid: id, title, path: artifacts[aid], type: 'video/webm' });
225
- if (aid.startsWith('trace')) traces.push({ rid: id, title, path: artifacts[aid], type: 'application/zip' });
226
- }
227
-
228
- // output.stop();
229
- });
230
-
231
- event.dispatcher.on(event.test.skipped, test => {
232
- const { id, tags, title } = test;
233
- if (failedTests.includes(id || title)) return;
234
-
235
- const testObj = getTestAndMessage(title);
236
- client.addTestRun(STATUS.SKIPPED, {
237
- rid: id,
238
- ...stripExampleFromTitle(title),
239
- test_id: getTestomatIdFromTestTitle(`${title} ${tags?.join(' ')}`),
240
- suite_title: test.parent && test.parent.title,
241
- message: testObj.message,
242
- time: getDuration(test),
73
+ event.dispatcher.on(event.hook.started, () => {
74
+ // global.testomatioDataStore.steps = [];
243
75
  });
244
- // output.stop();
245
- });
246
-
247
- event.dispatcher.on(event.step.started, step => {
248
- stepShift = 0;
249
- step.started = true;
250
- stepStart = new Date();
251
- });
252
-
253
- event.dispatcher.on(event.step.finished, step => {
254
- if (!step.started) return;
255
- let processingStep = step;
256
- const metaSteps = [];
257
- while (processingStep.metaStep) {
258
- metaSteps.unshift(processingStep.metaStep);
259
- processingStep = processingStep.metaStep;
260
- }
261
- const shift = metaSteps.length;
262
-
263
- for (let i = 0; i < Math.max(currentMetaStep.length, metaSteps.length); i++) {
264
- if (currentMetaStep[i] !== metaSteps[i]) {
265
- stepShift = 2 * i;
266
- // eslint-disable-next-line no-continue
267
- if (!metaSteps[i]) continue;
268
- if (metaSteps[i].isBDD()) {
269
- // output.push(repeat(stepShift) + chalk.bold(metaSteps[i].toString()) + metaSteps[i].comment);
270
- global.testomatioDataStore?.steps?.push(
271
- repeat(stepShift) + chalk.bold(metaSteps[i].toString()) + metaSteps[i].comment,
272
- );
273
- } else {
274
- // output.push(repeat(stepShift) + chalk.green.bold(metaSteps[i].toString()));
275
- global.testomatioDataStore?.steps?.push(repeat(stepShift) + chalk.green.bold(metaSteps[i].toString()));
76
+ event.dispatcher.on(event.hook.passed, () => {
77
+ if (suiteHookRunning) {
78
+ hookSteps.push(...global.testomatioDataStore.steps);
79
+ index_js_1.services.setContext(null);
276
80
  }
277
- }
278
- }
279
- currentMetaStep = metaSteps;
280
- stepShift = 2 * shift;
281
-
282
- const durationMs = +new Date() - +stepStart;
283
- let duration = '';
284
- if (durationMs) {
285
- duration = repeat(1) + chalk.grey(`(${durationMs}ms)`);
286
- }
287
-
288
- if (step.status === STATUS.FAILED) {
289
- // output.push(repeat(stepShift) + chalk.red(step.toString()) + duration);
290
- global.testomatioDataStore?.steps?.push(repeat(stepShift) + chalk.red(step.toString()) + duration);
291
- } else {
292
- // output.push(repeat(stepShift) + step.toString() + duration);
293
- global.testomatioDataStore?.steps?.push(repeat(stepShift) + step.toString() + duration);
294
- }
295
- });
296
-
297
- event.dispatcher.on(event.step.comment, step => {
298
- // output.push(chalk.cyan.bold(step.toString()));
299
- global.testomatioDataStore?.steps?.push(chalk.cyan.bold(step.toString()));
300
- });
81
+ });
82
+ event.dispatcher.on(event.hook.failed, () => {
83
+ if (suiteHookRunning) {
84
+ hookSteps.push(...global.testomatioDataStore.steps);
85
+ index_js_1.services.setContext(null);
86
+ }
87
+ });
88
+ event.dispatcher.on(event.test.before, test => {
89
+ suiteHookRunning = false;
90
+ global.testomatioDataStore.steps = [];
91
+ recorder.add(() => {
92
+ currentMetaStep = [];
93
+ // output.reset();
94
+ // output.start();
95
+ stepShift = 0;
96
+ });
97
+ if (!global.testomatioDataStore)
98
+ global.testomatioDataStore = {};
99
+ // reset steps
100
+ global.testomatioDataStore.steps = [];
101
+ index_js_1.services.setContext(test.fullTitle());
102
+ });
103
+ event.dispatcher.on(event.test.started, test => {
104
+ index_js_1.services.setContext(test.fullTitle());
105
+ testTimeMap[test.id] = Date.now();
106
+ // start logging
107
+ });
108
+ event.dispatcher.on(event.all.result, async () => {
109
+ debug('waiting for all tests to be reported');
110
+ // all tests were reported and we can upload videos
111
+ await Promise.all(reportTestPromises);
112
+ if (fileUploader_js_1.upload.isArtifactsEnabled()) {
113
+ await uploadAttachments(client, videos, '🎞️ Uploading', 'video');
114
+ await uploadAttachments(client, traces, '📁 Uploading', 'trace');
115
+ }
116
+ const status = failedTests.length === 0 ? constants_js_1.STATUS.PASSED : constants_js_1.STATUS.FAILED;
117
+ // @ts-ignore
118
+ client.updateRunStatus(status);
119
+ });
120
+ event.dispatcher.on(event.test.passed, test => {
121
+ const { id, tags, title } = test;
122
+ if (id && failedTests.includes(id)) {
123
+ failedTests = failedTests.filter(failed => id !== failed);
124
+ }
125
+ const testObj = getTestAndMessage(title);
126
+ const logs = getTestLogs(test);
127
+ const manuallyAttachedArtifacts = index_js_1.services.artifacts.get(test.fullTitle());
128
+ const keyValues = index_js_1.services.keyValues.get(test.fullTitle());
129
+ index_js_1.services.setContext(null);
130
+ client.addTestRun(constants_js_1.STATUS.PASSED, {
131
+ ...stripExampleFromTitle(title),
132
+ rid: id,
133
+ suite_title: test.parent && test.parent.title,
134
+ message: testObj.message,
135
+ time: getDuration(test),
136
+ steps: global.testomatioDataStore.steps.join('\n') || null,
137
+ test_id: (0, utils_js_1.getTestomatIdFromTestTitle)(`${title} ${tags?.join(' ')}`),
138
+ logs,
139
+ manuallyAttachedArtifacts,
140
+ meta: keyValues,
141
+ });
142
+ // output.stop();
143
+ });
144
+ event.dispatcher.on(event.test.failed, (test, err) => {
145
+ error = err;
146
+ });
147
+ event.dispatcher.on(event.hook.failed, (suite, err) => {
148
+ error = err;
149
+ if (!suite)
150
+ return;
151
+ if (!suite.tests)
152
+ return;
153
+ for (const test of suite.tests) {
154
+ const { id, tags, title } = test;
155
+ failedTests.push(id || title);
156
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(`${title} ${tags?.join(' ')}`);
157
+ client.addTestRun(constants_js_1.STATUS.FAILED, {
158
+ rid: id,
159
+ ...stripExampleFromTitle(title),
160
+ suite_title: suite.title,
161
+ test_id: testId,
162
+ error,
163
+ time: 0,
164
+ });
165
+ }
166
+ // output.stop();
167
+ });
168
+ event.dispatcher.on(event.test.after, test => {
169
+ if (test.state && test.state !== constants_js_1.STATUS.FAILED)
170
+ return;
171
+ if (test.err)
172
+ error = test.err;
173
+ const { id, tags, title, artifacts } = test;
174
+ failedTests.push(id || title);
175
+ const testObj = getTestAndMessage(title);
176
+ const files = [];
177
+ if (artifacts.screenshot)
178
+ files.push({ path: artifacts.screenshot, type: 'image/png' });
179
+ // todo: video must be uploaded later....
180
+ const logs = getTestLogs(test);
181
+ const manuallyAttachedArtifacts = index_js_1.services.artifacts.get(test.fullTitle());
182
+ const keyValues = index_js_1.services.keyValues.get(test.fullTitle());
183
+ index_js_1.services.setContext(null);
184
+ client.addTestRun(constants_js_1.STATUS.FAILED, {
185
+ ...stripExampleFromTitle(title),
186
+ rid: id,
187
+ test_id: (0, utils_js_1.getTestomatIdFromTestTitle)(`${title} ${tags?.join(' ')}`),
188
+ suite_title: test.parent && test.parent.title,
189
+ error,
190
+ message: testObj.message,
191
+ time: getDuration(test),
192
+ files,
193
+ steps: global.testomatioDataStore?.steps?.join('\n') || null,
194
+ logs,
195
+ manuallyAttachedArtifacts,
196
+ meta: keyValues,
197
+ });
198
+ debug('artifacts', artifacts);
199
+ for (const aid in artifacts) {
200
+ if (aid.startsWith('video'))
201
+ videos.push({ rid: id, title, path: artifacts[aid], type: 'video/webm' });
202
+ if (aid.startsWith('trace'))
203
+ traces.push({ rid: id, title, path: artifacts[aid], type: 'application/zip' });
204
+ }
205
+ // output.stop();
206
+ });
207
+ event.dispatcher.on(event.test.skipped, test => {
208
+ const { id, tags, title } = test;
209
+ if (failedTests.includes(id || title))
210
+ return;
211
+ const testObj = getTestAndMessage(title);
212
+ client.addTestRun(constants_js_1.STATUS.SKIPPED, {
213
+ rid: id,
214
+ ...stripExampleFromTitle(title),
215
+ test_id: (0, utils_js_1.getTestomatIdFromTestTitle)(`${title} ${tags?.join(' ')}`),
216
+ suite_title: test.parent && test.parent.title,
217
+ message: testObj.message,
218
+ time: getDuration(test),
219
+ });
220
+ // output.stop();
221
+ });
222
+ event.dispatcher.on(event.step.started, step => {
223
+ stepShift = 0;
224
+ step.started = true;
225
+ stepStart = new Date();
226
+ });
227
+ event.dispatcher.on(event.step.finished, step => {
228
+ if (!step.started)
229
+ return;
230
+ let processingStep = step;
231
+ const metaSteps = [];
232
+ while (processingStep.metaStep) {
233
+ metaSteps.unshift(processingStep.metaStep);
234
+ processingStep = processingStep.metaStep;
235
+ }
236
+ const shift = metaSteps.length;
237
+ for (let i = 0; i < Math.max(currentMetaStep.length, metaSteps.length); i++) {
238
+ if (currentMetaStep[i] !== metaSteps[i]) {
239
+ stepShift = 2 * i;
240
+ // eslint-disable-next-line no-continue
241
+ if (!metaSteps[i])
242
+ continue;
243
+ if (metaSteps[i].isBDD()) {
244
+ // output.push(repeat(stepShift) + pc.bold(metaSteps[i].toString()) + metaSteps[i].comment);
245
+ global.testomatioDataStore?.steps?.push(repeat(stepShift) + picocolors_1.default.bold(metaSteps[i].toString()) + metaSteps[i].comment);
246
+ }
247
+ else {
248
+ // output.push(repeat(stepShift) + pc.green.bold(metaSteps[i].toString()));
249
+ global.testomatioDataStore?.steps?.push(repeat(stepShift) + picocolors_1.default.green(picocolors_1.default.bold(metaSteps[i].toString())));
250
+ }
251
+ }
252
+ }
253
+ currentMetaStep = metaSteps;
254
+ stepShift = 2 * shift;
255
+ const durationMs = +new Date() - +stepStart;
256
+ let duration = '';
257
+ if (durationMs) {
258
+ duration = repeat(1) + picocolors_1.default.gray(`(${durationMs}ms)`);
259
+ }
260
+ if (step.status === constants_js_1.STATUS.FAILED) {
261
+ // output.push(repeat(stepShift) + pc.red(step.toString()) + duration);
262
+ global.testomatioDataStore?.steps?.push(repeat(stepShift) + picocolors_1.default.red(step.toString()) + duration);
263
+ }
264
+ else {
265
+ // output.push(repeat(stepShift) + step.toString() + duration);
266
+ global.testomatioDataStore?.steps?.push(repeat(stepShift) + step.toString() + duration);
267
+ }
268
+ });
269
+ event.dispatcher.on(event.step.comment, step => {
270
+ // output.push(pc.cyan.bold(step.toString()));
271
+ global.testomatioDataStore?.steps?.push(picocolors_1.default.cyan(picocolors_1.default.bold(step.toString())));
272
+ });
301
273
  }
302
-
303
274
  async function uploadAttachments(client, attachments, messagePrefix, attachmentType) {
304
- if (!attachments?.length) return;
305
-
306
- if (client.uploader.isEnabled) console.log(APP_PREFIX, `Attachments: ${messagePrefix} ${attachments.length} ${attachmentType} ...`);
307
-
308
- const promises = attachments.map(async attachment => {
309
- const { rid, title, path, type } = attachment;
310
- const file = { path, type, title };
311
-
312
- // we are storing file if upload is disabled
313
- if (!client.uploader.isEnabled) return client.uploader.storeUploadedFile(path, client.runId, rid, false);
314
-
315
- return client.addTestRun(undefined, {
316
- ...stripExampleFromTitle(title),
317
- rid,
318
- files: [file],
275
+ if (!attachments?.length)
276
+ return;
277
+ console.log(constants_js_1.APP_PREFIX, `Attachments: ${messagePrefix} ${attachments.length} ${attachmentType} ...`);
278
+ const promises = attachments.map(async (attachment) => {
279
+ const { rid, title, path, type } = attachment;
280
+ const file = { path, type, title };
281
+ return client.addTestRun(undefined, {
282
+ ...stripExampleFromTitle(title),
283
+ rid,
284
+ files: [file],
285
+ });
319
286
  });
320
- });
321
-
322
- await Promise.all(promises);
287
+ await Promise.all(promises);
323
288
  }
324
-
325
289
  function getTestAndMessage(title) {
326
- const testObj = { message: '' };
327
- const testArr = title.split(/\s(\|\s\{.*?\})/);
328
- testObj.title = testArr[0];
329
-
330
- return testObj;
290
+ const testObj = { message: '' };
291
+ const testArr = title.split(/\s(\|\s\{.*?\})/);
292
+ testObj.title = testArr[0];
293
+ return testObj;
331
294
  }
332
-
333
295
  function stripExampleFromTitle(title) {
334
- const res = title.match(DATA_REGEXP);
335
- if (!res) return { title, example: null };
336
-
337
- const example = JSON.parse(res[1]);
338
- title = title.replace(DATA_REGEXP, '').trim();
339
-
340
- return { title, example };
296
+ const res = title.match(DATA_REGEXP);
297
+ if (!res)
298
+ return { title, example: null };
299
+ const example = JSON.parse(res[1]);
300
+ title = title.replace(DATA_REGEXP, '').trim();
301
+ return { title, example };
341
302
  }
342
-
343
303
  function repeat(num) {
344
- return ''.padStart(num, ' ');
304
+ return ''.padStart(num, ' ');
345
305
  }
346
-
347
306
  // TODO: think about moving to some common utils
348
307
  function getTestLogs(test) {
349
- const suiteLogsArr = services.logger.getLogs(test.parent.fullTitle());
350
- const suiteLogs = suiteLogsArr ? suiteLogsArr.join('\n').trim() : '';
351
- const testLogsArr = services.logger.getLogs(test.fullTitle());
352
- const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
353
-
354
- let logs = '';
355
- if (suiteLogs) {
356
- logs += `${chalk.bold('\t--- BeforeSuite ---')}\n${suiteLogs}`;
357
- }
358
- if (testLogs) {
359
- logs += `\n${chalk.bold('\t--- Test ---')}\n${testLogs}`;
360
- }
361
- return logs;
308
+ const suiteLogsArr = index_js_1.services.logger.getLogs(test.parent.fullTitle());
309
+ const suiteLogs = suiteLogsArr ? suiteLogsArr.join('\n').trim() : '';
310
+ const testLogsArr = index_js_1.services.logger.getLogs(test.fullTitle());
311
+ const testLogs = testLogsArr ? testLogsArr.join('\n').trim() : '';
312
+ let logs = '';
313
+ if (suiteLogs) {
314
+ logs += `${picocolors_1.default.bold('\t--- BeforeSuite ---')}\n${suiteLogs}`;
315
+ }
316
+ if (testLogs) {
317
+ logs += `\n${picocolors_1.default.bold('\t--- Test ---')}\n${testLogs}`;
318
+ }
319
+ return logs;
362
320
  }
363
321
 
364
- module.exports = CodeceptReporter;
322
+ module.exports.CodeceptReporter = CodeceptReporter;