@testomatio/reporter 1.6.0-beta-2-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 -84
  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 -216
  96. package/lib/bin/uploadArtifacts.js +0 -86
  97. package/lib/uploader.js +0 -312
@@ -1,122 +1,123 @@
1
- const chalk = require('chalk');
2
- const { TestomatioClient } = require('../client');
3
- const { STATUS } = require('../constants');
4
- const { getTestomatIdFromTestTitle } = require('../utils/utils');
5
- const debug = require('debug')('@testomatio/reporter:adapter:vitest');
6
-
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.VitestReporter = void 0;
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
+ const client_js_1 = require("../client.js");
9
+ const constants_js_1 = require("../constants.js");
10
+ const utils_js_1 = require("../utils/utils.js");
11
+ const debug_1 = __importDefault(require("debug"));
12
+ const debug = (0, debug_1.default)('@testomatio/reporter:adapter-jest');
7
13
  /**
8
14
  * @typedef {import('../../types').VitestTest} VitestTest
9
15
  * @typedef {import('../../types').VitestTestFile} VitestTestFile
10
16
  * @typedef {import('../../types').VitestSuite} VitestSuite
11
17
  * @typedef {import('../../types').VitestTestLogs} VitestTestLogs
12
18
  * @typedef {import('../../vitest.types').ErrorWithDiff} ErrorWithDiff
13
- * @typedef {typeof import('../constants').STATUS} STATUS
19
+ * @typedef {typeof import('../constants.js').STATUS} STATUS
14
20
  * @typedef {import('../../types').TestData} TestData
15
21
  */
16
-
17
22
  class VitestReporter {
18
- constructor(config = {}) {
19
- this.client = new TestomatioClient({ apiKey: config?.apiKey });
23
+ constructor(config = {}) {
24
+ this.client = new client_js_1.Client({ apiKey: config?.apiKey });
25
+ /**
26
+ * @type {(TestData & {status: string})[]} tests
27
+ */
28
+ this.tests = [];
29
+ }
30
+ // on run start
31
+ onInit() {
32
+ this.client.createRun();
33
+ }
20
34
  /**
21
- * @type {(TestData & {status: string})[]} tests
35
+ * @param {VitestTestFile[] | undefined} files // array with results;
36
+ * @param {unknown[] | undefined} errors // errors does not contain errors from tests; probably its testrunner errors
22
37
  */
23
- this.tests = [];
24
- }
25
-
26
- // on run start
27
- onInit() {
28
- this.client.createRun();
29
- }
30
-
31
- /**
32
- * @param {VitestTestFile[] | undefined} files // array with results;
33
- * @param {unknown[] | undefined} errors // errors does not contain errors from tests; probably its testrunner errors
34
- */
35
- async onFinished(files, errors) {
36
- if (!files || !files.length) console.info('No tests executed');
37
-
38
- files.forEach(file => {
39
- // task could be test or suite
40
- file.tasks.forEach(taskOrSuite => {
41
- if (taskOrSuite.type === 'test') {
42
- const test = taskOrSuite;
43
- this.tests.push(this.#getDataFromTest(test));
44
- } else if (taskOrSuite.type === 'suite') {
45
- const suite = taskOrSuite;
46
- this.#processTasksOfSuite(suite);
47
- } else {
48
- throw new Error('Unprocessed case. Unknown task type');
38
+ async onFinished(files, errors) {
39
+ if (!files || !files.length)
40
+ console.info('No tests executed');
41
+ files.forEach(file => {
42
+ // task could be test or suite
43
+ file.tasks.forEach(taskOrSuite => {
44
+ if (taskOrSuite.type === 'test') {
45
+ const test = taskOrSuite;
46
+ this.tests.push(this.#getDataFromTest(test));
47
+ }
48
+ else if (taskOrSuite.type === 'suite') {
49
+ const suite = taskOrSuite;
50
+ this.#processTasksOfSuite(suite);
51
+ }
52
+ else {
53
+ throw new Error('Unprocessed case. Unknown task type');
54
+ }
55
+ });
56
+ });
57
+ debug(this.tests.length, 'tests collected');
58
+ // send tests to Testomat.io
59
+ for (const test of this.tests) {
60
+ await this.client.addTestRun(test.status, test);
49
61
  }
50
- });
51
- });
52
-
53
- debug(this.tests.length, 'tests collected');
54
-
55
- // send tests to Testomat.io
56
- for (const test of this.tests) {
57
- await this.client.addTestRun(test.status, test);
62
+ console.log('finished');
63
+ if (errors.length)
64
+ console.error('Vitest adapter errors:', errors);
65
+ await this.client.updateRunStatus(getRunStatusFromResults(files));
66
+ }
67
+ /* non-used listeners
68
+ onUserConsoleLog(log) {}
69
+ onPathsCollected(paths) {} // paths array to files with tests
70
+ onCollected(files) {} // files array with tests (but without results)
71
+ onTaskUpdate(packs) {} // some updates come here on afterAll block execution
72
+ onTestRemoved(trigger) {}
73
+ onWatcherStart(files, errors) {}
74
+ onWatcherRerun(files, trigger) {}
75
+ onServerRestart(reason) {}
76
+ onProcessTimeout() {}
77
+ */
78
+ /**
79
+ * Recursively gets all tasks from suite and pushes them to "tests" array
80
+ *
81
+ * @param {VitestSuite} suite
82
+ */
83
+ #processTasksOfSuite(suite) {
84
+ suite.tasks.forEach(taskOrSuite => {
85
+ if (taskOrSuite.type === 'test') {
86
+ const test = taskOrSuite;
87
+ this.tests.push(this.#getDataFromTest(test));
88
+ }
89
+ else if (taskOrSuite.type === 'suite') {
90
+ const theSuite = taskOrSuite;
91
+ this.#processTasksOfSuite(theSuite);
92
+ }
93
+ else {
94
+ throw new Error('Unprocessed case. Unknown task type');
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * Processes task and returns test data ready to be sent to Testomat.io
100
+ *
101
+ * @param {VitestTest} test
102
+ *
103
+ * @returns {TestData & {status: string}}
104
+ */
105
+ #getDataFromTest(test) {
106
+ return {
107
+ error: test.result?.errors ? test.result.errors[0] : undefined,
108
+ file: test.file.name,
109
+ logs: test.logs ? transformLogsToString(test.logs) : '',
110
+ meta: test.meta,
111
+ status: getTestStatus(test),
112
+ suite_title: test.suite.name || test.file?.name,
113
+ test_id: (0, utils_js_1.getTestomatIdFromTestTitle)(test.name),
114
+ time: test.result?.duration || 0,
115
+ title: test.name,
116
+ // testomatio functions (artifacts, logs, steps, meta) are not supported
117
+ };
58
118
  }
59
-
60
- console.log('finished');
61
- if (errors.length) console.error('Vitest adapter errors:', errors);
62
-
63
- await this.client.updateRunStatus(getRunStatusFromResults(files));
64
- }
65
-
66
- /* non-used listeners
67
- onUserConsoleLog(log) {}
68
- onPathsCollected(paths) {} // paths array to files with tests
69
- onCollected(files) {} // files array with tests (but without results)
70
- onTaskUpdate(packs) {} // some updates come here on afterAll block execution
71
- onTestRemoved(trigger) {}
72
- onWatcherStart(files, errors) {}
73
- onWatcherRerun(files, trigger) {}
74
- onServerRestart(reason) {}
75
- onProcessTimeout() {}
76
- */
77
-
78
- /**
79
- * Recursively gets all tasks from suite and pushes them to "tests" array
80
- *
81
- * @param {VitestSuite} suite
82
- */
83
- #processTasksOfSuite(suite) {
84
- suite.tasks.forEach(taskOrSuite => {
85
- if (taskOrSuite.type === 'test') {
86
- const test = taskOrSuite;
87
- this.tests.push(this.#getDataFromTest(test));
88
- } else if (taskOrSuite.type === 'suite') {
89
- const theSuite = taskOrSuite;
90
- this.#processTasksOfSuite(theSuite);
91
- } else {
92
- throw new Error('Unprocessed case. Unknown task type');
93
- }
94
- });
95
- }
96
-
97
- /**
98
- * Processes task and returns test data ready to be sent to Testomat.io
99
- *
100
- * @param {VitestTest} test
101
- *
102
- * @returns {TestData & {status: string}}
103
- */
104
- #getDataFromTest(test) {
105
- return {
106
- error: test.result?.errors ? test.result.errors[0] : undefined,
107
- file: test.file.name,
108
- logs: test.logs ? transformLogsToString(test.logs) : '',
109
- meta: test.meta,
110
- status: getTestStatus(test),
111
- suite_title: test.suite.name || test.file?.name,
112
- test_id: getTestomatIdFromTestTitle(test.name),
113
- time: test.result?.duration || 0,
114
- title: test.name,
115
- // testomatio functions (artifacts, logs, steps, meta) are not supported
116
- };
117
- }
118
119
  }
119
-
120
+ exports.VitestReporter = VitestReporter;
120
121
  /**
121
122
  * Returns run status based on test results
122
123
  *
@@ -124,32 +125,28 @@ class VitestReporter {
124
125
  * @returns {'passed' | 'failed' | 'finished'}
125
126
  */
126
127
  function getRunStatusFromResults(files) {
127
- /**
128
- * @type {'passed' | 'failed' | 'finished'}
129
- */
130
- let status = 'finished'; // default status (if no failed or passed tests)
131
-
132
- files.forEach(file => {
133
- // search for failed tests
134
- file.tasks.forEach(taskOrSuite => {
135
- if (taskOrSuite.result?.state === 'fail') {
136
- status = 'failed'; // set status to failed if any test failed
137
- }
138
- });
139
-
140
- // if there are no failed tests > search for passed tests
141
- if (status !== 'failed') {
142
- file.tasks.forEach(taskOrSuite => {
143
- if (taskOrSuite.result?.state === 'pass') {
144
- status = 'passed'; // set status to passed if any test passed (and there are no failed tests)
128
+ /**
129
+ * @type {'passed' | 'failed' | 'finished'}
130
+ */
131
+ let status = 'finished'; // default status (if no failed or passed tests)
132
+ files.forEach(file => {
133
+ // search for failed tests
134
+ file.tasks.forEach(taskOrSuite => {
135
+ if (taskOrSuite.result?.state === 'fail') {
136
+ status = 'failed'; // set status to failed if any test failed
137
+ }
138
+ });
139
+ // if there are no failed tests > search for passed tests
140
+ if (status !== 'failed') {
141
+ file.tasks.forEach(taskOrSuite => {
142
+ if (taskOrSuite.result?.state === 'pass') {
143
+ status = 'passed'; // set status to passed if any test passed (and there are no failed tests)
144
+ }
145
+ });
145
146
  }
146
- });
147
- }
148
- });
149
-
150
- return status;
147
+ });
148
+ return status;
151
149
  }
152
-
153
150
  /**
154
151
  * Returns test status in Testomat.io format
155
152
  *
@@ -157,26 +154,30 @@ function getRunStatusFromResults(files) {
157
154
  * @returns 'passed' | 'failed' | 'skipped'
158
155
  */
159
156
  function getTestStatus(test) {
160
- if (test.result?.state === 'fail') return STATUS.FAILED;
161
- if (test.result?.state === 'pass') return STATUS.PASSED;
162
- if (!test.result && test.mode === 'skip') return STATUS.SKIPPED;
163
- console.error(chalk.red('Unprocessed case for defining test status. Contact dev team. Test:'), test);
157
+ if (test.result?.state === 'fail')
158
+ return constants_js_1.STATUS.FAILED;
159
+ if (test.result?.state === 'pass')
160
+ return constants_js_1.STATUS.PASSED;
161
+ if (!test.result && test.mode === 'skip')
162
+ return constants_js_1.STATUS.SKIPPED;
163
+ console.error(picocolors_1.default.red('Unprocessed case for defining test status. Contact dev team. Test:'), test);
164
164
  }
165
-
166
165
  /**
167
166
  * @param {VitestTestLogs[]} logs
168
167
  * @returns string
169
168
  */
170
169
  function transformLogsToString(logs) {
171
- if (!logs) return '';
172
- let logsStr = '';
173
- logs.forEach(log => {
174
- if (log.type === 'stdout') logsStr += `${log.content}\n`;
175
- if (log.type === 'stderr') logsStr += `${chalk.red(log.content)}\n`;
176
- });
177
- return logsStr;
170
+ if (!logs)
171
+ return '';
172
+ let logsStr = '';
173
+ logs.forEach(log => {
174
+ if (log.type === 'stdout')
175
+ logsStr += `${log.content}\n`;
176
+ if (log.type === 'stderr')
177
+ logsStr += `${picocolors_1.default.red(log.content)}\n`;
178
+ });
179
+ return logsStr;
178
180
  }
181
+ module.exports = VitestReporter;
179
182
 
180
183
  module.exports.VitestReporter = VitestReporter;
181
- module.exports.default = VitestReporter;
182
- module.exports = VitestReporter;
@@ -1,101 +1,117 @@
1
- // eslint-disable-next-line global-require, import/no-extraneous-dependencies
2
- const WDIOReporter = require('@wdio/reporter').default;
3
- const TestomatClient = require('../client');
4
- const { getTestomatIdFromTestTitle } = require('../utils/utils');
5
-
6
- class WebdriverReporter extends WDIOReporter {
7
- constructor(options) {
8
- super(options);
9
-
10
- this.client = new TestomatClient({ apiKey: options?.apiKey });
11
- options = Object.assign(options, { stdout: true });
12
-
13
- this._addTestPromises = [];
14
-
15
- this._isSynchronising = false;
16
- }
17
-
18
- get isSynchronised() {
19
- return this._isSynchronising === false;
20
- }
21
-
22
- async onRunnerEnd() {
23
- this._isSynchronising = true;
24
-
25
- await Promise.all(this._addTestPromises);
26
-
27
- this._isSynchronising = false;
28
- }
29
-
30
- onTestEnd(test) {
31
- this._addTestPromises.push(this.addTest(test));
32
- }
33
-
34
- // wdio-cucumber does not trigger onTestEnd hook, thus, using this one
35
- /**
36
- *
37
- * @param {} scerario
38
- * @returns
39
- */
40
- onSuiteEnd(scerario) {
41
- if (scerario.type === 'scenario') {
42
- this._addTestPromises.push(this.addBddScenario(scerario));
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
43
7
  }
44
- }
45
-
46
- async addTest(test) {
47
- if (!this.client) return;
48
-
49
- const { title, _duration: duration, state, error, output } = test;
50
-
51
- const testId = getTestomatIdFromTestTitle(title);
52
-
53
- const screenshotEndpoint = '/session/:sessionId/screenshot';
54
- const screenshotsBuffers = output
55
- .filter(el => el.endpoint === screenshotEndpoint && el.result && el.result.value)
56
- .map(el => Buffer.from(el.result.value, 'base64'));
57
-
58
- await this.client.addTestRun(state, {
59
- error,
60
- title,
61
- test_id: testId,
62
- time: duration,
63
- filesBuffers: screenshotsBuffers,
64
- });
65
- }
66
-
67
- /**
68
- * @param {import('../../types').WebdriverIOScenario} scenario
69
- */
70
- addBddScenario(scenario) {
71
- if (!this.client) return;
72
-
73
- const { title, _duration: duration } = scenario;
74
-
75
- const testId = getTestomatIdFromTestTitle(title || scenario.tags.map(tag => tag.name).join(' '));
76
-
77
- let scenarioState = scenario.tests.every(test => test.state === 'passed') ? 'passed' : 'failed';
78
- if (scenario.tests.every(test => test.state === 'skipped')) {
79
- scenarioState = 'skipped';
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ // eslint-disable-next-line
30
+ const reporter_1 = __importStar(require("@wdio/reporter"));
31
+ const client_js_1 = __importDefault(require("../client.js"));
32
+ const utils_js_1 = require("../utils/utils.js");
33
+ class WebdriverReporter extends reporter_1.default {
34
+ constructor(options) {
35
+ super(options);
36
+ this.client = new client_js_1.default({ apiKey: options?.apiKey });
37
+ options = Object.assign(options, { stdout: true });
38
+ this._addTestPromises = [];
39
+ this._isSynchronising = false;
40
+ // NOTE: new functionality; may break everything
41
+ this.client.createRun();
42
+ }
43
+ get isSynchronised() {
44
+ return this._isSynchronising === false;
45
+ }
46
+ /**
47
+ *
48
+ * @param {RunnerStats} runData
49
+ */
50
+ async onRunnerEnd(runData) {
51
+ this._isSynchronising = true;
52
+ await Promise.all(this._addTestPromises);
53
+ this._isSynchronising = false;
54
+ // NOTE: new functionality; may break everything
55
+ // also this may require additional status mapping
56
+ await this.client.updateRunStatus(runData.failures ? 'failed' : 'passed');
57
+ }
58
+ onTestEnd(test) {
59
+ this._addTestPromises.push(this.addTest(test));
60
+ }
61
+ // wdio-cucumber does not trigger onTestEnd hook, thus, using this one
62
+ /**
63
+ *
64
+ * @returns
65
+ */
66
+ onSuiteEnd(scerario) {
67
+ if (scerario.type === 'scenario') {
68
+ this._addTestPromises.push(this.addBddScenario(scerario));
69
+ }
70
+ }
71
+ async addTest(test) {
72
+ if (!this.client)
73
+ return;
74
+ const { title, _duration: duration, state, error, output } = test;
75
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(title);
76
+ const screenshotEndpoint = '/session/:sessionId/screenshot';
77
+ const screenshotsBuffers = output
78
+ .filter(el => el.endpoint === screenshotEndpoint && el.result && el.result.value)
79
+ .map(el => Buffer.from(el.result.value, 'base64'));
80
+ await this.client.addTestRun(state, {
81
+ error,
82
+ title,
83
+ test_id: testId,
84
+ time: duration,
85
+ filesBuffers: screenshotsBuffers,
86
+ });
87
+ }
88
+ /**
89
+ * @param {import('../../types').WebdriverIOScenario} scenario
90
+ */
91
+ addBddScenario(scenario) {
92
+ if (!this.client)
93
+ return;
94
+ const { title, _duration: duration } = scenario;
95
+ const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(title || scenario.tags.map(tag => tag.name).join(' '));
96
+ let scenarioState = scenario.tests.every(test => test.state === 'passed') ? 'passed' : 'failed';
97
+ if (scenario.tests.every(test => test.state === 'skipped')) {
98
+ scenarioState = 'skipped';
99
+ }
100
+ const errors = scenario.tests
101
+ .filter(test => test.state === 'failed')
102
+ .map(test => test.error?.stack)
103
+ .filter(Boolean);
104
+ const error = errors.join('\n');
105
+ const tags = scenario.tags.map(tag => tag.name);
106
+ return this.client.addTestRun(scenarioState, {
107
+ error: error ? Error(error) : null,
108
+ title,
109
+ test_id: testId,
110
+ time: duration,
111
+ tags,
112
+ file: scenario.file,
113
+ // filesBuffers: screenshotsBuffers,
114
+ });
80
115
  }
81
- const errors = scenario.tests
82
- .filter(test => test.state === 'failed')
83
- .map(test => test.error?.stack)
84
- .filter(Boolean);
85
- const error = errors.join('\n');
86
-
87
- const tags = scenario.tags.map(tag => tag.name);
88
-
89
- return this.client.addTestRun(scenarioState, {
90
- error: error ? Error(error) : null,
91
- title,
92
- test_id: testId,
93
- time: duration,
94
- tags,
95
- file: scenario.file,
96
- // filesBuffers: screenshotsBuffers,
97
- });
98
- }
99
116
  }
100
-
101
117
  module.exports = WebdriverReporter;
@@ -1,67 +1,67 @@
1
1
  #!/usr/bin/env node
2
- const program = require('commander');
3
- const chalk = require('chalk');
4
- const glob = require('glob');
5
- const debug = require('debug')('@testomatio/reporter:xml-cli');
6
- const { APP_PREFIX } = require('../constants');
7
- const XmlReader = require('../xmlReader');
8
-
9
- const { version } = require('../../package.json');
10
-
11
- console.log(chalk.cyan.bold(` 🤩 Testomat.io XML Reporter v${version}`));
12
-
13
- program
14
- .arguments('<pattern>')
15
- .option('-d, --dir <dir>', 'Project directory')
16
- .option('--java-tests [java-path]', 'Load Java tests from path, by default: src/test/java')
17
- .option('--lang <lang>', 'Language used (python, ruby, java)')
18
- .option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
19
- .option('--env-file <envfile>', 'Load environment variables from env file')
20
- .action(async (pattern, opts) => {
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = __importDefault(require("commander"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
9
+ const glob_1 = __importDefault(require("glob"));
10
+ const debug_1 = __importDefault(require("debug"));
11
+ const constants_js_1 = require("../constants.js");
12
+ const xmlReader_js_1 = __importDefault(require("../xmlReader.js"));
13
+ const package_json_1 = require("../../package.json");
14
+ const debug = (0, debug_1.default)('@testomatio/reporter:xml-cli');
15
+ console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io XML Reporter v${package_json_1.version}`)));
16
+ commander_1.default
17
+ .arguments('<pattern>')
18
+ .option('-d, --dir <dir>', 'Project directory')
19
+ .option('--java-tests [java-path]', 'Load Java tests from path, by default: src/test/java')
20
+ .option('--lang <lang>', 'Language used (python, ruby, java)')
21
+ .option('--timelimit <time>', 'default time limit in seconds to kill a stuck process')
22
+ .option('--env-file <envfile>', 'Load environment variables from env file')
23
+ .action(async (pattern, opts) => {
21
24
  if (!pattern.endsWith('.xml')) {
22
- pattern += '.xml';
25
+ pattern += '.xml';
23
26
  }
24
27
  let { javaTests, lang } = opts;
25
28
  if (opts.envFile) {
26
- console.log(APP_PREFIX, 'Loading env file:', opts.envFile);
27
- debug('Loading env file: %s', opts.envFile);
28
- require('dotenv').config({ path: opts.envFile }); // eslint-disable-line
29
+ console.log(constants_js_1.APP_PREFIX, 'Loading env file:', opts.envFile);
30
+ debug('Loading env file: %s', opts.envFile);
31
+ require('dotenv').config({ path: opts.envFile }); // eslint-disable-line
29
32
  }
30
- if (javaTests === true) javaTests = 'src/test/java';
33
+ if (javaTests === true)
34
+ javaTests = 'src/test/java';
31
35
  lang = lang?.toLowerCase();
32
- const runReader = new XmlReader({ javaTests, lang });
33
- const files = glob.sync(pattern, { cwd: opts.dir || process.cwd() });
36
+ const runReader = new xmlReader_js_1.default({ javaTests, lang });
37
+ const files = glob_1.default.sync(pattern, { cwd: opts.dir || process.cwd() });
34
38
  if (!files.length) {
35
- console.log(APP_PREFIX, `Report can't be created. No XML files found 😥`);
36
- process.exitCode = 1;
37
- return;
39
+ console.log(constants_js_1.APP_PREFIX, `Report can't be created. No XML files found 😥`);
40
+ process.exitCode = 1;
41
+ return;
38
42
  }
39
-
40
43
  for (const file of files) {
41
- console.log(APP_PREFIX, `Parsed ${file}`);
42
- runReader.parse(file);
44
+ console.log(constants_js_1.APP_PREFIX, `Parsed ${file}`);
45
+ runReader.parse(file);
43
46
  }
44
-
45
47
  let timeoutTimer;
46
48
  if (opts.timelimit) {
47
- timeoutTimer = setTimeout(() => {
48
- console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
49
- process.exit(0);
50
- }, parseInt(opts.timelimit, 10) * 1000);
49
+ timeoutTimer = setTimeout(() => {
50
+ console.log(`⚠️ Reached timeout of ${opts.timelimit}s. Exiting... (Exit code is 0 to not fail the pipeline)`);
51
+ process.exit(0);
52
+ }, parseInt(opts.timelimit, 10) * 1000);
51
53
  }
52
-
53
54
  try {
54
- await runReader.createRun();
55
- await runReader.uploadData();
56
- } catch (err) {
57
- console.log(APP_PREFIX, 'Error updating status, skipping...', err);
55
+ await runReader.createRun();
56
+ await runReader.uploadData();
58
57
  }
59
-
60
- if (timeoutTimer) clearTimeout(timeoutTimer);
61
- });
62
-
58
+ catch (err) {
59
+ console.log(constants_js_1.APP_PREFIX, 'Error updating status, skipping...', err);
60
+ }
61
+ if (timeoutTimer)
62
+ clearTimeout(timeoutTimer);
63
+ });
63
64
  if (process.argv.length < 3) {
64
- program.outputHelp();
65
+ commander_1.default.outputHelp();
65
66
  }
66
-
67
- program.parse(process.argv);
67
+ commander_1.default.parse(process.argv);