@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
@@ -1,227 +1,186 @@
1
- const debug = require('debug')('@testomatio/reporter:pipe:gitlab');
2
- const { default: axios } = require('axios');
3
- const chalk = require('chalk');
4
- const humanizeDuration = require('humanize-duration');
5
- const merge = require('lodash.merge');
6
- const path = require('path');
7
- const { APP_PREFIX, testomatLogoURL } = require('../constants');
8
- const { ansiRegExp, isSameTest } = require('../utils/utils');
9
- const { statusEmoji, fullName } = require('../utils/pipe_utils');
10
-
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
+ const debug_1 = __importDefault(require("debug"));
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
9
+ const humanize_duration_1 = __importDefault(require("humanize-duration"));
10
+ const lodash_merge_1 = __importDefault(require("lodash.merge"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const constants_js_1 = require("../constants.js");
13
+ const utils_js_1 = require("../utils/utils.js");
14
+ const pipe_utils_js_1 = require("../utils/pipe_utils.js");
15
+ const debug = (0, debug_1.default)('@testomatio/reporter:pipe:gitlab');
11
16
  //! GITLAB_PAT environment variable is required for this functionality to work
12
17
  //! and your pipeline trigger should be merge_request
13
-
14
18
  /**
15
19
  * @class GitLabPipe
16
- * @typedef {import('../../types').Pipe} Pipe
17
- * @typedef {import('../../types').TestData} TestData
20
+ * @typedef {import('../../types/types.js').Pipe} Pipe
21
+ * @typedef {import('../../types/types.js').TestData} TestData
18
22
  */
19
23
  class GitLabPipe {
20
- constructor(params, store = {}) {
21
- this.isEnabled = false;
22
- this.ENV = process.env;
23
- this.store = store;
24
- this.tests = [];
25
- // GitLab PAT looks like glpat-nKGdja3jsG4850sGksh7
26
- this.token = params.GITLAB_PAT || process.env.GITLAB_PAT || this.ENV.GITLAB_PAT;
27
- this.hiddenCommentData = `<!--- testomat.io report ${process.env.CI_JOB_NAME || ''} -->`;
28
-
29
- debug(
30
- chalk.yellow('GitLab Pipe:'),
31
- this.token ? 'TOKEN passed' : '*no token*',
32
- `Project id: ${this.ENV.CI_PROJECT_ID}, MR id: ${this.ENV.CI_MERGE_REQUEST_IID}`,
33
- );
34
-
35
- if (!this.ENV.CI_PROJECT_ID || !this.ENV.CI_MERGE_REQUEST_IID) {
36
- debug(`CI pipeline should be run in Merge Request to have ability to add the report comment.`);
37
- return;
38
- }
39
-
40
- if (!this.token) {
41
- debug(`Hint: GitLab CI variables are unavailable for unprotected branches by default.`);
42
- return;
24
+ constructor(params, store = {}) {
25
+ this.isEnabled = false;
26
+ this.ENV = process.env;
27
+ this.store = store;
28
+ this.tests = [];
29
+ // GitLab PAT looks like glpat-nKGdja3jsG4850sGksh7
30
+ this.token = params.GITLAB_PAT || process.env.GITLAB_PAT || this.ENV.GITLAB_PAT;
31
+ this.hiddenCommentData = `<!--- testomat.io report ${process.env.CI_JOB_NAME || ''} -->`;
32
+ debug(picocolors_1.default.yellow('GitLab Pipe:'), this.token ? 'TOKEN passed' : '*no token*', `Project id: ${this.ENV.CI_PROJECT_ID}, MR id: ${this.ENV.CI_MERGE_REQUEST_IID}`);
33
+ if (!this.ENV.CI_PROJECT_ID || !this.ENV.CI_MERGE_REQUEST_IID) {
34
+ debug(`CI pipeline should be run in Merge Request to have ability to add the report comment.`);
35
+ return;
36
+ }
37
+ if (!this.token) {
38
+ debug(`Hint: GitLab CI variables are unavailable for unprotected branches by default.`);
39
+ return;
40
+ }
41
+ this.isEnabled = true;
42
+ debug('GitLab Pipe: Enabled');
43
43
  }
44
-
45
- this.isEnabled = true;
46
-
47
- debug('GitLab Pipe: Enabled');
48
- }
49
-
50
- // TODO: to using SET opts as argument => prepareRun(opts)
51
- async prepareRun() {}
52
-
53
- async createRun() {}
54
-
55
- addTest(test) {
56
- if (!this.isEnabled) return;
57
-
58
- const index = this.tests.findIndex(t => isSameTest(t, test));
59
- // update if they were already added
60
- if (index >= 0) {
61
- this.tests[index] = merge(this.tests[index], test);
62
- return;
44
+ // TODO: to using SET opts as argument => prepareRun(opts)
45
+ async prepareRun() { }
46
+ async createRun() { }
47
+ addTest(test) {
48
+ if (!this.isEnabled)
49
+ return;
50
+ const index = this.tests.findIndex(t => (0, utils_js_1.isSameTest)(t, test));
51
+ // update if they were already added
52
+ if (index >= 0) {
53
+ this.tests[index] = (0, lodash_merge_1.default)(this.tests[index], test);
54
+ return;
55
+ }
56
+ this.tests.push(test);
63
57
  }
64
-
65
- this.tests.push(test);
66
- }
67
-
68
- async finishRun(runParams) {
69
- if (!this.isEnabled) return;
70
-
71
- if (runParams.tests) runParams.tests.forEach(t => this.addTest(t));
72
-
73
- // ... create a comment on GitLab
74
- const passedCount = this.tests.filter(t => t.status === 'passed').length;
75
- const failedCount = this.tests.filter(t => t.status === 'failed').length;
76
- const skippedCount = this.tests.filter(t => t.status === 'skipped').length;
77
-
78
- // constructing the table
79
- let summary = `${this.hiddenCommentData}
58
+ async finishRun(runParams) {
59
+ if (!this.isEnabled)
60
+ return;
61
+ if (runParams.tests)
62
+ runParams.tests.forEach(t => this.addTest(t));
63
+ // ... create a comment on GitLab
64
+ const passedCount = this.tests.filter(t => t.status === 'passed').length;
65
+ const failedCount = this.tests.filter(t => t.status === 'failed').length;
66
+ const skippedCount = this.tests.filter(t => t.status === 'skipped').length;
67
+ // constructing the table
68
+ let summary = `${this.hiddenCommentData}
80
69
 
81
- | [![Testomat.io Report](${testomatLogoURL})](https://testomat.io) | ${statusEmoji(
82
- runParams.status,
83
- )} ${runParams.status.toUpperCase()} ${statusEmoji(runParams.status)} |
70
+ | [![Testomat.io Report](${constants_js_1.testomatLogoURL})](https://testomat.io) | ${(0, pipe_utils_js_1.statusEmoji)(runParams.status)} ${runParams.status.toUpperCase()} ${(0, pipe_utils_js_1.statusEmoji)(runParams.status)} |
84
71
  | --- | --- |
85
72
  | Tests | ✔️ **${this.tests.length}** tests run |
86
- | Summary | ${statusEmoji('failed')} **${failedCount}** failed; ${statusEmoji(
87
- 'passed',
88
- )} **${passedCount}** passed; **${statusEmoji('skipped')}** ${skippedCount} skipped |
89
- | Duration | 🕐 **${humanizeDuration(
90
- parseInt(
91
- this.tests.reduce((a, t) => a + (t.run_time || 0), 0),
92
- 10,
93
- ),
94
- {
95
- maxDecimalPoints: 0,
96
- },
97
- )}** |
73
+ | Summary | ${(0, pipe_utils_js_1.statusEmoji)('failed')} **${failedCount}** failed; ${(0, pipe_utils_js_1.statusEmoji)('passed')} **${passedCount}** passed; **${(0, pipe_utils_js_1.statusEmoji)('skipped')}** ${skippedCount} skipped |
74
+ | Duration | 🕐 **${(0, humanize_duration_1.default)(parseInt(this.tests.reduce((a, t) => a + (t.run_time || 0), 0), 10), {
75
+ maxDecimalPoints: 0,
76
+ })}** |
98
77
  `;
99
-
100
- if (this.ENV.CI_JOB_NAME && this.ENV.CI_JOB_ID) {
101
- // eslint-disable-next-line max-len
102
- summary += `| Job | 👷 [${this.ENV.CI_JOB_ID}](${this.ENV.CI_JOB_URL})<br>Name: **${this.ENV.CI_JOB_NAME}**<br>Stage: **${this.ENV.CI_JOB_STAGE}** | `;
103
- }
104
-
105
- const failures = this.tests
106
- .filter(t => t.status === 'failed')
107
- .slice(0, 20)
108
- .map(t => {
109
- let text = `#### ${statusEmoji('failed')} ${fullName(t)} `;
110
- text += '\n\n';
111
- if (t.message)
112
- text += `> ${t.message
113
- .replace(/[^\x20-\x7E]/g, '')
114
- .replace(ansiRegExp(), '')
115
- .trim()}\n`;
116
- if (t.stack) text += `\`\`\`diff\n${t.stack.replace(ansiRegExp(), '').trim()}\n\`\`\`\n`;
117
-
118
- if (t.artifacts && t.artifacts.length && !this.ENV.TESTOMATIO_PRIVATE_ARTIFACTS) {
119
- t.artifacts
120
- .filter(f => !!f)
121
- .filter(f => f.endsWith('.png'))
122
- .forEach(f => {
123
- if (f.endsWith('.png')) {
124
- text += `![](${f})\n`;
125
- return text;
126
- }
127
- text += `[📄 ${path.basename(f)}](${f})\n`;
128
- return text;
129
- });
78
+ if (this.ENV.CI_JOB_NAME && this.ENV.CI_JOB_ID) {
79
+ // eslint-disable-next-line max-len
80
+ summary += `| Job | 👷 [${this.ENV.CI_JOB_ID}](${this.ENV.CI_JOB_URL})<br>Name: **${this.ENV.CI_JOB_NAME}**<br>Stage: **${this.ENV.CI_JOB_STAGE}** | `;
130
81
  }
131
-
132
- text += '\n---\n';
133
-
134
- return text;
135
- });
136
-
137
- let body = summary;
138
-
139
- if (failures.length) {
140
- body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h4></summary>\n\n${failures.join('\n')}\n`;
141
- if (failures.length > 20) {
142
- body += '\n> Notice\n> Only first 20 failures shown*';
143
- }
144
- body += '\n\n</details>';
145
- }
146
-
147
- if (this.tests.length > 0) {
148
- body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
149
- body += this.tests
150
- // eslint-disable-next-line no-unsafe-optional-chaining
151
- .sort((a, b) => b?.run_time - a?.run_time)
152
- .slice(0, 5)
153
- .map(t => `* ${fullName(t)} (${humanizeDuration(parseFloat(t.run_time))})`)
154
- .join('\n');
155
- body += '\n</details>';
156
- }
157
-
158
- // eslint-disable-next-line max-len
159
- const commentsRequestURL = `https://gitlab.com/api/v4/projects/${this.ENV.CI_PROJECT_ID}/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}/notes`;
160
-
161
- // delete previous report
162
- await deletePreviousReport(axios, commentsRequestURL, this.hiddenCommentData, this.token);
163
-
164
- // add current report
165
- debug(`Adding comment via url: ${commentsRequestURL}`);
166
-
167
- try {
168
- const addCommentResponse = await axios.post(`${commentsRequestURL}?access_token=${this.token}`, { body });
169
-
170
- const commentID = addCommentResponse.data.id;
171
- // eslint-disable-next-line max-len
172
- const commentURL = `${this.ENV.CI_PROJECT_URL}/-/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}#note_${commentID}`;
173
-
174
- console.log(APP_PREFIX, chalk.yellow('GitLab'), `Report created: ${chalk.magenta(commentURL)}`);
175
- } catch (err) {
176
- console.error(
177
- APP_PREFIX,
178
- chalk.yellow('GitLab'),
179
- `Couldn't create GitLab report\n${err}.
82
+ const failures = this.tests
83
+ .filter(t => t.status === 'failed')
84
+ .slice(0, 20)
85
+ .map(t => {
86
+ let text = `#### ${(0, pipe_utils_js_1.statusEmoji)('failed')} ${(0, pipe_utils_js_1.fullName)(t)} `;
87
+ text += '\n\n';
88
+ if (t.message)
89
+ text += `> ${t.message
90
+ .replace(/[^\x20-\x7E]/g, '')
91
+ .replace((0, utils_js_1.ansiRegExp)(), '')
92
+ .trim()}\n`;
93
+ if (t.stack)
94
+ text += `\`\`\`diff\n${t.stack.replace((0, utils_js_1.ansiRegExp)(), '').trim()}\n\`\`\`\n`;
95
+ if (t.artifacts && t.artifacts.length && !this.ENV.TESTOMATIO_PRIVATE_ARTIFACTS) {
96
+ t.artifacts
97
+ .filter(f => !!f)
98
+ .filter(f => f.endsWith('.png'))
99
+ .forEach(f => {
100
+ if (f.endsWith('.png')) {
101
+ text += `![](${f})\n`;
102
+ return text;
103
+ }
104
+ text += `[📄 ${path_1.default.basename(f)}](${f})\n`;
105
+ return text;
106
+ });
107
+ }
108
+ text += '\n---\n';
109
+ return text;
110
+ });
111
+ let body = summary;
112
+ if (failures.length) {
113
+ body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h4></summary>\n\n${failures.join('\n')}\n`;
114
+ if (failures.length > 20) {
115
+ body += '\n> Notice\n> Only first 20 failures shown*';
116
+ }
117
+ body += '\n\n</details>';
118
+ }
119
+ if (this.tests.length > 0) {
120
+ body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
121
+ body += this.tests
122
+ // eslint-disable-next-line no-unsafe-optional-chaining
123
+ .sort((a, b) => b?.run_time - a?.run_time)
124
+ .slice(0, 5)
125
+ .map(t => `* ${(0, pipe_utils_js_1.fullName)(t)} (${(0, humanize_duration_1.default)(parseFloat(t.run_time))})`)
126
+ .join('\n');
127
+ body += '\n</details>';
128
+ }
129
+ // eslint-disable-next-line max-len
130
+ const commentsRequestURL = `https://gitlab.com/api/v4/projects/${this.ENV.CI_PROJECT_ID}/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}/notes`;
131
+ // delete previous report
132
+ await deletePreviousReport(axios_1.default, commentsRequestURL, this.hiddenCommentData, this.token);
133
+ // add current report
134
+ debug(`Adding comment via url: ${commentsRequestURL}`);
135
+ try {
136
+ const addCommentResponse = await axios_1.default.post(`${commentsRequestURL}?access_token=${this.token}`, { body });
137
+ const commentID = addCommentResponse.data.id;
138
+ // eslint-disable-next-line max-len
139
+ const commentURL = `${this.ENV.CI_PROJECT_URL}/-/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}#note_${commentID}`;
140
+ console.log(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitLab'), `Report created: ${picocolors_1.default.magenta(commentURL)}`);
141
+ }
142
+ catch (err) {
143
+ console.error(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitLab'), `Couldn't create GitLab report\n${err}.
180
144
  Request url: ${commentsRequestURL}
181
- Request data: ${body}`,
182
- );
145
+ Request data: ${body}`);
146
+ }
147
+ }
148
+ toString() {
149
+ return 'GitLab Reporter';
183
150
  }
184
- }
185
-
186
- toString() {
187
- return 'GitLab Reporter';
188
- }
189
-
190
- updateRun() {}
151
+ updateRun() { }
191
152
  }
192
-
193
153
  async function deletePreviousReport(axiosInstance, commentsRequestURL, hiddenCommentData, token) {
194
- if (process.env.GITLAB_KEEP_OUTDATED_REPORTS) return;
195
-
196
- // get comments
197
- let comments = [];
198
-
199
- try {
200
- const response = await axiosInstance.get(`${commentsRequestURL}?access_token=${token}`);
201
- comments = response.data;
202
- } catch (e) {
203
- console.error('Error while attempt to retrieve comments on GitLab Merge Request:\n', e);
204
- }
205
-
206
- if (!comments.length) return;
207
-
208
- for (const comment of comments) {
209
- // if comment was left by the same workflow
210
- if (comment.body.includes(hiddenCommentData)) {
211
- try {
212
- // delete previous comment
213
- const deleteCommentURL = `${commentsRequestURL}/${comment.id}?access_token=${token}`;
214
- await axiosInstance.delete(deleteCommentURL);
215
- } catch (e) {
216
- console.warn(`Can't delete previously added comment with testomat.io report. Ignore.`);
217
- }
218
-
219
- // pass next env var if need to clear all previous reports;
220
- // only the last one is removed by default
221
- if (!process.env.GITLAB_REMOVE_ALL_OUTDATED_REPORTS) break;
222
- // TODO: in case of many reports should implement pagination
154
+ if (process.env.GITLAB_KEEP_OUTDATED_REPORTS)
155
+ return;
156
+ // get comments
157
+ let comments = [];
158
+ try {
159
+ const response = await axiosInstance.get(`${commentsRequestURL}?access_token=${token}`);
160
+ comments = response.data;
161
+ }
162
+ catch (e) {
163
+ console.error('Error while attempt to retrieve comments on GitLab Merge Request:\n', e);
164
+ }
165
+ if (!comments.length)
166
+ return;
167
+ for (const comment of comments) {
168
+ // if comment was left by the same workflow
169
+ if (comment.body.includes(hiddenCommentData)) {
170
+ try {
171
+ // delete previous comment
172
+ const deleteCommentURL = `${commentsRequestURL}/${comment.id}?access_token=${token}`;
173
+ await axiosInstance.delete(deleteCommentURL);
174
+ }
175
+ catch (e) {
176
+ console.warn(`Can't delete previously added comment with testomat.io report. Ignore.`);
177
+ }
178
+ // pass next env var if need to clear all previous reports;
179
+ // only the last one is removed by default
180
+ if (!process.env.GITLAB_REMOVE_ALL_OUTDATED_REPORTS)
181
+ break;
182
+ // TODO: in case of many reports should implement pagination
183
+ }
223
184
  }
224
- }
225
185
  }
226
-
227
186
  module.exports = GitLabPipe;
@@ -0,0 +1,34 @@
1
+ export default HtmlPipe;
2
+ declare class HtmlPipe {
3
+ constructor(params: any, store?: {});
4
+ store: {};
5
+ title: any;
6
+ apiKey: any;
7
+ isHtml: string;
8
+ isEnabled: boolean;
9
+ htmlOutputPath: string;
10
+ fullHtmlOutputPath: string;
11
+ filenameMsg: string;
12
+ tests: any[];
13
+ htmlReportDir: string;
14
+ htmlReportName: string;
15
+ templateFolderPath: string;
16
+ templateHtmlPath: string;
17
+ createRun(): Promise<void>;
18
+ updateRun(): void;
19
+ /**
20
+ * Add test data to the result array for saving. As a result of this function, we get a result object to save.
21
+ * @param {import('../../types/types.js').RunData} test - object which includes each test entry.
22
+ */
23
+ addTest(test: import("../../types/types.js").RunData): void;
24
+ finishRun(runParams: any): Promise<void>;
25
+ /**
26
+ * Generates an HTML report based on provided test data and a template.
27
+ * @param {object} opts - Test options used to generate the HTML report:
28
+ * runParams, tests, outputPath, templatePath
29
+ * @returns {void} - This function does not return anything.
30
+ */
31
+ buildReport(opts: object): void;
32
+ toString(): string;
33
+ #private;
34
+ }