@testomatio/reporter 2.0.1-beta.4 → 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,254 +0,0 @@
1
- import pc from 'picocolors';
2
- import crypto from 'crypto';
3
- import os from 'os';
4
- import path from 'path';
5
- import { v4 as uuidv4 } from 'uuid';
6
- import fs from 'fs';
7
- import { APP_PREFIX, STATUS as Status, TESTOMAT_TMP_STORAGE_DIR } from '../constants.js';
8
- import TestomatioClient from '../client.js';
9
- import { getTestomatIdFromTestTitle, fileSystem } from '../utils/utils.js';
10
- import { services } from '../services/index.js';
11
- import { dataStorage } from '../data-storage.js';
12
-
13
- const reportTestPromises = [];
14
-
15
- class PlaywrightReporter {
16
- constructor(config = {}) {
17
- this.client = new TestomatioClient({ apiKey: config?.apiKey });
18
-
19
- this.uploads = [];
20
- }
21
-
22
- onBegin(config, suite) {
23
- // clean data storage
24
- fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
25
- if (!this.client) return;
26
- this.suite = suite;
27
- this.config = config;
28
- this.client.createRun();
29
- }
30
-
31
- onTestBegin(testInfo) {
32
- const fullTestTitle = getTestContextName(testInfo);
33
- dataStorage.setContext(fullTestTitle);
34
- }
35
-
36
- onTestEnd(test, result) {
37
- // test.parent.project().__projectId
38
-
39
- if (!this.client) return;
40
-
41
- const { title } = test;
42
- const { error, duration } = result;
43
- const suite_title = test.parent ? test.parent?.title : path.basename(test?.location?.file);
44
-
45
- const steps = [];
46
- for (const step of result.steps) {
47
- const appendedStep = appendStep(step);
48
- if (appendedStep) {
49
- steps.push(appendedStep);
50
- }
51
- }
52
-
53
- const fullTestTitle = getTestContextName(test);
54
- let logs = '';
55
- if (result.stderr.length || result.stdout.length) {
56
- logs = `\n\n${pc.bold('Logs:')}\n${pc.red(result.stderr.join(''))}\n${result.stdout.join('')}`;
57
- }
58
- const manuallyAttachedArtifacts = services.artifacts.get(fullTestTitle);
59
- const testMeta = services.keyValues.get(fullTestTitle);
60
- const rid = test.id || test.testId || uuidv4();
61
-
62
- /**
63
- * @type {{
64
- * browser?: string,
65
- * dependencies: string[],
66
- * isMobile?: boolean
67
- * metadata: Record<string, any>,
68
- * name: string,
69
- * }}
70
- */
71
- const project = {
72
- browser: test.parent.project().use.defaultBrowserType,
73
- dependencies: test.parent.project().dependencies,
74
- isMobile: test.parent.project().use.isMobile,
75
- metadata: test.parent.project().metadata,
76
- name: test.parent.project().name,
77
- };
78
-
79
- let status = result.status;
80
- // process test.fail() annotation
81
- if (test.expectedStatus === 'failed') {
82
- // actual status = expected
83
- if (result.status === 'failed') status = 'passed';
84
- // actual status != expected
85
- if (result.status === 'passed') status = 'failed';
86
- }
87
-
88
- const reportTestPromise = this.client.addTestRun(checkStatus(status), {
89
- rid: `${rid}-${project.name}`,
90
- error,
91
- test_id: getTestomatIdFromTestTitle(`${title} ${test.tags?.join(' ')}`),
92
- suite_title,
93
- title,
94
- steps: steps.length ? steps : undefined,
95
- time: duration,
96
- logs,
97
- manuallyAttachedArtifacts,
98
- meta: {
99
- browser: project.browser,
100
- isMobile: project.isMobile,
101
- project: project.name,
102
- projectDependencies: project.dependencies?.length ? project.dependencies : null,
103
- ...testMeta,
104
- ...project.metadata, // metadata has any type (in playwright), but we will stringify it in client.js
105
- ...test.annotations?.reduce((acc, annotation) => {
106
- acc[annotation.type] = annotation.description;
107
- return acc;
108
- }, {}),
109
- },
110
- file: test.location?.file,
111
- });
112
-
113
- this.uploads.push({
114
- rid: `${rid}-${project.name}`,
115
- title: test.title,
116
- files: result.attachments.filter(a => a.body || a.path),
117
- file: test.location?.file,
118
- });
119
- // remove empty uploads
120
- this.uploads = this.uploads.filter(anUpload => anUpload.files.length);
121
-
122
- reportTestPromises.push(reportTestPromise);
123
- }
124
-
125
- #getArtifactPath(artifact) {
126
- if (artifact.path) {
127
- if (path.isAbsolute(artifact.path)) return artifact.path;
128
-
129
- return path.join(this.config.outputDir || this.config.projects[0].outputDir, artifact.path);
130
- }
131
-
132
- if (artifact.body) {
133
- let filePath = generateTmpFilepath(artifact.name);
134
-
135
- const extension = artifact.contentType?.split('/')[1]?.replace('jpeg', 'jpg');
136
- if (extension) filePath += `.${extension}`;
137
-
138
- fs.writeFileSync(filePath, artifact.body);
139
- return filePath;
140
- }
141
-
142
- return null;
143
- }
144
-
145
- async onEnd(result) {
146
- if (!this.client) return;
147
-
148
- await Promise.all(reportTestPromises);
149
-
150
- if (this.uploads.length) {
151
- if (this.client.uploader.isEnabled) console.log(APP_PREFIX, `🎞️ Uploading ${this.uploads.length} files...`);
152
-
153
- const promises = [];
154
-
155
- // ? possible move to addTestRun (needs investigation if files are ready)
156
- for (const upload of this.uploads) {
157
- const { rid, file, title } = upload;
158
-
159
- const files = upload.files.map(attachment => ({
160
- path: this.#getArtifactPath(attachment),
161
- title,
162
- type: attachment.contentType,
163
- }));
164
-
165
- if (!this.client.uploader.isEnabled) {
166
- files.forEach(f => this.client.uploader.storeUploadedFile(f, this.client.runId, rid, false));
167
- continue;
168
- }
169
-
170
- promises.push(
171
- this.client.addTestRun(undefined, {
172
- rid,
173
- title,
174
- files,
175
- file,
176
- }),
177
- );
178
- }
179
- await Promise.all(promises);
180
- }
181
-
182
- await this.client.updateRunStatus(checkStatus(result.status));
183
- }
184
- }
185
-
186
- function checkStatus(status) {
187
- return (
188
- {
189
- skipped: Status.SKIPPED,
190
- timedOut: Status.FAILED,
191
- passed: Status.PASSED,
192
- }[status] || Status.FAILED
193
- );
194
- }
195
-
196
- function appendStep(step, shift = 0) {
197
- // nesting too deep, ignore those steps
198
- if (shift >= 10) return;
199
-
200
- let newCategory = step.category;
201
- switch (newCategory) {
202
- case 'test.step':
203
- newCategory = 'user';
204
- break;
205
- case 'hook':
206
- newCategory = 'hook';
207
- break;
208
- case 'attach':
209
- return null; // Skip steps with category 'attach'
210
- default:
211
- newCategory = 'framework';
212
- }
213
-
214
- const formattedSteps = [];
215
- for (const child of step.steps || []) {
216
- const appendedChild = appendStep(child, shift + 2);
217
- if (appendedChild) {
218
- formattedSteps.push(appendedChild);
219
- }
220
- }
221
-
222
- const resultStep = {
223
- category: newCategory,
224
- title: step.title,
225
- duration: step.duration,
226
- };
227
-
228
- if (formattedSteps.length) {
229
- resultStep.steps = formattedSteps.filter(s => !!s);
230
- }
231
-
232
- if (step.error !== undefined) {
233
- resultStep.error = step.error;
234
- }
235
-
236
- return resultStep;
237
- }
238
-
239
- function generateTmpFilepath(filename = '') {
240
- filename = filename || `tmp.${crypto.randomBytes(16).toString('hex')}`;
241
- const tmpdir = os.tmpdir();
242
- return path.join(tmpdir, filename);
243
- }
244
-
245
- /**
246
- * Returns filename + test title
247
- * @param {*} test - testInfo object from Playwright
248
- * @returns
249
- */
250
- function getTestContextName(test) {
251
- return `${test._requireFile || ''}_${test.title}`;
252
- }
253
-
254
- export default PlaywrightReporter;
@@ -1,183 +0,0 @@
1
- import pc from 'picocolors';
2
- import { Client as TestomatioClient } from '../client.js';
3
- import { STATUS } from '../constants.js';
4
- import { getTestomatIdFromTestTitle } from '../utils/utils.js';
5
- import createDebugMessages from 'debug';
6
-
7
- const debug = createDebugMessages('@testomatio/reporter:adapter-jest');
8
-
9
- /**
10
- * @typedef {import('../../types/types.js').VitestTest} VitestTest
11
- * @typedef {import('../../types/types.js').VitestTestFile} VitestTestFile
12
- * @typedef {import('../../types/types.js').VitestSuite} VitestSuite
13
- * @typedef {import('../../types/types.js').VitestTestLogs} VitestTestLogs
14
- * @typedef {import('../../types/vitest.types.js').ErrorWithDiff} ErrorWithDiff
15
- * @typedef {typeof import('../constants.js').STATUS} STATUS
16
- * @typedef {import('../../types/types.js').TestData} TestData
17
- */
18
-
19
- class VitestReporter {
20
- constructor(config = {}) {
21
- this.client = new TestomatioClient({ apiKey: config?.apiKey });
22
- /**
23
- * @type {(TestData & {status: string})[]} tests
24
- */
25
- this.tests = [];
26
- }
27
-
28
- // on run start
29
- onInit() {
30
- this.client.createRun();
31
- }
32
-
33
- /**
34
- * @param {VitestTestFile[] | undefined} files // array with results;
35
- * @param {unknown[] | undefined} errors // errors does not contain errors from tests; probably its testrunner errors
36
- */
37
- async onFinished(files, errors) {
38
- if (!files || !files.length) console.info('No tests executed');
39
-
40
- files.forEach(file => {
41
- // task could be test or suite
42
- file.tasks.forEach(taskOrSuite => {
43
- if (taskOrSuite.type === 'test') {
44
- const test = taskOrSuite;
45
- this.tests.push(this.#getDataFromTest(test));
46
- } else if (taskOrSuite.type === 'suite') {
47
- const suite = taskOrSuite;
48
- this.#processTasksOfSuite(suite);
49
- } else {
50
- throw new Error('Unprocessed case. Unknown task type');
51
- }
52
- });
53
- });
54
-
55
- debug(this.tests.length, 'tests collected');
56
-
57
- // send tests to Testomat.io
58
- for (const test of this.tests) {
59
- await this.client.addTestRun(test.status, test);
60
- }
61
-
62
- console.log('finished');
63
- if (errors.length) console.error('Vitest adapter errors:', errors);
64
-
65
- await this.client.updateRunStatus(getRunStatusFromResults(files));
66
- }
67
-
68
- /* non-used listeners
69
- onUserConsoleLog(log) {}
70
- onPathsCollected(paths) {} // paths array to files with tests
71
- onCollected(files) {} // files array with tests (but without results)
72
- onTaskUpdate(packs) {} // some updates come here on afterAll block execution
73
- onTestRemoved(trigger) {}
74
- onWatcherStart(files, errors) {}
75
- onWatcherRerun(files, trigger) {}
76
- onServerRestart(reason) {}
77
- onProcessTimeout() {}
78
- */
79
-
80
- /**
81
- * Recursively gets all tasks from suite and pushes them to "tests" array
82
- *
83
- * @param {VitestSuite} suite
84
- */
85
- #processTasksOfSuite(suite) {
86
- suite.tasks.forEach(taskOrSuite => {
87
- if (taskOrSuite.type === 'test') {
88
- const test = taskOrSuite;
89
- this.tests.push(this.#getDataFromTest(test));
90
- } else if (taskOrSuite.type === 'suite') {
91
- const theSuite = taskOrSuite;
92
- this.#processTasksOfSuite(theSuite);
93
- } else {
94
- throw new Error('Unprocessed case. Unknown task type');
95
- }
96
- });
97
- }
98
-
99
- /**
100
- * Processes task and returns test data ready to be sent to Testomat.io
101
- *
102
- * @param {VitestTest} test
103
- *
104
- * @returns {TestData & {status: string}}
105
- */
106
- #getDataFromTest(test) {
107
- return {
108
- error: test.result?.errors ? test.result.errors[0] : undefined,
109
- file: test.file.name,
110
- logs: test.logs ? transformLogsToString(test.logs) : '',
111
- meta: test.meta,
112
- status: getTestStatus(test),
113
- suite_title: test.suite.name || test.file?.name,
114
- test_id: getTestomatIdFromTestTitle(test.name),
115
- time: test.result?.duration || 0,
116
- title: test.name,
117
- // testomatio functions (artifacts, logs, steps, meta) are not supported
118
- };
119
- }
120
- }
121
-
122
- /**
123
- * Returns run status based on test results
124
- *
125
- * @param {VitestTestFile[]} files
126
- * @returns {'passed' | 'failed' | 'finished'}
127
- */
128
- function getRunStatusFromResults(files) {
129
- /**
130
- * @type {'passed' | 'failed' | 'finished'}
131
- */
132
- let status = 'finished'; // default status (if no failed or passed tests)
133
-
134
- files.forEach(file => {
135
- // search for failed tests
136
- file.tasks.forEach(taskOrSuite => {
137
- if (taskOrSuite.result?.state === 'fail') {
138
- status = 'failed'; // set status to failed if any test failed
139
- }
140
- });
141
-
142
- // if there are no failed tests > search for passed tests
143
- if (status !== 'failed') {
144
- file.tasks.forEach(taskOrSuite => {
145
- if (taskOrSuite.result?.state === 'pass') {
146
- status = 'passed'; // set status to passed if any test passed (and there are no failed tests)
147
- }
148
- });
149
- }
150
- });
151
-
152
- return status;
153
- }
154
-
155
- /**
156
- * Returns test status in Testomat.io format
157
- *
158
- * @param {VitestTest} test
159
- * @returns 'passed' | 'failed' | 'skipped'
160
- */
161
- function getTestStatus(test) {
162
- if (test.result?.state === 'fail') return STATUS.FAILED;
163
- if (test.result?.state === 'pass') return STATUS.PASSED;
164
- if (!test.result && test.mode === 'skip') return STATUS.SKIPPED;
165
- console.error(pc.red('Unprocessed case for defining test status. Contact dev team. Test:'), test);
166
- }
167
-
168
- /**
169
- * @param {VitestTestLogs[]} logs
170
- * @returns string
171
- */
172
- function transformLogsToString(logs) {
173
- if (!logs) return '';
174
- let logsStr = '';
175
- logs.forEach(log => {
176
- if (log.type === 'stdout') logsStr += `${log.content}\n`;
177
- if (log.type === 'stderr') logsStr += `${pc.red(log.content)}\n`;
178
- });
179
- return logsStr;
180
- }
181
-
182
- export default VitestReporter;
183
- export { VitestReporter };
@@ -1,142 +0,0 @@
1
- import { default as WDIOReporter, RunnerStats } from '@wdio/reporter';
2
- import TestomatClient from '../client.js';
3
- import { getTestomatIdFromTestTitle, fileSystem } from '../utils/utils.js';
4
- import { services } from '../services/index.js';
5
- import { TESTOMAT_TMP_STORAGE_DIR } from '../constants.js';
6
-
7
- class WebdriverReporter extends WDIOReporter {
8
- constructor(options) {
9
- super(options);
10
-
11
- this.client = new TestomatClient({ apiKey: options?.apiKey });
12
- options = Object.assign(options, { stdout: true });
13
-
14
- this._addTestPromises = [];
15
-
16
- this._isSynchronising = false;
17
- // NOTE: new functionality; may break everything
18
- this.client.createRun();
19
- }
20
-
21
- get isSynchronised() {
22
- return this._isSynchronising === false;
23
- }
24
-
25
- /**
26
- *
27
- * @param {RunnerStats} runData
28
- */
29
- async onRunnerEnd(runData) {
30
- this._isSynchronising = true;
31
-
32
- await Promise.all(this._addTestPromises);
33
-
34
- this._isSynchronising = false;
35
-
36
- // NOTE: new functionality; may break everything
37
- // also this may require additional status mapping
38
- await this.client.updateRunStatus(runData.failures ? 'failed' : 'passed');
39
- }
40
-
41
- onRunnerStart() {
42
- // clear dir with artifacts/logs
43
- //
44
- fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
45
- }
46
-
47
- onTestStart(test) {
48
- services.setContext(test.fullTitle);
49
- }
50
-
51
- onTestEnd(test) {
52
- test.suite = test.parent;
53
- const logs = getTestLogs(test.fullTitle);
54
- // TODO: FIX: artifacts for some reason leads to empty report on Testomat.io
55
- // const artifacts = services.artifacts.get(test.fullTitle);
56
- // const keyValues = services.keyValues.get(test.fullTitle);
57
- test.logs = logs;
58
- // test.artifacts = artifacts;
59
- // test.meta = keyValues;
60
-
61
- this._addTestPromises.push(this.addTest(test));
62
- }
63
-
64
- // wdio-cucumber does not trigger onTestEnd hook, thus, using this one
65
- onSuiteEnd(scerario) {
66
- if (scerario.type === 'scenario') {
67
- this._addTestPromises.push(this.addBddScenario(scerario));
68
- }
69
- }
70
-
71
- async addTest(test) {
72
- if (!this.client) return;
73
-
74
- const { title, _duration: duration, state, error, output } = test;
75
-
76
- const testId = getTestomatIdFromTestTitle(title);
77
-
78
- const screenshotEndpoint = '/session/:sessionId/screenshot';
79
- const screenshotsBuffers = output
80
- .filter(el => el.endpoint === screenshotEndpoint && el.result && el.result.value)
81
- .map(el => Buffer.from(el.result.value, 'base64'));
82
-
83
- await this.client.addTestRun(state, {
84
- rid: test.uid || '',
85
- manuallyAttachedArtifacts: test.artifacts,
86
- error,
87
- logs: test.logs,
88
- meta: test.meta,
89
- title,
90
- test_id: testId,
91
- time: duration,
92
- filesBuffers: screenshotsBuffers,
93
- });
94
- }
95
-
96
- /**
97
- * @param {import('../../types/types.js').WebdriverIOScenario} scenario
98
- */
99
- addBddScenario(scenario) {
100
- if (!this.client) return;
101
-
102
- const { title, _duration: duration } = scenario;
103
-
104
- const testId = getTestomatIdFromTestTitle(title || scenario.tags.map(tag => tag.name).join(' '));
105
-
106
- let scenarioState = scenario.tests.every(test => test.state === 'passed') ? 'passed' : 'failed';
107
- if (scenario.tests.every(test => test.state === 'skipped')) {
108
- scenarioState = 'skipped';
109
- }
110
- const errors = scenario.tests
111
- .filter(test => test.state === 'failed')
112
- .map(test => test.error?.stack)
113
- .filter(Boolean);
114
- const error = errors.join('\n');
115
-
116
- const tags = scenario.tags.map(tag => tag.name);
117
-
118
- return this.client.addTestRun(scenarioState, {
119
- error: error ? Error(error) : null,
120
- title,
121
- test_id: testId,
122
- time: duration,
123
- tags,
124
- file: scenario.file,
125
- // filesBuffers: screenshotsBuffers,
126
- });
127
- }
128
- }
129
-
130
- /**
131
- *
132
- * @param {*} fullTestTitle
133
- * @returns string
134
- */
135
- function getTestLogs(fullTestTitle) {
136
- const logsArr = services.logger.getLogs(fullTestTitle);
137
- // remove duplicates (for some reason, logs are duplicated several times)
138
- const logs = logsArr ? Array.from(new Set(logsArr)).join('\n').trim() : '';
139
- return logs;
140
- }
141
-
142
- export default WebdriverReporter;