qase-javascript-commons 2.6.2 → 2.6.3
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/changelog.md +47 -0
- package/dist/formatter/index.d.ts +1 -0
- package/dist/formatter/index.js +3 -1
- package/dist/formatter/report-serializer.d.ts +20 -0
- package/dist/formatter/report-serializer.js +89 -0
- package/dist/qase/options-resolver.d.ts +19 -0
- package/dist/qase/options-resolver.js +47 -0
- package/dist/qase/reporter-factory.d.ts +19 -0
- package/dist/qase/reporter-factory.js +67 -0
- package/dist/qase/status-processor.d.ts +17 -0
- package/dist/qase/status-processor.js +48 -0
- package/dist/qase.d.ts +17 -85
- package/dist/qase.js +133 -415
- package/dist/reporters/report-reporter.d.ts +4 -35
- package/dist/reporters/report-reporter.js +6 -130
- package/dist/reporters/shared/fallback-coordinator.d.ts +47 -0
- package/dist/reporters/shared/fallback-coordinator.js +119 -0
- package/dist/reporters/shared/testops-constants.d.ts +5 -0
- package/dist/reporters/shared/testops-constants.js +8 -0
- package/dist/reporters/shared/testops-url.d.ts +9 -0
- package/dist/reporters/shared/testops-url.js +17 -0
- package/dist/reporters/testops-multi-reporter.d.ts +0 -1
- package/dist/reporters/testops-multi-reporter.js +4 -9
- package/dist/reporters/testops-reporter.d.ts +0 -6
- package/dist/reporters/testops-reporter.js +7 -17
- package/dist/utils/token-masker.d.ts +11 -0
- package/dist/utils/token-masker.js +26 -0
- package/package.json +1 -1
package/dist/qase.js
CHANGED
|
@@ -4,19 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.QaseReporter = void 0;
|
|
7
|
-
const env_schema_1 = __importDefault(require("env-schema"));
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const reporters_1 = require("./reporters");
|
|
10
8
|
const options_1 = require("./options");
|
|
11
|
-
const env_1 = require("./env");
|
|
12
9
|
const models_1 = require("./models");
|
|
13
|
-
const writer_1 = require("./writer");
|
|
14
10
|
const disabled_exception_1 = require("./utils/disabled-exception");
|
|
15
11
|
const logger_1 = require("./utils/logger");
|
|
16
|
-
const state_1 = require("./state/state");
|
|
17
12
|
const hostData_1 = require("./utils/hostData");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
13
|
+
const token_masker_1 = require("./utils/token-masker");
|
|
14
|
+
const state_1 = require("./state/state");
|
|
15
|
+
const options_resolver_1 = require("./qase/options-resolver");
|
|
16
|
+
const reporter_factory_1 = require("./qase/reporter-factory");
|
|
17
|
+
const status_processor_1 = require("./qase/status-processor");
|
|
18
|
+
const fallback_coordinator_1 = require("./reporters/shared/fallback-coordinator");
|
|
20
19
|
/**
|
|
21
20
|
* @type {Record<TestStatusEnum, (test: TestResultType) => string>}
|
|
22
21
|
*/
|
|
@@ -30,476 +29,195 @@ const resultLogMap = {
|
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
32
31
|
* @class QaseReporter
|
|
33
|
-
*
|
|
32
|
+
*
|
|
33
|
+
* Thin orchestrator: delegates to OptionsResolver, ReporterFactory,
|
|
34
|
+
* StatusProcessor, and FallbackCoordinator. Public API is preserved.
|
|
34
35
|
*/
|
|
35
36
|
class QaseReporter {
|
|
36
37
|
static instance;
|
|
37
|
-
/**
|
|
38
|
-
* @type {InternalReporterInterface}
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
upstreamReporter;
|
|
42
|
-
/**
|
|
43
|
-
* @type {InternalReporterInterface}
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
fallbackReporter;
|
|
47
|
-
/**
|
|
48
|
-
* @type {boolean | undefined}
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
captureLogs;
|
|
52
|
-
/**
|
|
53
|
-
* @type {boolean}
|
|
54
|
-
* @private
|
|
55
|
-
*/
|
|
56
|
-
disabled = false;
|
|
57
|
-
/**
|
|
58
|
-
* @type {boolean}
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
useFallback = false;
|
|
62
38
|
logger;
|
|
63
|
-
startTestRunOperation;
|
|
64
39
|
options;
|
|
65
40
|
withState;
|
|
66
|
-
|
|
41
|
+
captureLogs;
|
|
42
|
+
statusProcessor;
|
|
43
|
+
fallback;
|
|
44
|
+
startTestRunOperation;
|
|
67
45
|
/**
|
|
68
46
|
* @param {OptionsType} options
|
|
69
47
|
*/
|
|
70
48
|
constructor(options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
49
|
+
const resolved = new options_resolver_1.OptionsResolver().resolve(options);
|
|
50
|
+
this.options = resolved.composed;
|
|
51
|
+
this.withState = resolved.withState;
|
|
52
|
+
this.captureLogs = resolved.composed.captureLogs;
|
|
53
|
+
this.logger = this.buildLogger(resolved);
|
|
54
|
+
this.logger.logDebug(`Config: ${JSON.stringify((0, token_masker_1.sanitizeOptionsForLog)(resolved.composed))}`);
|
|
55
|
+
const hostData = (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName);
|
|
56
|
+
this.logger.logDebug(`Host data: ${JSON.stringify(hostData)}`);
|
|
57
|
+
const factory = new reporter_factory_1.ReporterFactory(this.logger, hostData);
|
|
58
|
+
const { upstream, fallback, disabled, useFallbackFromStart } = this.buildReporters(factory, resolved);
|
|
59
|
+
this.statusProcessor = new status_processor_1.StatusProcessor(this.logger, resolved.composed.statusMapping, resolved.composed.testops?.statusFilter);
|
|
60
|
+
this.fallback = new fallback_coordinator_1.FallbackCoordinator(this.logger, upstream, fallback, {
|
|
61
|
+
onFallbackActivated: () => {
|
|
62
|
+
if (this.withState) {
|
|
63
|
+
state_1.StateManager.setMode(resolved.composed.fallback);
|
|
77
64
|
}
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
},
|
|
66
|
+
onDisabled: () => {
|
|
67
|
+
if (this.withState) {
|
|
68
|
+
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
80
69
|
}
|
|
81
|
-
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (disabled) {
|
|
73
|
+
this.fallback.setDisabled(true);
|
|
82
74
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
if (
|
|
91
|
-
|
|
75
|
+
if (useFallbackFromStart) {
|
|
76
|
+
this.fallback.setUseFallback(true);
|
|
77
|
+
}
|
|
78
|
+
this.persistInitialState(resolved, disabled, useFallbackFromStart);
|
|
79
|
+
}
|
|
80
|
+
buildLogger(resolved) {
|
|
81
|
+
const opts = { debug: resolved.composed.debug };
|
|
82
|
+
if (resolved.composed.logging?.console !== undefined) {
|
|
83
|
+
opts.consoleLogging = resolved.composed.logging.console;
|
|
92
84
|
}
|
|
93
|
-
if (
|
|
94
|
-
|
|
85
|
+
if (resolved.composed.logging?.file !== undefined) {
|
|
86
|
+
opts.fileLogging = resolved.composed.logging.file;
|
|
95
87
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
88
|
+
return new logger_1.Logger(opts);
|
|
89
|
+
}
|
|
90
|
+
buildReporters(factory, resolved) {
|
|
91
|
+
let upstream;
|
|
92
|
+
let fallbackReporter;
|
|
93
|
+
let disabled = false;
|
|
94
|
+
let upstreamFailed = false;
|
|
103
95
|
try {
|
|
104
|
-
|
|
96
|
+
upstream = factory.create(resolved.effectiveMode, resolved.composed, this.withState);
|
|
105
97
|
}
|
|
106
98
|
catch (error) {
|
|
107
99
|
if (error instanceof disabled_exception_1.DisabledException) {
|
|
108
|
-
|
|
100
|
+
disabled = true;
|
|
109
101
|
}
|
|
110
102
|
else {
|
|
111
103
|
this.logger.logError('Unable to create upstream reporter:', error);
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
return;
|
|
104
|
+
if (resolved.composed.fallback === undefined) {
|
|
105
|
+
disabled = true;
|
|
106
|
+
return { upstream, fallback: fallbackReporter, disabled, useFallbackFromStart: false };
|
|
115
107
|
}
|
|
116
|
-
|
|
108
|
+
upstreamFailed = true;
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
111
|
try {
|
|
120
|
-
|
|
112
|
+
fallbackReporter = factory.create(resolved.effectiveFallback, resolved.composed, this.withState);
|
|
121
113
|
}
|
|
122
114
|
catch (error) {
|
|
123
115
|
if (error instanceof disabled_exception_1.DisabledException) {
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
}
|
|
116
|
+
if (upstreamFailed)
|
|
117
|
+
disabled = true;
|
|
127
118
|
}
|
|
128
119
|
else {
|
|
129
120
|
this.logger.logError('Unable to create fallback reporter:', error);
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (this.withState) {
|
|
136
|
-
if (!state_1.StateManager.isStateExists()) {
|
|
137
|
-
const state = {
|
|
138
|
-
RunId: undefined,
|
|
139
|
-
Mode: this.useFallback ? composedOptions.fallback : composedOptions.mode,
|
|
140
|
-
IsModeChanged: undefined,
|
|
141
|
-
};
|
|
142
|
-
if (this.disabled) {
|
|
143
|
-
state.Mode = options_1.ModeEnum.off;
|
|
144
|
-
}
|
|
145
|
-
state_1.StateManager.setState(state);
|
|
121
|
+
if (upstreamFailed && upstream === undefined)
|
|
122
|
+
disabled = true;
|
|
146
123
|
}
|
|
147
124
|
}
|
|
125
|
+
const useFallbackFromStart = upstreamFailed && fallbackReporter !== undefined;
|
|
126
|
+
return { upstream, fallback: fallbackReporter, disabled, useFallbackFromStart };
|
|
148
127
|
}
|
|
149
|
-
|
|
150
|
-
if (this.
|
|
151
|
-
return
|
|
128
|
+
persistInitialState(resolved, disabled, useFallbackFromStart) {
|
|
129
|
+
if (!this.withState)
|
|
130
|
+
return;
|
|
131
|
+
if (state_1.StateManager.isStateExists())
|
|
132
|
+
return;
|
|
133
|
+
const state = {
|
|
134
|
+
RunId: undefined,
|
|
135
|
+
Mode: useFallbackFromStart
|
|
136
|
+
? resolved.composed.fallback
|
|
137
|
+
: resolved.composed.mode,
|
|
138
|
+
IsModeChanged: undefined,
|
|
139
|
+
};
|
|
140
|
+
if (disabled) {
|
|
141
|
+
state.Mode = options_1.ModeEnum.off;
|
|
152
142
|
}
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
state_1.StateManager.setState(state);
|
|
144
|
+
}
|
|
145
|
+
static getInstance(options) {
|
|
146
|
+
if (!QaseReporter.instance) {
|
|
147
|
+
QaseReporter.instance = new QaseReporter(options);
|
|
155
148
|
}
|
|
156
|
-
return
|
|
149
|
+
return QaseReporter.instance;
|
|
150
|
+
}
|
|
151
|
+
getStatusMapping() {
|
|
152
|
+
return this.options.statusMapping;
|
|
153
|
+
}
|
|
154
|
+
async uploadAttachment(attachment) {
|
|
155
|
+
const result = await this.fallback.run((r) => r.uploadAttachment(attachment), 'upload attachment');
|
|
156
|
+
return result ?? '';
|
|
157
157
|
}
|
|
158
158
|
getResults() {
|
|
159
|
-
if (this.
|
|
159
|
+
if (this.fallback.isDisabled())
|
|
160
160
|
return [];
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return this.upstreamReporter?.getTestResults() ?? [];
|
|
161
|
+
const active = this.fallback.isUsingFallback()
|
|
162
|
+
? this.fallback.getFallback()
|
|
163
|
+
: this.fallback.getUpstream();
|
|
164
|
+
return active?.getTestResults() ?? [];
|
|
166
165
|
}
|
|
167
166
|
setTestResults(results) {
|
|
168
|
-
if (this.
|
|
167
|
+
if (this.fallback.isDisabled())
|
|
169
168
|
return;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.
|
|
173
|
-
|
|
174
|
-
else {
|
|
175
|
-
this.upstreamReporter?.setTestResults(results);
|
|
176
|
-
}
|
|
169
|
+
const active = this.fallback.isUsingFallback()
|
|
170
|
+
? this.fallback.getFallback()
|
|
171
|
+
: this.fallback.getUpstream();
|
|
172
|
+
active?.setTestResults(results);
|
|
177
173
|
}
|
|
178
|
-
async
|
|
179
|
-
if (this.
|
|
174
|
+
async addTestResult(result) {
|
|
175
|
+
if (this.fallback.isDisabled())
|
|
180
176
|
return;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
await this.upstreamReporter?.sendResults();
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
this.logger.logError('Unable to send the results to the upstream reporter:', error);
|
|
187
|
-
if (this.fallbackReporter == undefined) {
|
|
188
|
-
if (this.withState) {
|
|
189
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
190
|
-
}
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (!this.useFallback) {
|
|
194
|
-
this.fallbackReporter.setTestResults(this.upstreamReporter?.getTestResults() ?? []);
|
|
195
|
-
this.useFallback = true;
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
await this.fallbackReporter.sendResults();
|
|
199
|
-
if (this.withState) {
|
|
200
|
-
state_1.StateManager.setMode(this.options.fallback);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
this.logger.logError('Unable to send the results to the fallback reporter:', error);
|
|
205
|
-
if (this.withState) {
|
|
206
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
async complete() {
|
|
212
|
-
if (this.withState) {
|
|
213
|
-
state_1.StateManager.clearState();
|
|
214
|
-
}
|
|
215
|
-
if (this.disabled) {
|
|
177
|
+
const processed = this.statusProcessor.process(result);
|
|
178
|
+
if (!processed)
|
|
216
179
|
return;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
this.logger.logError('Unable to complete the run in the upstream reporter:', error);
|
|
223
|
-
if (this.fallbackReporter == undefined) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (!this.useFallback) {
|
|
227
|
-
this.fallbackReporter.setTestResults(this.upstreamReporter?.getTestResults() ?? []);
|
|
228
|
-
this.useFallback = true;
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
await this.fallbackReporter.complete();
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
this.logger.logError('Unable to complete the run in the fallback reporter:', error);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
180
|
+
await this.startTestRunOperation;
|
|
181
|
+
this.logger.log(resultLogMap[processed.execution.status](processed));
|
|
182
|
+
await this.fallback.run((r) => r.addTestResult(processed), 'add the result');
|
|
237
183
|
}
|
|
238
|
-
/**
|
|
239
|
-
* @returns {void}
|
|
240
|
-
*/
|
|
241
184
|
startTestRun() {
|
|
242
|
-
if (this.withState)
|
|
185
|
+
if (this.withState)
|
|
243
186
|
state_1.StateManager.clearState();
|
|
244
|
-
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
this.startTestRunOperation = this.upstreamReporter?.startTestRun();
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
this.logger.logError('Unable to start test run in the upstream reporter: ', error);
|
|
254
|
-
if (this.fallbackReporter == undefined) {
|
|
255
|
-
this.disabled = true;
|
|
256
|
-
if (this.withState) {
|
|
257
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
258
|
-
}
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
try {
|
|
262
|
-
this.startTestRunOperation = this.fallbackReporter.startTestRun();
|
|
263
|
-
if (this.withState) {
|
|
264
|
-
state_1.StateManager.setMode(this.options.fallback);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
this.logger.logError('Unable to start test run in the fallback reporter: ', error);
|
|
269
|
-
this.disabled = true;
|
|
270
|
-
if (this.withState) {
|
|
271
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
187
|
+
this.fallback.reset();
|
|
188
|
+
this.logger.logDebug('Starting test run');
|
|
189
|
+
const runOp = this.fallback.run(async (r) => {
|
|
190
|
+
await r.startTestRun();
|
|
191
|
+
}, 'start test run');
|
|
192
|
+
this.startTestRunOperation = runOp.then(() => undefined);
|
|
276
193
|
}
|
|
277
194
|
async startTestRunAsync() {
|
|
278
195
|
this.startTestRun();
|
|
279
196
|
await this.startTestRunOperation;
|
|
280
197
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
static getInstance(options) {
|
|
286
|
-
if (!QaseReporter.instance) {
|
|
287
|
-
QaseReporter.instance = new QaseReporter(options);
|
|
288
|
-
}
|
|
289
|
-
return QaseReporter.instance;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get status mapping configuration
|
|
293
|
-
* @returns Status mapping configuration or undefined
|
|
294
|
-
*/
|
|
295
|
-
getStatusMapping() {
|
|
296
|
-
return this.options.statusMapping;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* @param {TestResultType} result
|
|
300
|
-
*/
|
|
301
|
-
async addTestResult(result) {
|
|
302
|
-
if (!this.disabled) {
|
|
303
|
-
// Apply status mapping if configured
|
|
304
|
-
const statusMapping = this.getStatusMapping();
|
|
305
|
-
if (statusMapping) {
|
|
306
|
-
const originalStatus = result.execution.status;
|
|
307
|
-
const mappedStatus = (0, status_mapping_utils_1.applyStatusMapping)(originalStatus, statusMapping);
|
|
308
|
-
if (mappedStatus !== originalStatus) {
|
|
309
|
-
this.logger.logDebug(`Status mapping applied: ${originalStatus} -> ${mappedStatus}`);
|
|
310
|
-
result.execution.status = mappedStatus;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
// Check if result should be filtered out based on status
|
|
314
|
-
if (this.shouldFilterResult(result)) {
|
|
315
|
-
this.logger.logDebug(`Filtering out test result with status: ${result.execution.status}`);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
await this.startTestRunOperation;
|
|
319
|
-
this.logTestItem(result);
|
|
320
|
-
if (this.useFallback) {
|
|
321
|
-
await this.addTestResultToFallback(result);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
try {
|
|
325
|
-
await this.upstreamReporter?.addTestResult(result);
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
this.logger.logError('Unable to add the result to the upstream reporter:', error);
|
|
329
|
-
if (this.fallbackReporter == undefined) {
|
|
330
|
-
this.disabled = true;
|
|
331
|
-
if (this.withState) {
|
|
332
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
333
|
-
}
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
337
|
-
if (!this.useFallback) {
|
|
338
|
-
this.fallbackReporter.setTestResults(this.upstreamReporter?.getTestResults() ?? []);
|
|
339
|
-
this.useFallback = true;
|
|
340
|
-
}
|
|
341
|
-
await this.addTestResultToFallback(result);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* @param {TestResultType} result
|
|
347
|
-
* @private
|
|
348
|
-
*/
|
|
349
|
-
shouldFilterResult(result) {
|
|
350
|
-
const statusFilter = this.options.testops?.statusFilter;
|
|
351
|
-
if (!statusFilter || statusFilter.length === 0) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
// Convert TestStatusEnum to string for comparison
|
|
355
|
-
const statusString = result.execution.status.toString();
|
|
356
|
-
this.logger.logDebug(`Checking filter: status="${statusString}", filter=${JSON.stringify(statusFilter)}`);
|
|
357
|
-
// Check if the status is in the filter list
|
|
358
|
-
const shouldFilter = statusFilter.includes(statusString);
|
|
359
|
-
this.logger.logDebug(`Filter result: ${shouldFilter ? 'FILTERED' : 'NOT FILTERED'}`);
|
|
360
|
-
return shouldFilter;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* @param {TestResultType} result
|
|
364
|
-
* @private
|
|
365
|
-
*/
|
|
366
|
-
async addTestResultToFallback(result) {
|
|
367
|
-
try {
|
|
368
|
-
await this.fallbackReporter?.addTestResult(result);
|
|
369
|
-
if (this.withState) {
|
|
370
|
-
state_1.StateManager.setMode(this.options.fallback);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
catch (error) {
|
|
374
|
-
this.logger.logError('Unable to add the result to the fallback reporter:', error);
|
|
375
|
-
this.disabled = true;
|
|
376
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* @returns {boolean}
|
|
381
|
-
*/
|
|
382
|
-
isCaptureLogs() {
|
|
383
|
-
return this.captureLogs ?? false;
|
|
198
|
+
async sendResults() {
|
|
199
|
+
if (this.fallback.isDisabled())
|
|
200
|
+
return;
|
|
201
|
+
await this.fallback.run((r) => r.sendResults(), 'send the results');
|
|
384
202
|
}
|
|
385
|
-
/**
|
|
386
|
-
* @returns {Promise<void>}
|
|
387
|
-
*/
|
|
388
203
|
async publish() {
|
|
389
|
-
if (!this.
|
|
204
|
+
if (!this.fallback.isDisabled()) {
|
|
390
205
|
await this.startTestRunOperation;
|
|
391
206
|
this.logger.logDebug('Publishing test run results');
|
|
392
|
-
|
|
393
|
-
await this.publishFallback();
|
|
394
|
-
}
|
|
395
|
-
try {
|
|
396
|
-
await this.upstreamReporter?.publish();
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
this.logger.logError('Unable to publish the run results to the upstream reporter:', error);
|
|
400
|
-
if (this.fallbackReporter == undefined) {
|
|
401
|
-
this.disabled = true;
|
|
402
|
-
if (this.withState) {
|
|
403
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
404
|
-
}
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (!this.useFallback) {
|
|
408
|
-
this.fallbackReporter.setTestResults(this.upstreamReporter?.getTestResults() ?? []);
|
|
409
|
-
this.useFallback = true;
|
|
410
|
-
}
|
|
411
|
-
await this.publishFallback();
|
|
412
|
-
}
|
|
207
|
+
await this.fallback.run((r) => r.publish(), 'publish the run results');
|
|
413
208
|
}
|
|
414
|
-
if (this.withState)
|
|
209
|
+
if (this.withState)
|
|
415
210
|
state_1.StateManager.clearState();
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* @returns {Promise<void>}
|
|
420
|
-
*/
|
|
421
|
-
async publishFallback() {
|
|
422
|
-
try {
|
|
423
|
-
await this.fallbackReporter?.publish();
|
|
424
|
-
if (this.withState) {
|
|
425
|
-
state_1.StateManager.setMode(this.options.fallback);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
catch (error) {
|
|
429
|
-
if (this.withState) {
|
|
430
|
-
state_1.StateManager.setMode(options_1.ModeEnum.off);
|
|
431
|
-
}
|
|
432
|
-
this.logger.logError('Unable to publish the run results to the fallback reporter:', error);
|
|
433
|
-
this.disabled = true;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* @todo implement mode registry
|
|
438
|
-
* @param {ModeEnum} mode
|
|
439
|
-
* @param {OptionsType} options
|
|
440
|
-
* @returns {InternalReporterInterface}
|
|
441
|
-
* @private
|
|
442
|
-
*/
|
|
443
|
-
createReporter(mode, options) {
|
|
444
|
-
switch (mode) {
|
|
445
|
-
case options_1.ModeEnum.testops: {
|
|
446
|
-
if (!options.testops?.api?.token) {
|
|
447
|
-
throw new Error(`Either "testops.api.token" parameter or "${env_1.EnvApiEnum.token}" environment variable is required in "testops" mode`);
|
|
448
|
-
}
|
|
449
|
-
if (!options.testops.project) {
|
|
450
|
-
throw new Error(`Either "testops.project" parameter or "${env_1.EnvTestOpsEnum.project}" environment variable is required in "testops" mode`);
|
|
451
|
-
}
|
|
452
|
-
const apiClient = new clientV2_1.ClientV2(this.logger, options.testops, options.environment, options.rootSuite, this.hostData, options.reporterName, options.frameworkPackage);
|
|
453
|
-
return new reporters_1.TestOpsReporter(this.logger, apiClient, this.withState, options.testops.project, options.testops.api.host, options.testops.batch?.size, options.testops.run?.id, options.testops.showPublicReportLink);
|
|
454
|
-
}
|
|
455
|
-
case options_1.ModeEnum.testops_multi: {
|
|
456
|
-
if (!options.testops?.api?.token) {
|
|
457
|
-
throw new Error(`Either "testops.api.token" parameter or "${env_1.EnvApiEnum.token}" environment variable is required in "testops_multi" mode`);
|
|
458
|
-
}
|
|
459
|
-
const multi = options.testops_multi;
|
|
460
|
-
if (!multi?.projects?.length) {
|
|
461
|
-
throw new Error('"testops_multi.projects" must contain at least one project with a "code" field');
|
|
462
|
-
}
|
|
463
|
-
for (const p of multi.projects) {
|
|
464
|
-
if (!p?.code) {
|
|
465
|
-
throw new Error('Each project in "testops_multi.projects" must have a "code" field');
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return new reporters_1.TestOpsMultiReporter(this.logger, options.testops, multi, this.withState, this.hostData, options.reporterName, options.frameworkPackage, options.environment, options.testops.api?.host, options.testops.batch?.size, options.testops.showPublicReportLink);
|
|
469
|
-
}
|
|
470
|
-
case options_1.ModeEnum.report: {
|
|
471
|
-
const localOptions = options.report?.connections?.[writer_1.DriverEnum.local];
|
|
472
|
-
const writer = new writer_1.FsWriter(localOptions);
|
|
473
|
-
return new reporters_1.ReportReporter(this.logger, writer, options.frameworkPackage, options.reporterName, options.environment, options.rootSuite, options.testops?.run?.id, this.hostData);
|
|
474
|
-
}
|
|
475
|
-
case options_1.ModeEnum.off:
|
|
476
|
-
throw new disabled_exception_1.DisabledException();
|
|
477
|
-
default:
|
|
478
|
-
throw new Error(`Unknown mode type`);
|
|
479
|
-
}
|
|
480
211
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
this.
|
|
487
|
-
}
|
|
488
|
-
setWithState(options) {
|
|
489
|
-
return options.frameworkName === 'cypress' || !options.frameworkName;
|
|
490
|
-
}
|
|
491
|
-
maskToken(token) {
|
|
492
|
-
if (token.length <= 7) {
|
|
493
|
-
return '*'.repeat(token.length);
|
|
494
|
-
}
|
|
495
|
-
return `${token.slice(0, 3)}****${token.slice(-4)}`;
|
|
212
|
+
async complete() {
|
|
213
|
+
if (this.withState)
|
|
214
|
+
state_1.StateManager.clearState();
|
|
215
|
+
if (this.fallback.isDisabled())
|
|
216
|
+
return;
|
|
217
|
+
await this.fallback.run((r) => r.complete(), 'complete the run');
|
|
496
218
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (sanitized.testops?.api?.token) {
|
|
500
|
-
sanitized.testops.api.token = this.maskToken(sanitized.testops.api.token);
|
|
501
|
-
}
|
|
502
|
-
return sanitized;
|
|
219
|
+
isCaptureLogs() {
|
|
220
|
+
return this.captureLogs ?? false;
|
|
503
221
|
}
|
|
504
222
|
}
|
|
505
223
|
exports.QaseReporter = QaseReporter;
|