@testomatio/reporter 1.2.4-beta → 1.3.0-ignore-stack-for-passed.1

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 (48) hide show
  1. package/README.md +61 -54
  2. package/lib/adapter/codecept.js +96 -35
  3. package/lib/adapter/cucumber/current.js +19 -12
  4. package/lib/adapter/cucumber/legacy.js +8 -7
  5. package/lib/adapter/cucumber.js +2 -2
  6. package/lib/adapter/cypress-plugin/index.js +52 -25
  7. package/lib/adapter/jasmine.js +1 -1
  8. package/lib/adapter/jest.js +49 -16
  9. package/lib/adapter/mocha.js +103 -51
  10. package/lib/adapter/playwright.js +80 -27
  11. package/lib/adapter/webdriver.js +1 -1
  12. package/lib/bin/reportXml.js +14 -13
  13. package/lib/bin/startTest.js +27 -6
  14. package/lib/client.js +192 -69
  15. package/lib/config.js +34 -0
  16. package/lib/constants.js +19 -7
  17. package/lib/data-storage.js +203 -0
  18. package/lib/fileUploader.js +128 -53
  19. package/lib/junit-adapter/adapter.js +0 -2
  20. package/lib/junit-adapter/csharp.js +3 -4
  21. package/lib/junit-adapter/index.js +3 -3
  22. package/lib/junit-adapter/java.js +35 -17
  23. package/lib/junit-adapter/javascript.js +1 -2
  24. package/lib/junit-adapter/python.js +12 -14
  25. package/lib/junit-adapter/ruby.js +1 -2
  26. package/lib/pipe/csv.js +5 -3
  27. package/lib/pipe/github.js +27 -39
  28. package/lib/pipe/gitlab.js +20 -24
  29. package/lib/pipe/html.js +317 -0
  30. package/lib/pipe/index.js +3 -1
  31. package/lib/pipe/testomatio.js +189 -56
  32. package/lib/reporter-functions.js +46 -0
  33. package/lib/reporter.js +11 -9
  34. package/lib/services/artifacts.js +57 -0
  35. package/lib/services/index.js +13 -0
  36. package/lib/services/key-values.js +58 -0
  37. package/lib/services/logger.js +311 -0
  38. package/lib/template/template-draft.hbs +249 -0
  39. package/lib/template/testomatio.hbs +388 -0
  40. package/lib/utils/pipe_utils.js +128 -0
  41. package/lib/{util.js → utils/utils.js} +144 -12
  42. package/lib/xmlReader.js +211 -122
  43. package/package.json +18 -7
  44. package/lib/_ArtifactStorageOld.js +0 -142
  45. package/lib/artifactStorage.js +0 -25
  46. package/lib/dataStorage.js +0 -241
  47. package/lib/helpers.js +0 -34
  48. package/lib/logger.js +0 -293
package/lib/logger.js DELETED
@@ -1,293 +0,0 @@
1
- const chalk = require('chalk');
2
- const debug = require('debug')('@testomatio/reporter:logger');
3
- const { DataStorage } = require('./dataStorage');
4
-
5
- const LOG_METHODS = ['assert', 'debug', 'error', 'info', 'log', 'trace', 'warn'];
6
- const LEVELS = {
7
- ALL: { severity: 1, color: '' },
8
- VERBOSE: { severity: 3, color: 'grey' },
9
- TRACE: { severity: 5, color: 'grey' },
10
- DEBUG: { severity: 7, color: 'cyan' },
11
- INFO: { severity: 9, color: 'black' },
12
- LOG: { severity: 11, color: 'black' },
13
- WARN: { severity: 13, color: 'yellow' },
14
- ERROR: { severity: 15, color: 'red' },
15
- };
16
-
17
- /**
18
- * Logger allows to:
19
- * 1. Intercept logs from user logger (console.log, etc) and store them.
20
- * 2. Output logs to console (actually, logger functionality).
21
- * 3. Varied syntax.
22
- */
23
- class Logger {
24
- // _originalUserLogger used to output logs to console by the user logger
25
- // _loggerToIntercept intercepted and reassigned immediately when added
26
-
27
- constructor() {
28
- // set default logger to be used in log, warn, error, etc methods
29
- this._originalUserLogger = { ...console };
30
-
31
- this.dataStorage = new DataStorage('log');
32
- this.logLevel = process?.env?.LOG_LEVEL?.toUpperCase() || 'ALL';
33
-
34
- // commented because prefer to use "intercept" method
35
- // if (params?.logger) this._loggerToIntercept = params.logger;
36
-
37
- this.intercept(this._loggerToIntercept);
38
-
39
- // singleton
40
- if (!Logger.instance) {
41
- Logger.instance = this;
42
- }
43
- }
44
-
45
- /**
46
- * Tagget template literal. Allows to use different syntaxes:
47
- * 1. Tagget template: $`text ${someVar}`
48
- * 2. Standard: $(`text ${someVar}`)
49
- * 3. Standard with multiple arguments: $('text', someVar)
50
- */
51
- _log(strings, ...args) {
52
- let logs;
53
- // this block means tagged template is used (syntax like $`text ${someVar}`)
54
- if (Array.isArray(strings) && strings.length === args.length + 1) {
55
- logs = strings.reduce(
56
- (result, current, index) =>
57
- result +
58
- current +
59
- // strings are splitted by args when use tagged template, thus we add arg after each string
60
- // it looks like: `string1 arg1 string2 arg2 string3`
61
- (args[index] !== undefined // eslint-disable-line no-nested-ternary
62
- ? typeof args[index] === 'string'
63
- ? args[index] // add arg as it is
64
- : this._strinfifyLogs(args[index]) // stringify arg
65
- : ' '), // add space if no arg after string
66
- // initial accumulator value
67
- '',
68
- );
69
- } else {
70
- // this block means arguments syntax is used (syntax like $('text', someVar))
71
- // in this case strings represents just a first argument
72
- logs = this._strinfifyLogs(strings, ...args);
73
- }
74
- this.dataStorage.putData(logs);
75
- }
76
-
77
- /**
78
- * Allows you to define a step inside a test. Step name is attached to the report and
79
- * helps to understand the test flow.
80
- * @param {*} strings
81
- * @param {...any} values
82
- */
83
- step(strings, ...values) {
84
- let logs = '';
85
- for (let i = 0; i < strings.length; i++) {
86
- logs += strings[i];
87
- if (i < values.length) {
88
- logs += values[i];
89
- }
90
- }
91
- logs = chalk.blue(`> ${logs}`);
92
- this.dataStorage.putData(logs);
93
- }
94
-
95
- /**
96
- *
97
- * @param {*} context testId or test context from test runner
98
- * @returns
99
- */
100
- getLogs(context) {
101
- const logs = this.dataStorage.getData(context);
102
- return logs || '';
103
- }
104
-
105
- _strinfifyLogs(...args) {
106
- const logs = [];
107
- // stringify everything except strings
108
- for (const arg of args) {
109
- if (typeof arg === 'string') {
110
- logs.push(arg);
111
- } else {
112
- try {
113
- // eslint-disable-next-line no-unused-expressions
114
- this.prettyObjects ? logs.push(JSON.stringify(arg, null, 2)) : logs.push(JSON.stringify(arg));
115
- } catch (e) {
116
- debug('Error while stringify object', e);
117
- logs.push(arg);
118
- }
119
- }
120
- }
121
- return logs.join(' ');
122
- }
123
-
124
- assert(...args) {
125
- // sometimes user invokes logger without any arguments passed
126
- if (!args.length) return;
127
-
128
- const level = 'ERROR';
129
- const severity = LEVELS[level].severity;
130
- if (severity < LEVELS[this.logLevel]?.severity) return;
131
-
132
- const logs = this._strinfifyLogs(...args);
133
- this.dataStorage.putData(logs);
134
- try {
135
- this._originalUserLogger.log(`Assertion result: `, ...args);
136
- } catch (e) {
137
- // method could be unexisting, ignore error
138
- }
139
- }
140
-
141
- debug(...args) {
142
- if (!args.length) return;
143
-
144
- const level = 'DEBUG';
145
- const severity = LEVELS[level].severity;
146
- if (severity < LEVELS[this.logLevel]?.severity) return;
147
-
148
- if (this.logLevel === 'error' || this.logLevel === 'warn') return;
149
- const logs = this._strinfifyLogs(...args);
150
- const colorizedLogs = chalk[LEVELS[level].color](logs);
151
- this.dataStorage.putData(colorizedLogs);
152
- try {
153
- this._originalUserLogger.debug(...args);
154
- } catch (e) {
155
- // method could be unexisting, ignore error
156
- }
157
- }
158
-
159
- error(...args) {
160
- if (!args.length) return;
161
-
162
- const level = 'ERROR';
163
- const severity = LEVELS[level].severity;
164
- if (severity < LEVELS[this.logLevel]?.severity) return;
165
-
166
- const logs = this._strinfifyLogs(...args);
167
- const colorizedLogs = chalk[LEVELS[level].color](logs);
168
- this.dataStorage.putData(colorizedLogs);
169
- try {
170
- this._originalUserLogger.error(...args);
171
- } catch (e) {
172
- // method could be unexisting, ignore error
173
- }
174
- }
175
-
176
- info(...args) {
177
- if (!args.length) return;
178
-
179
- const level = 'INFO';
180
- const severity = LEVELS[level].severity;
181
- if (severity < LEVELS[this.logLevel]?.severity) return;
182
-
183
- const logs = this._strinfifyLogs(...args);
184
- this.dataStorage.putData(logs);
185
- try {
186
- this._originalUserLogger.info(...args);
187
- } catch (e) {
188
- // method could be unexisting, ignore error
189
- }
190
- }
191
-
192
- log(...args) {
193
- if (!args.length) return;
194
-
195
- const level = 'INFO';
196
- const severity = LEVELS[level].severity;
197
- if (severity < LEVELS[this.logLevel]?.severity) return;
198
-
199
- const logs = this._strinfifyLogs(...args);
200
- this.dataStorage.putData(logs);
201
- try {
202
- this._originalUserLogger.log(...args);
203
- } catch (e) {
204
- // method could be unexisting, ignore error
205
- }
206
- }
207
-
208
- trace(...args) {
209
- if (!args.length) return;
210
-
211
- const level = 'TRACE';
212
- const severity = LEVELS[level].severity;
213
- if (severity < LEVELS[this.logLevel]?.severity) return;
214
-
215
- const logs = this._strinfifyLogs(...args);
216
- const colorizedLogs = chalk[LEVELS[level].color](logs);
217
- this.dataStorage.putData(colorizedLogs);
218
- try {
219
- this._originalUserLogger.trace(...args);
220
- } catch (e) {
221
- // method could be unexisting, ignore error
222
- }
223
- }
224
-
225
- warn(...args) {
226
- if (!args.length) return;
227
-
228
- const level = 'WARN';
229
- const severity = LEVELS[level].severity;
230
- if (severity < LEVELS[this.logLevel]?.severity) return;
231
-
232
- const logs = this._strinfifyLogs(...args);
233
- const colorizedLogs = chalk[LEVELS[level].color](logs);
234
- this.dataStorage.putData(colorizedLogs);
235
- try {
236
- this._originalUserLogger.warn(...args);
237
- } catch (e) {
238
- // method could be unexisting, ignore error
239
- }
240
- }
241
-
242
- /**
243
- * Intercepts user logger messages.
244
- * When call this method, Logger start to control the user logger,
245
- * but almost nothing is changed for user ragarding the console output (like log level set by user)
246
- * (until multiple loggers are intercepted,
247
- * in this case only the last intercepted logger will be used as user console output).
248
- * @param {*} userLogger
249
- */
250
- intercept(userLogger) {
251
- if (!userLogger) return;
252
- debug(`User logger intercepted`);
253
-
254
- // save original user logger to use it for logging (last intercepted will be used for console output)
255
- this._originalUserLogger = { ...userLogger };
256
- this._loggerToIntercept = userLogger;
257
-
258
- /*
259
- override user logger (any, e.g. console) methods to intercept log messages
260
- this._loggerToIntercept = this; could be used, but decided to override only output methods
261
- */
262
- for (const method of LOG_METHODS) {
263
- /*
264
- decided to comment next code line because its better to create method even if it does not exist in user logger;
265
- on method invocation, we will store the data anyway and catch block will prevent potential errors
266
- */
267
- // if (!this._loggerToIntercept[method]) continue;
268
- this._loggerToIntercept[method] = (...args) => this[method](...args);
269
- }
270
- }
271
-
272
- /**
273
- * Allows to configure logger. Make sure you do it before the logger usage in your code.
274
- *
275
- * @param {Object} [config={}] - The configuration object.
276
- * @param {string} [config.logLevel] - The desired log level. Valid values are 'DEBUG', 'INFO', 'WARN', and 'ERROR'.
277
- * @param {boolean} [config.prettyObjects] - Specifies whether to enable pretty printing of objects.
278
- * @returns {void}
279
- */
280
- configure(config = {}) {
281
- if (!config) return;
282
- if (config.prettyObjects) this.prettyObjects = config.prettyObjects;
283
- if (config.logLevel) this.logLevel = config.logLevel.toUpperCase();
284
- }
285
- }
286
-
287
- Logger.instance = null;
288
-
289
- // module.exports.Logger = Logger;
290
- module.exports = new Logger();
291
-
292
- // TODO: parse passed arguments as {level: 'str', message: 'str'} because some loggers use such syntax;
293
- // upd: did not face such loggers, but still could be useful