@testomatio/reporter 2.0.0-beta-esm → 2.0.0-beta.1-xml

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 (123) hide show
  1. package/lib/adapter/codecept.d.ts +2 -0
  2. package/lib/adapter/codecept.js +31 -26
  3. package/lib/adapter/cucumber/current.d.ts +14 -0
  4. package/lib/adapter/cucumber/legacy.d.ts +0 -0
  5. package/lib/adapter/cucumber.d.ts +2 -0
  6. package/lib/adapter/cypress-plugin/index.d.ts +2 -0
  7. package/lib/adapter/cypress-plugin/index.js +10 -10
  8. package/lib/adapter/jasmine.d.ts +11 -0
  9. package/lib/adapter/jest.d.ts +13 -0
  10. package/lib/adapter/mocha.d.ts +2 -0
  11. package/lib/adapter/mocha.js +4 -4
  12. package/lib/adapter/nightwatch.d.ts +4 -0
  13. package/lib/adapter/nightwatch.js +80 -0
  14. package/lib/adapter/playwright.d.ts +14 -0
  15. package/lib/adapter/playwright.js +58 -33
  16. package/lib/adapter/vitest.d.ts +35 -0
  17. package/lib/adapter/vitest.js +6 -6
  18. package/lib/adapter/webdriver.d.ts +24 -0
  19. package/lib/adapter/webdriver.js +51 -14
  20. package/lib/bin/cli.d.ts +2 -0
  21. package/lib/bin/cli.js +250 -0
  22. package/lib/bin/reportXml.d.ts +2 -0
  23. package/lib/bin/reportXml.js +15 -11
  24. package/lib/bin/startTest.d.ts +2 -0
  25. package/lib/bin/startTest.js +12 -7
  26. package/lib/bin/uploadArtifacts.d.ts +2 -0
  27. package/lib/bin/uploadArtifacts.js +82 -0
  28. package/lib/client.d.ts +76 -0
  29. package/lib/client.js +128 -53
  30. package/lib/config.d.ts +1 -0
  31. package/lib/config.js +2 -2
  32. package/lib/constants.d.ts +25 -0
  33. package/lib/constants.js +5 -1
  34. package/lib/data-storage.d.ts +34 -0
  35. package/lib/data-storage.js +19 -9
  36. package/lib/junit-adapter/adapter.d.ts +9 -0
  37. package/lib/junit-adapter/csharp.d.ts +5 -0
  38. package/lib/junit-adapter/csharp.js +11 -1
  39. package/lib/junit-adapter/index.d.ts +3 -0
  40. package/lib/junit-adapter/java.d.ts +5 -0
  41. package/lib/junit-adapter/javascript.d.ts +4 -0
  42. package/lib/junit-adapter/python.d.ts +5 -0
  43. package/lib/junit-adapter/ruby.d.ts +4 -0
  44. package/lib/output.d.ts +11 -0
  45. package/lib/package.json +3 -1
  46. package/lib/pipe/bitbucket.d.ts +23 -0
  47. package/lib/pipe/bitbucket.js +19 -9
  48. package/lib/pipe/csv.d.ts +47 -0
  49. package/lib/pipe/csv.js +2 -2
  50. package/lib/pipe/debug.d.ts +29 -0
  51. package/lib/pipe/debug.js +108 -0
  52. package/lib/pipe/github.d.ts +30 -0
  53. package/lib/pipe/github.js +37 -5
  54. package/lib/pipe/gitlab.d.ts +23 -0
  55. package/lib/pipe/gitlab.js +2 -3
  56. package/lib/pipe/html.d.ts +35 -0
  57. package/lib/pipe/html.js +9 -4
  58. package/lib/pipe/index.d.ts +1 -0
  59. package/lib/pipe/index.js +20 -10
  60. package/lib/pipe/testomatio.d.ts +70 -0
  61. package/lib/pipe/testomatio.js +54 -39
  62. package/lib/reporter-functions.d.ts +34 -0
  63. package/lib/reporter-functions.js +17 -7
  64. package/lib/reporter.d.ts +232 -0
  65. package/lib/reporter.js +19 -33
  66. package/lib/services/artifacts.d.ts +33 -0
  67. package/lib/services/index.d.ts +9 -0
  68. package/lib/services/key-values.d.ts +27 -0
  69. package/lib/services/key-values.js +1 -1
  70. package/lib/services/logger.d.ts +64 -0
  71. package/lib/services/logger.js +1 -2
  72. package/lib/template/testomatio.hbs +651 -1366
  73. package/lib/uploader.d.ts +60 -0
  74. package/lib/uploader.js +312 -0
  75. package/lib/utils/pipe_utils.d.ts +41 -0
  76. package/lib/utils/pipe_utils.js +3 -5
  77. package/lib/utils/utils.d.ts +47 -0
  78. package/lib/utils/utils.js +99 -12
  79. package/lib/xmlReader.d.ts +92 -0
  80. package/lib/xmlReader.js +64 -25
  81. package/package.json +19 -13
  82. package/src/adapter/codecept.js +30 -26
  83. package/src/adapter/cypress-plugin/index.js +5 -5
  84. package/src/adapter/mocha.cjs +1 -1
  85. package/src/adapter/mocha.js +4 -4
  86. package/src/adapter/nightwatch.js +88 -0
  87. package/src/adapter/playwright.js +59 -31
  88. package/src/adapter/vitest.js +6 -6
  89. package/src/adapter/webdriver.js +42 -12
  90. package/src/bin/cli.js +303 -0
  91. package/src/bin/reportXml.js +19 -9
  92. package/src/bin/startTest.js +9 -4
  93. package/src/bin/uploadArtifacts.js +91 -0
  94. package/src/client.js +137 -57
  95. package/src/config.js +2 -2
  96. package/src/constants.js +5 -1
  97. package/src/data-storage.js +2 -2
  98. package/src/junit-adapter/csharp.js +13 -1
  99. package/src/pipe/bitbucket.js +2 -2
  100. package/src/pipe/csv.js +3 -3
  101. package/src/pipe/debug.js +104 -0
  102. package/src/pipe/github.js +3 -5
  103. package/src/pipe/gitlab.js +6 -7
  104. package/src/pipe/html.js +14 -7
  105. package/src/pipe/index.js +5 -7
  106. package/src/pipe/testomatio.js +75 -76
  107. package/src/reporter-functions.js +18 -7
  108. package/src/reporter.cjs_decprecated +21 -0
  109. package/src/reporter.js +20 -11
  110. package/src/services/key-values.js +1 -1
  111. package/src/services/logger.js +5 -4
  112. package/src/template/testomatio.hbs +651 -1366
  113. package/src/uploader.js +371 -0
  114. package/src/utils/pipe_utils.js +4 -12
  115. package/src/utils/utils.js +64 -15
  116. package/src/xmlReader.js +76 -26
  117. package/lib/adapter/jasmine/jasmine.js +0 -63
  118. package/lib/adapter/mocha/mocha.js +0 -125
  119. package/lib/fileUploader.js +0 -245
  120. package/lib/utils/chalk.js +0 -10
  121. package/src/fileUploader.js +0 -307
  122. package/src/reporter.cjs +0 -22
  123. package/src/utils/chalk.js +0 -13
@@ -1,10 +0,0 @@
1
- // import chalk from 'chalk';
2
- // let chalkToUse = chalk;
3
- // try {
4
- // if (typeof require !== 'undefined') {
5
- // chalkToUse = require('chalk4');
6
- // }
7
- // } catch (e) {
8
- // chalkToUse = chalk;
9
- // }
10
- // export default chalkToUse;
@@ -1,307 +0,0 @@
1
- import createDebugMessages from 'debug';
2
- import { S3 } from '@aws-sdk/client-s3';
3
- import { Upload } from '@aws-sdk/lib-storage';
4
- import fs from 'fs';
5
- import util from 'util';
6
- import path from 'path';
7
- import promiseRetry from 'promise-retry';
8
- import pc from 'picocolors';
9
- import { randomUUID } from 'crypto';
10
- import { APP_PREFIX } from './constants.js';
11
-
12
- const readFile = util.promisify(fs.readFile);
13
- const stat = util.promisify(fs.stat);
14
- const debug = createDebugMessages('@testomatio/reporter:file-uploader');
15
- const keys = [
16
- 'S3_ENDPOINT',
17
- 'S3_REGION',
18
- 'S3_BUCKET',
19
- 'S3_ACCESS_KEY_ID',
20
- 'S3_SECRET_ACCESS_KEY',
21
- 'S3_SESSION_TOKEN',
22
- 'TESTOMATIO_DISABLE_ARTIFACTS',
23
- 'TESTOMATIO_PRIVATE_ARTIFACTS',
24
- 'S3_FORCE_PATH_STYLE',
25
- ];
26
-
27
- let config;
28
-
29
- function resetConfig() {
30
- config = undefined;
31
- isEnabled = undefined;
32
- }
33
-
34
- function getConfig() {
35
- if (config) return config;
36
- config = keys.reduce((acc, key) => {
37
- acc[key] = process.env[key];
38
- return acc;
39
- }, {});
40
- return config;
41
- }
42
-
43
- function getMaskedConfig() {
44
- return Object.fromEntries(
45
- Object.entries(getConfig()).map(([key, value]) => [
46
- key,
47
- key === 'S3_SECRET_ACCESS_KEY' || key === 'S3_ACCESS_KEY_ID' ? '***' : value,
48
- ]),
49
- );
50
- }
51
-
52
- let isEnabled;
53
-
54
- const isArtifactsEnabled = () => {
55
- if (isEnabled !== undefined) return isEnabled;
56
- const { S3_BUCKET, TESTOMATIO_DISABLE_ARTIFACTS } = getConfig();
57
- isEnabled = !!(S3_BUCKET && !TESTOMATIO_DISABLE_ARTIFACTS);
58
- debug(`Upload is ${isEnabled ? 'enabled' : 'disabled'}`);
59
- return isEnabled;
60
- };
61
-
62
- const _getFileExtBase64 = str => {
63
- const type = str.charAt(0);
64
-
65
- return (
66
- {
67
- '/': '.jpg',
68
- i: '.png',
69
- R: '.gif',
70
- U: '.webp',
71
- }[type] || ''
72
- );
73
- };
74
-
75
- const _getS3Config = () => {
76
- const { S3_REGION, S3_SESSION_TOKEN, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_FORCE_PATH_STYLE, S3_ENDPOINT } =
77
- getConfig();
78
-
79
- const cfg = {
80
- region: S3_REGION,
81
- credentials: {
82
- accessKeyId: S3_ACCESS_KEY_ID,
83
- secretAccessKey: S3_SECRET_ACCESS_KEY,
84
- s3ForcePathStyle: S3_FORCE_PATH_STYLE,
85
- },
86
- };
87
-
88
- if (S3_SESSION_TOKEN) {
89
- cfg.credentials.sessionToken = S3_SESSION_TOKEN;
90
- }
91
-
92
- if (S3_ENDPOINT) {
93
- cfg.endpoint = S3_ENDPOINT;
94
- }
95
-
96
- return cfg;
97
- };
98
-
99
- const uploadUsingS3 = async (filePath, runId) => {
100
- let ContentType;
101
- let Key;
102
-
103
- if (typeof filePath === 'object') {
104
- ContentType = filePath?.type;
105
- filePath = filePath?.path;
106
- Key = filePath?.name;
107
- }
108
-
109
- const { TESTOMATIO_PRIVATE_ARTIFACTS, S3_BUCKET } = getConfig();
110
-
111
- try {
112
- debug('S3 config', getMaskedConfig());
113
- debug('Started upload', filePath, 'to ', S3_BUCKET);
114
-
115
- // Verification that the file was actually created: 20 attempts of 0.5 second => 10sec
116
- const isFileExist = await checkFileExists(filePath, 20, 500);
117
-
118
- if (!isFileExist) {
119
- console.error(pc.yellow(`Artifacts file ${filePath} does not exist. Skipping...`));
120
- return;
121
- }
122
-
123
- debug('File: ', filePath, ' exists');
124
-
125
- const fileData = await readFile(filePath);
126
-
127
- Key = `${runId}/${randomUUID()}-${Key || path.basename(filePath)}`;
128
-
129
- const ACL = TESTOMATIO_PRIVATE_ARTIFACTS ? 'private' : 'public-read';
130
-
131
- if (!S3_BUCKET || !fileData) {
132
- console.log(
133
- APP_PREFIX,
134
- pc.bold(pc.red(`Failed uploading '${Key}'. Please check S3 credentials`)),
135
- getMaskedConfig(),
136
- );
137
- return;
138
- }
139
-
140
- const s3 = new S3(_getS3Config());
141
-
142
- /**
143
- * @type {import('@aws-sdk/client-s3').PutObjectCommandInput}
144
- */
145
- const params = {
146
- Bucket: S3_BUCKET,
147
- Key,
148
- Body: fileData,
149
- ContentType,
150
- ACL,
151
- };
152
-
153
- const out = new Upload({
154
- client: s3,
155
- params,
156
- });
157
-
158
- const link = await getS3LocationLink(out);
159
-
160
- debug(`Succesfully uploaded ${filePath} => ${S3_BUCKET}/${Key} | URL: ${link}`);
161
-
162
- return link;
163
- } catch (e) {
164
- debug('S3 file uploading error: ', e);
165
-
166
- console.log(APP_PREFIX, `To ${pc.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`);
167
-
168
- if (!TESTOMATIO_PRIVATE_ARTIFACTS) {
169
- console.log(APP_PREFIX, `To enable ${pc.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`);
170
- } else {
171
- console.log(
172
- APP_PREFIX,
173
- `To enable ${pc.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`,
174
- );
175
- }
176
- console.log(APP_PREFIX, '---------------');
177
- }
178
- };
179
-
180
- const uploadUsingS3AsBuffer = async (buffer, fileName, runId) => {
181
- const { S3_REGION, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_ENDPOINT, TESTOMATIO_PRIVATE_ARTIFACTS, S3_BUCKET } =
182
- getConfig();
183
-
184
- const ACL = TESTOMATIO_PRIVATE_ARTIFACTS ? 'private' : 'public-read';
185
-
186
- const fileExtension = _getFileExtBase64(buffer.toString('base64'));
187
- const Key = `${runId}/${fileName}${fileExtension}`;
188
-
189
- if (!S3_BUCKET || !buffer) {
190
- console.log(APP_PREFIX, pc.bold(pc.red(`Failed uploading '${Key}'. Please check S3 credentials`)), {
191
- accessKeyId: S3_ACCESS_KEY_ID,
192
- secretAccessKey: S3_SECRET_ACCESS_KEY ? '**** (hidden) ***' : '(empty)',
193
- region: S3_REGION,
194
- bucket: S3_BUCKET,
195
- acl: ACL,
196
- endpoint: S3_ENDPOINT,
197
- });
198
- return;
199
- }
200
-
201
- const s3 = new S3(_getS3Config());
202
-
203
- try {
204
- const out = new Upload({
205
- client: s3,
206
-
207
- params: {
208
- Bucket: S3_BUCKET,
209
- Key,
210
- Body: buffer,
211
- ACL,
212
- },
213
- });
214
-
215
- return await getS3LocationLink(out);
216
- } catch (e) {
217
- debug('S3 buffer uploading error: ', e);
218
-
219
- console.log(APP_PREFIX, `To ${pc.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`);
220
-
221
- if (!TESTOMATIO_PRIVATE_ARTIFACTS) {
222
- console.log(APP_PREFIX, `To enable ${pc.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`);
223
- } else {
224
- console.log(
225
- APP_PREFIX,
226
- `To enable ${pc.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`,
227
- );
228
- }
229
- console.log(APP_PREFIX, '---------------');
230
- }
231
- };
232
-
233
- const uploadFileByPath = async (filePath, runId) => {
234
- try {
235
- if (isArtifactsEnabled()) {
236
- return uploadUsingS3(filePath, runId);
237
- }
238
- } catch (e) {
239
- debug(e);
240
-
241
- console.error(pc.red('Error occurred while uploading artifacts! '), e);
242
- }
243
- };
244
-
245
- const uploadFileAsBuffer = async (buffer, fileName, runId) => {
246
- try {
247
- if (isArtifactsEnabled()) {
248
- return uploadUsingS3AsBuffer(buffer, fileName, runId);
249
- }
250
- } catch (e) {
251
- debug(e);
252
-
253
- console.error(pc.red('Error occurred while uploading artifacts! '), e);
254
- }
255
- };
256
-
257
- const checkFileExists = async (filePath, attempts = 5, intervalMs = 500) => {
258
- const checkFile = async () => {
259
- const fileStats = await stat(filePath);
260
- if (fileStats.isFile()) {
261
- return true;
262
- }
263
-
264
- throw new Error('File not found');
265
- };
266
-
267
- try {
268
- await promiseRetry(
269
- {
270
- retries: attempts,
271
- minTimeout: intervalMs,
272
- },
273
- checkFile,
274
- );
275
-
276
- return true;
277
- } catch (err) {
278
- console.error(pc.yellow(`File ${filePath} was not found or did not have time to be generated...`));
279
-
280
- return false;
281
- }
282
- };
283
-
284
- const getS3LocationLink = async out => {
285
- const response = await out.done();
286
-
287
- let s3Location = response?.Location;
288
-
289
- if (!s3Location) {
290
- // TODO: out: a fallback case - remove after deeper testing
291
- s3Location = out?.singleUploadResult?.Location;
292
- debug('Uploaded singleUploadResult.Location', s3Location);
293
-
294
- if (!s3Location) {
295
- throw new Error("Problems getting the S3 artifact's link. Please check S3 permissions!");
296
- }
297
- }
298
-
299
- return s3Location;
300
- };
301
-
302
- export const upload = {
303
- uploadFileByPath,
304
- uploadFileAsBuffer,
305
- isArtifactsEnabled,
306
- resetConfig,
307
- };
package/src/reporter.cjs DELETED
@@ -1,22 +0,0 @@
1
- const _reporter = require('../lib/reporter.js');
2
-
3
- /**
4
- * @typedef {import('../lib/client.js').default} TestomatClient
5
- * @typedef {import('../lib/constants.js')} TRConstants
6
- * @typedef {import('../lib/reporter-functions.js')} artifact
7
- * @typedef {import('../lib/reporter-functions.js')} log
8
- * @typedef {import('../lib/reporter-functions.js')} logger
9
- * @typedef {import('../lib/reporter-functions.js')} meta
10
- * @typedef {import('../lib/reporter-functions.js')} step
11
- *
12
- * "Reporter" type which is object containing all types from the above
13
- * @typedef {{artifact: artifact, log: log, logger: logger, meta: meta, step: step, TestomatClient: TestomatClient, TRConstants: TRConstants}} Reporter
14
- */
15
-
16
- // const reporter = _reporter;
17
-
18
- /**
19
- * @type {Reporter}
20
- */
21
- const reporter = _reporter;
22
- module.exports = reporter;
@@ -1,13 +0,0 @@
1
- // import chalk from 'chalk';
2
-
3
- // let chalkToUse = chalk;
4
-
5
- // try {
6
- // if (typeof require !== 'undefined') {
7
- // chalkToUse = require('chalk4');
8
- // }
9
- // } catch (e) {
10
- // chalkToUse = chalk;
11
- // }
12
-
13
- // export default chalkToUse;