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