@testomatio/reporter 2.0.1-beta.3 → 2.0.1-beta.5-timestamp

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