@testomatio/reporter 2.0.1-beta.3 → 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.
- package/lib/adapter/codecept.js +335 -293
- package/lib/adapter/cucumber/current.js +203 -195
- package/lib/adapter/cucumber/legacy.js +155 -130
- package/lib/adapter/cucumber.js +16 -5
- package/lib/adapter/cypress-plugin/index.js +105 -91
- package/lib/adapter/jasmine.js +53 -54
- package/lib/adapter/jest.js +99 -97
- package/lib/adapter/mocha.js +141 -112
- package/lib/adapter/playwright.js +231 -199
- package/lib/adapter/vitest.js +149 -150
- package/lib/adapter/webdriver.js +121 -144
- package/lib/bin/cli.js +211 -229
- package/lib/bin/reportXml.js +52 -51
- package/lib/bin/startTest.js +95 -83
- package/lib/bin/uploadArtifacts.js +61 -56
- package/lib/client.js +465 -424
- package/lib/config.js +23 -18
- package/lib/constants.js +44 -50
- package/lib/data-storage.js +188 -216
- package/lib/junit-adapter/adapter.js +20 -17
- package/lib/junit-adapter/csharp.js +14 -28
- package/lib/junit-adapter/index.js +25 -27
- package/lib/junit-adapter/java.js +53 -41
- package/lib/junit-adapter/javascript.js +27 -30
- package/lib/junit-adapter/python.js +37 -38
- package/lib/junit-adapter/ruby.js +8 -11
- package/lib/output.js +52 -44
- package/lib/pipe/bitbucket.js +230 -223
- package/lib/pipe/csv.js +126 -113
- package/lib/pipe/debug.js +99 -118
- package/lib/pipe/github.js +213 -218
- package/lib/pipe/gitlab.js +206 -183
- package/lib/pipe/html.js +321 -258
- package/lib/pipe/index.js +66 -94
- package/lib/pipe/testomatio.js +474 -429
- package/lib/reporter-functions.js +26 -28
- package/lib/reporter.js +29 -34
- package/lib/services/artifacts.js +51 -55
- package/lib/services/index.js +12 -14
- package/lib/services/key-values.js +53 -56
- package/lib/services/logger.js +245 -226
- package/lib/template/testomatio.hbs +1366 -1026
- package/lib/uploader.js +364 -295
- package/lib/utils/pipe_utils.js +85 -89
- package/lib/utils/utils.js +307 -398
- package/lib/xmlReader.js +532 -525
- package/package.json +21 -64
- package/lib/adapter/codecept.d.ts +0 -2
- package/lib/adapter/cucumber/current.d.ts +0 -14
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber.d.ts +0 -2
- package/lib/adapter/cypress-plugin/index.d.ts +0 -2
- package/lib/adapter/jasmine.d.ts +0 -11
- package/lib/adapter/jest.d.ts +0 -13
- package/lib/adapter/mocha.d.ts +0 -2
- package/lib/adapter/nightwatch.d.ts +0 -4
- package/lib/adapter/nightwatch.js +0 -80
- package/lib/adapter/playwright.d.ts +0 -14
- package/lib/adapter/vitest.d.ts +0 -35
- package/lib/adapter/webdriver.d.ts +0 -24
- package/lib/bin/cli.d.ts +0 -2
- package/lib/bin/reportXml.d.ts +0 -2
- package/lib/bin/startTest.d.ts +0 -2
- package/lib/bin/uploadArtifacts.d.ts +0 -2
- package/lib/client.d.ts +0 -76
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +0 -25
- package/lib/data-storage.d.ts +0 -34
- package/lib/junit-adapter/adapter.d.ts +0 -9
- package/lib/junit-adapter/csharp.d.ts +0 -5
- package/lib/junit-adapter/index.d.ts +0 -3
- package/lib/junit-adapter/java.d.ts +0 -5
- package/lib/junit-adapter/javascript.d.ts +0 -4
- package/lib/junit-adapter/python.d.ts +0 -5
- package/lib/junit-adapter/ruby.d.ts +0 -4
- package/lib/output.d.ts +0 -11
- package/lib/package.json +0 -3
- package/lib/pipe/bitbucket.d.ts +0 -25
- package/lib/pipe/csv.d.ts +0 -47
- package/lib/pipe/debug.d.ts +0 -29
- package/lib/pipe/github.d.ts +0 -30
- package/lib/pipe/gitlab.d.ts +0 -25
- package/lib/pipe/html.d.ts +0 -35
- package/lib/pipe/index.d.ts +0 -1
- package/lib/pipe/testomatio.d.ts +0 -71
- package/lib/replay.d.ts +0 -31
- package/lib/replay.js +0 -237
- package/lib/reporter-functions.d.ts +0 -34
- package/lib/reporter.d.ts +0 -232
- package/lib/services/artifacts.d.ts +0 -33
- package/lib/services/index.d.ts +0 -9
- package/lib/services/key-values.d.ts +0 -27
- package/lib/services/logger.d.ts +0 -64
- package/lib/uploader.d.ts +0 -60
- package/lib/utils/pipe_utils.d.ts +0 -41
- package/lib/utils/utils.d.ts +0 -54
- package/lib/xmlReader.d.ts +0 -92
- package/src/adapter/codecept.js +0 -373
- package/src/adapter/cucumber/current.js +0 -228
- package/src/adapter/cucumber/legacy.js +0 -158
- package/src/adapter/cucumber.js +0 -4
- package/src/adapter/cypress-plugin/index.js +0 -110
- package/src/adapter/jasmine.js +0 -60
- package/src/adapter/jest.js +0 -107
- package/src/adapter/mocha.cjs +0 -2
- package/src/adapter/mocha.js +0 -156
- package/src/adapter/nightwatch.js +0 -88
- package/src/adapter/playwright.js +0 -254
- package/src/adapter/vitest.js +0 -183
- package/src/adapter/webdriver.js +0 -142
- package/src/bin/cli.js +0 -348
- package/src/bin/reportXml.js +0 -77
- package/src/bin/startTest.js +0 -124
- package/src/bin/uploadArtifacts.js +0 -91
- package/src/client.js +0 -508
- package/src/config.js +0 -30
- package/src/constants.js +0 -53
- package/src/data-storage.js +0 -204
- package/src/junit-adapter/adapter.js +0 -23
- package/src/junit-adapter/csharp.js +0 -28
- package/src/junit-adapter/index.js +0 -28
- package/src/junit-adapter/java.js +0 -58
- package/src/junit-adapter/javascript.js +0 -31
- package/src/junit-adapter/python.js +0 -42
- package/src/junit-adapter/ruby.js +0 -10
- package/src/output.js +0 -57
- package/src/pipe/bitbucket.js +0 -252
- package/src/pipe/csv.js +0 -140
- package/src/pipe/debug.js +0 -119
- package/src/pipe/github.js +0 -232
- package/src/pipe/gitlab.js +0 -247
- package/src/pipe/html.js +0 -373
- package/src/pipe/index.js +0 -71
- package/src/pipe/testomatio.js +0 -504
- package/src/replay.js +0 -245
- package/src/reporter-functions.js +0 -55
- package/src/reporter.cjs_decprecated +0 -21
- package/src/reporter.js +0 -33
- package/src/services/artifacts.js +0 -59
- package/src/services/index.js +0 -13
- package/src/services/key-values.js +0 -59
- package/src/services/logger.js +0 -315
- package/src/template/emptyData.svg +0 -23
- package/src/template/testomatio.hbs +0 -1081
- package/src/uploader.js +0 -376
- package/src/utils/pipe_utils.js +0 -119
- package/src/utils/utils.js +0 -416
- package/src/xmlReader.js +0 -614
package/lib/services/logger.js
CHANGED
|
@@ -1,254 +1,272 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger = void 0;
|
|
7
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
|
-
const debug_1 = __importDefault(require("debug"));
|
|
9
|
-
const data_storage_js_1 = require("../data-storage.js");
|
|
10
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:services-logger');
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const debug = require('debug')('@testomatio/reporter:services-logger');
|
|
3
|
+
const { dataStorage } = require('../data-storage');
|
|
4
|
+
|
|
11
5
|
const LOG_METHODS = ['assert', 'debug', 'error', 'info', 'log', 'trace', 'warn'];
|
|
12
6
|
const LEVELS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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' },
|
|
21
15
|
};
|
|
16
|
+
|
|
22
17
|
// ! DON'T use console.log, console.warn, etc in this file, because it will lead to infinite loop
|
|
23
18
|
// use debug() instead
|
|
19
|
+
|
|
24
20
|
/**
|
|
25
21
|
* Logger allows to intercept logs from any logger (console.log, tracer, pino, etc)
|
|
26
22
|
* and save in the testomatio reporter.
|
|
27
23
|
* Supports different syntaxes to satisfy any user preferences.
|
|
28
24
|
*/
|
|
29
25
|
class Logger {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
logLevel = process?.env?.LOG_LEVEL?.toUpperCase() || 'ALL';
|
|
45
|
-
constructor() {
|
|
46
|
-
if (!data_storage_js_1.dataStorage.isFileStorage ||
|
|
47
|
-
(process.env.TESTOMATIO_INTERCEPT_CONSOLE_LOGS && process.env.TESTOMATIO_INTERCEPT_CONSOLE_LOGS !== 'false'))
|
|
48
|
-
this.intercept(console);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Allows you to define a step inside a test. Step name is attached to the report and
|
|
52
|
-
* helps to understand the test flow.
|
|
53
|
-
* @param {*} strings
|
|
54
|
-
* @param {...any} values
|
|
55
|
-
*/
|
|
56
|
-
step(strings, ...values) {
|
|
57
|
-
let logs = '';
|
|
58
|
-
for (let i = 0; i < strings.length; i++) {
|
|
59
|
-
logs += strings[i];
|
|
60
|
-
if (i < values.length) {
|
|
61
|
-
logs += values[i];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
logs = picocolors_1.default.blue(`> ${logs}`);
|
|
65
|
-
data_storage_js_1.dataStorage.putData('log', logs);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {string} context testId or test context from test runner
|
|
70
|
-
* @returns {string[]}
|
|
71
|
-
*/
|
|
72
|
-
getLogs(context) {
|
|
73
|
-
const logs = data_storage_js_1.dataStorage.getData('log', context);
|
|
74
|
-
if (!logs)
|
|
75
|
-
return [];
|
|
76
|
-
return logs;
|
|
77
|
-
}
|
|
78
|
-
#stringifyLogs(...args) {
|
|
79
|
-
const logs = [];
|
|
80
|
-
// stringify everything except strings
|
|
81
|
-
for (const arg of args) {
|
|
82
|
-
// ignore empty strings
|
|
83
|
-
if (arg === '')
|
|
84
|
-
continue;
|
|
85
|
-
if (typeof arg === 'string') {
|
|
86
|
-
logs.push(arg);
|
|
87
|
-
}
|
|
88
|
-
else if (Array.isArray(arg)) {
|
|
89
|
-
logs.push(arg.join(' '));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
try {
|
|
93
|
-
this.prettyObjects ? logs.push(JSON.stringify(arg, null, 2)) : logs.push(JSON.stringify(arg));
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
debug('Error while stringify object', e);
|
|
97
|
-
logs.push(arg);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return logs.join(' ');
|
|
26
|
+
// set default logger to be used in log, warn, error, etc methods
|
|
27
|
+
#originalUserLogger = { ...console };
|
|
28
|
+
|
|
29
|
+
#userLoggerWithOverridenMethods;
|
|
30
|
+
|
|
31
|
+
static #instance;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @returns {Logger}
|
|
36
|
+
*/
|
|
37
|
+
static getInstance() {
|
|
38
|
+
if (!this.#instance) {
|
|
39
|
+
this.#instance = new Logger();
|
|
102
40
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
: ''),
|
|
126
|
-
// initial accumulator value
|
|
127
|
-
'');
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
// this block means arguments syntax is used (syntax like $('text', someVar))
|
|
131
|
-
// in this case strings represents just a first argument
|
|
132
|
-
logs = this.#stringifyLogs(strings, ...args);
|
|
133
|
-
}
|
|
134
|
-
this.#originalUserLogger.log(logs);
|
|
135
|
-
data_storage_js_1.dataStorage.putData('log', logs);
|
|
41
|
+
return this.#instance;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
logLevel = process?.env?.LOG_LEVEL?.toUpperCase() || 'ALL';
|
|
45
|
+
|
|
46
|
+
constructor() {
|
|
47
|
+
if (!dataStorage.isFileStorage || process.env.TESTOMATIO_INTERCEPT_CONSOLE_LOGS) this.intercept(console);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Allows you to define a step inside a test. Step name is attached to the report and
|
|
52
|
+
* helps to understand the test flow.
|
|
53
|
+
* @param {*} strings
|
|
54
|
+
* @param {...any} values
|
|
55
|
+
*/
|
|
56
|
+
step(strings, ...values) {
|
|
57
|
+
let logs = '';
|
|
58
|
+
for (let i = 0; i < strings.length; i++) {
|
|
59
|
+
logs += strings[i];
|
|
60
|
+
if (i < values.length) {
|
|
61
|
+
logs += values[i];
|
|
62
|
+
}
|
|
136
63
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
64
|
+
logs = chalk.blue(`> ${logs}`);
|
|
65
|
+
dataStorage.putData('log', logs);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {string} context testId or test context from test runner
|
|
71
|
+
* @returns {string[]}
|
|
72
|
+
*/
|
|
73
|
+
getLogs(context) {
|
|
74
|
+
const logs = dataStorage.getData('log', context);
|
|
75
|
+
if (!logs) return [];
|
|
76
|
+
return logs;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#stringifyLogs(...args) {
|
|
80
|
+
const logs = [];
|
|
81
|
+
// stringify everything except strings
|
|
82
|
+
for (const arg of args) {
|
|
83
|
+
// ignore empty strings
|
|
84
|
+
if (arg === '') continue;
|
|
85
|
+
if (typeof arg === 'string') {
|
|
86
|
+
logs.push(arg);
|
|
87
|
+
} else if (Array.isArray(arg)) {
|
|
88
|
+
logs.push(arg.join(' '));
|
|
89
|
+
} else {
|
|
155
90
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
91
|
+
// eslint-disable-next-line no-unused-expressions
|
|
92
|
+
this.prettyObjects ? logs.push(JSON.stringify(arg, null, 2)) : logs.push(JSON.stringify(arg));
|
|
93
|
+
} catch (e) {
|
|
94
|
+
debug('Error while stringify object', e);
|
|
95
|
+
logs.push(arg);
|
|
158
96
|
}
|
|
159
|
-
|
|
160
|
-
// method could be unexisting, ignore error
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
assert(...args) {
|
|
164
|
-
this.#logWrapper(args, 'ERROR');
|
|
165
|
-
}
|
|
166
|
-
debug(...args) {
|
|
167
|
-
this.#logWrapper(args, 'DEBUG');
|
|
168
|
-
}
|
|
169
|
-
error(...args) {
|
|
170
|
-
this.#logWrapper(args, 'ERROR');
|
|
97
|
+
}
|
|
171
98
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
99
|
+
return logs.join(' ');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tagget template literal. Allows to use different syntaxes:
|
|
104
|
+
* 1. Tagget template: log`text ${someVar}`
|
|
105
|
+
* 2. Standard: log(`text ${someVar}`)
|
|
106
|
+
* 3. Standard with multiple arguments: log('text', someVar)
|
|
107
|
+
*/
|
|
108
|
+
_templateLiteralLog(strings, ...args) {
|
|
109
|
+
if (Array.isArray(strings)) strings = strings.filter(item => item !== '').map(item => item.trim());
|
|
110
|
+
if (Array.isArray(args)) args = args.filter(item => item !== '');
|
|
111
|
+
|
|
112
|
+
let logs;
|
|
113
|
+
// this block means tagged template is used (syntax like $`text ${someVar}`)
|
|
114
|
+
if (Array.isArray(strings) && strings.length === args.length + 1) {
|
|
115
|
+
logs = strings.reduce(
|
|
116
|
+
(result, current, index) =>
|
|
117
|
+
result +
|
|
118
|
+
current +
|
|
119
|
+
// strings are splitted by args when use tagged template, thus we add arg after each string
|
|
120
|
+
// it looks like: `string1 arg1 string2 arg2 string3`
|
|
121
|
+
(args[index] !== undefined // eslint-disable-line no-nested-ternary
|
|
122
|
+
? typeof args[index] === 'string'
|
|
123
|
+
? args[index] // add arg as it is
|
|
124
|
+
: this.#stringifyLogs(args[index]) // stringify arg
|
|
125
|
+
: ''),
|
|
126
|
+
// initial accumulator value
|
|
127
|
+
'',
|
|
128
|
+
);
|
|
129
|
+
} else {
|
|
130
|
+
// this block means arguments syntax is used (syntax like $('text', someVar))
|
|
131
|
+
// in this case strings represents just a first argument
|
|
132
|
+
logs = this.#stringifyLogs(strings, ...args);
|
|
177
133
|
}
|
|
178
|
-
|
|
179
|
-
|
|
134
|
+
this.#originalUserLogger.log(logs);
|
|
135
|
+
dataStorage.putData('log', logs);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* This function is a wrapper for each logging methods (log, warn, error etc) (not to repeat the same code)
|
|
140
|
+
* @param {*} argsArray
|
|
141
|
+
* @param {*} level
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
#logWrapper(argsArray, level) {
|
|
145
|
+
if (!argsArray.length) return;
|
|
146
|
+
|
|
147
|
+
const severity = LEVELS[level].severity;
|
|
148
|
+
if (severity < LEVELS[this.logLevel]?.severity) return;
|
|
149
|
+
|
|
150
|
+
const logs = this.#stringifyLogs(...argsArray);
|
|
151
|
+
|
|
152
|
+
const colorizedLogs = chalk[LEVELS[level].color](logs);
|
|
153
|
+
// do not attach logs from testomatio reporter itself
|
|
154
|
+
if (!logs.includes('[TESTOMATIO]')) {
|
|
155
|
+
dataStorage.putData('log', colorizedLogs);
|
|
180
156
|
}
|
|
181
|
-
|
|
182
|
-
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
// level.toLowerCase() represents method name (log, warn, error, etc)
|
|
160
|
+
this.#originalUserLogger[level.toLowerCase()](colorizedLogs);
|
|
161
|
+
} catch (e) {
|
|
162
|
+
// method could be unexisting, ignore error
|
|
183
163
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
assert(...args) {
|
|
167
|
+
this.#logWrapper(args, 'ERROR');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
debug(...args) {
|
|
171
|
+
this.#logWrapper(args, 'DEBUG');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
error(...args) {
|
|
175
|
+
this.#logWrapper(args, 'ERROR');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
info(...args) {
|
|
179
|
+
this.#logWrapper(args, 'INFO');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
log(...args) {
|
|
183
|
+
this.#logWrapper(args, 'LOG');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
trace(...args) {
|
|
187
|
+
this.#logWrapper(args, 'TRACE');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
warn(...args) {
|
|
191
|
+
this.#logWrapper(args, 'WARN');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Intercepts user logger messages.
|
|
196
|
+
* When call this method, Logger start to control the user logger
|
|
197
|
+
* @param {*} userLogger
|
|
198
|
+
*/
|
|
199
|
+
intercept(userLogger) {
|
|
200
|
+
// STEP 1: reset previously intercepted logger methods to original
|
|
201
|
+
if (this.#userLoggerWithOverridenMethods) {
|
|
202
|
+
for (const method of LOG_METHODS) {
|
|
203
|
+
this.#userLoggerWithOverridenMethods[method] = this.#originalUserLogger[method];
|
|
204
|
+
}
|
|
222
205
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
206
|
+
|
|
207
|
+
// STEP 2: intercept new logger
|
|
208
|
+
this.#originalUserLogger = { ...userLogger };
|
|
209
|
+
|
|
210
|
+
const isUserLoggerConsole = userLogger.toString?.().toLowerCase() === '[object console]';
|
|
211
|
+
debug(`Intercepting ${isUserLoggerConsole ? 'console' : 'some user'} logger}`);
|
|
212
|
+
|
|
213
|
+
// override user logger (any, e.g. console) methods to intercept log messages
|
|
214
|
+
for (const method of LOG_METHODS) {
|
|
215
|
+
/*
|
|
216
|
+
its better to create method even if it does not exist in user logger;
|
|
217
|
+
on method invocation, we will store the data anyway and catch block will prevent potential errors
|
|
218
|
+
while trying to output the message to terminal
|
|
219
|
+
*/
|
|
220
|
+
// if (!this._loggerToIntercept[method]) continue;
|
|
221
|
+
userLogger[method] = (...args) => this[method](...args);
|
|
231
222
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
223
|
+
|
|
224
|
+
this.#userLoggerWithOverridenMethods = userLogger;
|
|
225
|
+
|
|
226
|
+
/*
|
|
227
|
+
Initial idea was to intercept any logger (tracer, pino, etc),
|
|
228
|
+
intercept message and provide output by the same logger.
|
|
229
|
+
But reality brings some problems: the same messages are intercepted multiple times
|
|
230
|
+
(because of multiple loggers are created at the same terminal process).
|
|
231
|
+
Also its difficult to understand (actually did not find the way to do it) if logger was already intercepted or not.
|
|
232
|
+
Thus, decided to intercept only console by default and provide output by default console.
|
|
233
|
+
It means, if user uses his own logger, its messages will be intercepted,
|
|
234
|
+
but the output will be always provided by console.
|
|
235
|
+
TODO: try to implement the providing output to terminal by user logger
|
|
236
|
+
*/
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
stopInterception() {
|
|
240
|
+
debug('Stop ntercepting logs');
|
|
241
|
+
|
|
242
|
+
// restore original user logger
|
|
243
|
+
if (this.#userLoggerWithOverridenMethods) {
|
|
244
|
+
for (const method of LOG_METHODS) {
|
|
245
|
+
this.#userLoggerWithOverridenMethods[method] = this.#originalUserLogger[method];
|
|
246
|
+
}
|
|
247
247
|
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Allows to configure logger. Make sure you do it before the logger usage in your code.
|
|
252
|
+
*
|
|
253
|
+
* @param {Object} [config={}] - The configuration object.
|
|
254
|
+
* @param {string} [config.logLevel] - The desired log level. Valid values are 'DEBUG', 'INFO', 'WARN', and 'ERROR'.
|
|
255
|
+
* @param {boolean} [config.prettyObjects] - Specifies whether to enable pretty printing of objects.
|
|
256
|
+
* @returns {void}
|
|
257
|
+
*/
|
|
258
|
+
configure(config = {}) {
|
|
259
|
+
if (!config) return;
|
|
260
|
+
if (config.prettyObjects === false || config.prettyObjects === true) this.prettyObjects = config.prettyObjects;
|
|
261
|
+
if (config.logLevel) this.logLevel = config.logLevel.toUpperCase();
|
|
262
|
+
}
|
|
248
263
|
}
|
|
249
|
-
|
|
264
|
+
|
|
265
|
+
module.exports.logger = Logger.getInstance();
|
|
266
|
+
|
|
250
267
|
// TODO: parse passed arguments as {level: 'str', message: 'str'} because some loggers use such syntax;
|
|
251
268
|
// upd: did not face such loggers, but still could be useful
|
|
269
|
+
|
|
252
270
|
/* Cypress
|
|
253
271
|
There is no listener like "after:test" in cypress, only "after:spec" is available.
|
|
254
272
|
Thus, cannot separate logs even when I gather them (because I don't know when the test is done, just know about suite).
|
|
@@ -288,5 +306,6 @@ Finally, in the test it will look like:
|
|
|
288
306
|
|
|
289
307
|
Parallelization in Cypress is only available if using Cypress Dashboard??
|
|
290
308
|
*/
|
|
309
|
+
|
|
291
310
|
// TODO: add time to logs
|
|
292
311
|
// TODO: add logger name to logs?
|