qase-javascript-commons 2.2.10 → 2.2.11

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 CHANGED
@@ -1,3 +1,10 @@
1
+ # qase-javascript-commons@2.2.11
2
+
3
+ ## What's new
4
+
5
+ - Improved state manager behavior to ensure correct handling.
6
+ - Masked token in logs to enhance security.
7
+
1
8
  # qase-javascript-commons@2.2.10
2
9
 
3
10
  ## What's new
package/dist/qase.d.ts CHANGED
@@ -51,6 +51,7 @@ export declare class QaseReporter implements ReporterInterface {
51
51
  private readonly logger;
52
52
  private startTestRunOperation?;
53
53
  private options;
54
+ private withState;
54
55
  /**
55
56
  * @param {OptionsType} options
56
57
  */
@@ -103,4 +104,7 @@ export declare class QaseReporter implements ReporterInterface {
103
104
  * @private
104
105
  */
105
106
  private logTestItem;
107
+ private setWithState;
108
+ private maskToken;
109
+ private sanitizeOptions;
106
110
  }
package/dist/qase.js CHANGED
@@ -95,24 +95,28 @@ class QaseReporter {
95
95
  logger;
96
96
  startTestRunOperation;
97
97
  options;
98
+ withState;
98
99
  /**
99
100
  * @param {OptionsType} options
100
101
  */
101
102
  constructor(options) {
102
- if (state_1.StateManager.isStateExists()) {
103
- const state = state_1.StateManager.getState();
104
- if (state.IsModeChanged && state.Mode) {
105
- process.env[env_1.EnvEnum.mode] = state.Mode.toString();
106
- }
107
- if (state.RunId) {
108
- process.env[env_1.EnvRunEnum.id] = state.RunId.toString();
103
+ this.withState = this.setWithState(options);
104
+ if (this.withState) {
105
+ if (state_1.StateManager.isStateExists()) {
106
+ const state = state_1.StateManager.getState();
107
+ if (state.IsModeChanged && state.Mode) {
108
+ process.env[env_1.EnvEnum.mode] = state.Mode.toString();
109
+ }
110
+ if (state.RunId) {
111
+ process.env[env_1.EnvRunEnum.id] = state.RunId.toString();
112
+ }
109
113
  }
110
114
  }
111
115
  const env = (0, env_1.envToConfig)((0, env_schema_1.default)({ schema: env_1.envValidationSchema }));
112
116
  const composedOptions = (0, options_1.composeOptions)(options, env);
113
117
  this.options = composedOptions;
114
118
  this.logger = new logger_1.Logger({ debug: composedOptions.debug });
115
- this.logger.logDebug(`Config: ${JSON.stringify(composedOptions)}`);
119
+ this.logger.logDebug(`Config: ${JSON.stringify(this.sanitizeOptions(composedOptions))}`);
116
120
  this.captureLogs = composedOptions.captureLogs;
117
121
  try {
118
122
  this.upstreamReporter = this.createReporter(
@@ -150,16 +154,18 @@ class QaseReporter {
150
154
  }
151
155
  }
152
156
  }
153
- if (!state_1.StateManager.isStateExists()) {
154
- const state = {
155
- RunId: undefined,
156
- Mode: this.useFallback ? composedOptions.fallback : composedOptions.mode,
157
- IsModeChanged: undefined,
158
- };
159
- if (this.disabled) {
160
- state.Mode = options_1.ModeEnum.off;
157
+ if (this.withState) {
158
+ if (!state_1.StateManager.isStateExists()) {
159
+ const state = {
160
+ RunId: undefined,
161
+ Mode: this.useFallback ? composedOptions.fallback : composedOptions.mode,
162
+ IsModeChanged: undefined,
163
+ };
164
+ if (this.disabled) {
165
+ state.Mode = options_1.ModeEnum.off;
166
+ }
167
+ state_1.StateManager.setState(state);
161
168
  }
162
- state_1.StateManager.setState(state);
163
169
  }
164
170
  }
165
171
  getResults() {
@@ -192,7 +198,9 @@ class QaseReporter {
192
198
  catch (error) {
193
199
  this.logger.logError('Unable to send the results to the upstream reporter:', error);
194
200
  if (this.fallbackReporter == undefined) {
195
- state_1.StateManager.setMode(options_1.ModeEnum.off);
201
+ if (this.withState) {
202
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
203
+ }
196
204
  return;
197
205
  }
198
206
  if (!this.useFallback) {
@@ -201,16 +209,22 @@ class QaseReporter {
201
209
  }
202
210
  try {
203
211
  await this.fallbackReporter?.sendResults();
204
- state_1.StateManager.setMode(this.options.fallback);
212
+ if (this.withState) {
213
+ state_1.StateManager.setMode(this.options.fallback);
214
+ }
205
215
  }
206
216
  catch (error) {
207
217
  this.logger.logError('Unable to send the results to the fallback reporter:', error);
208
- state_1.StateManager.setMode(options_1.ModeEnum.off);
218
+ if (this.withState) {
219
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
220
+ }
209
221
  }
210
222
  }
211
223
  }
212
224
  async complete() {
213
- state_1.StateManager.clearState();
225
+ if (this.withState) {
226
+ state_1.StateManager.clearState();
227
+ }
214
228
  if (this.disabled) {
215
229
  return;
216
230
  }
@@ -238,6 +252,10 @@ class QaseReporter {
238
252
  * @returns {void}
239
253
  */
240
254
  startTestRun() {
255
+ if (this.withState) {
256
+ console.log("Clean state");
257
+ state_1.StateManager.clearState();
258
+ }
241
259
  if (!this.disabled) {
242
260
  this.logger.logDebug('Starting test run');
243
261
  try {
@@ -247,17 +265,23 @@ class QaseReporter {
247
265
  this.logger.logError('Unable to start test run in the upstream reporter: ', error);
248
266
  if (this.fallbackReporter == undefined) {
249
267
  this.disabled = true;
250
- state_1.StateManager.setMode(options_1.ModeEnum.off);
268
+ if (this.withState) {
269
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
270
+ }
251
271
  return;
252
272
  }
253
273
  try {
254
274
  this.startTestRunOperation = this.fallbackReporter?.startTestRun();
255
- state_1.StateManager.setMode(this.options.fallback);
275
+ if (this.withState) {
276
+ state_1.StateManager.setMode(this.options.fallback);
277
+ }
256
278
  }
257
279
  catch (error) {
258
280
  this.logger.logError('Unable to start test run in the fallback reporter: ', error);
259
281
  this.disabled = true;
260
- state_1.StateManager.setMode(options_1.ModeEnum.off);
282
+ if (this.withState) {
283
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
284
+ }
261
285
  }
262
286
  }
263
287
  }
@@ -294,7 +318,9 @@ class QaseReporter {
294
318
  this.logger.logError('Unable to add the result to the upstream reporter:', error);
295
319
  if (this.fallbackReporter == undefined) {
296
320
  this.disabled = true;
297
- state_1.StateManager.setMode(options_1.ModeEnum.off);
321
+ if (this.withState) {
322
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
323
+ }
298
324
  return;
299
325
  }
300
326
  if (!this.useFallback) {
@@ -312,7 +338,9 @@ class QaseReporter {
312
338
  async addTestResultToFallback(result) {
313
339
  try {
314
340
  await this.fallbackReporter?.addTestResult(result);
315
- state_1.StateManager.setMode(this.options.fallback);
341
+ if (this.withState) {
342
+ state_1.StateManager.setMode(this.options.fallback);
343
+ }
316
344
  }
317
345
  catch (error) {
318
346
  this.logger.logError('Unable to add the result to the fallback reporter:', error);
@@ -343,7 +371,9 @@ class QaseReporter {
343
371
  this.logger.logError('Unable to publish the run results to the upstream reporter:', error);
344
372
  if (this.fallbackReporter == undefined) {
345
373
  this.disabled = true;
346
- state_1.StateManager.setMode(options_1.ModeEnum.off);
374
+ if (this.withState) {
375
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
376
+ }
347
377
  return;
348
378
  }
349
379
  if (!this.useFallback) {
@@ -353,7 +383,9 @@ class QaseReporter {
353
383
  await this.publishFallback();
354
384
  }
355
385
  }
356
- state_1.StateManager.clearState();
386
+ if (this.withState) {
387
+ state_1.StateManager.clearState();
388
+ }
357
389
  }
358
390
  /**
359
391
  * @returns {Promise<void>}
@@ -361,10 +393,14 @@ class QaseReporter {
361
393
  async publishFallback() {
362
394
  try {
363
395
  await this.fallbackReporter?.publish();
364
- state_1.StateManager.setMode(this.options.fallback);
396
+ if (this.withState) {
397
+ state_1.StateManager.setMode(this.options.fallback);
398
+ }
365
399
  }
366
400
  catch (error) {
367
- state_1.StateManager.setMode(options_1.ModeEnum.off);
401
+ if (this.withState) {
402
+ state_1.StateManager.setMode(options_1.ModeEnum.off);
403
+ }
368
404
  this.logger.logError('Unable to publish the run results to the fallback reporter:', error);
369
405
  this.disabled = true;
370
406
  }
@@ -407,7 +443,7 @@ class QaseReporter {
407
443
  batch,
408
444
  useV2,
409
445
  defect,
410
- }, apiClient, environment, rootSuite, api.host);
446
+ }, apiClient, this.withState, environment, rootSuite, api.host);
411
447
  }
412
448
  case options_1.ModeEnum.report: {
413
449
  const localOptions = report.connections?.[writer_1.DriverEnum.local];
@@ -427,5 +463,38 @@ class QaseReporter {
427
463
  logTestItem(test) {
428
464
  this.logger.log(resultLogMap[test.execution.status](test));
429
465
  }
466
+ setWithState(options) {
467
+ return options.frameworkName == 'cypress'
468
+ || options.frameworkName == ''
469
+ || options.frameworkName == null
470
+ || options.frameworkName == undefined;
471
+ }
472
+ maskToken(token) {
473
+ if (token.length <= 7) {
474
+ return '*'.repeat(token.length);
475
+ }
476
+ return `${token.slice(0, 3)}****${token.slice(-4)}`;
477
+ }
478
+ sanitizeOptions(options) {
479
+ if (typeof options !== 'object' || options === null) {
480
+ return options;
481
+ }
482
+ const sanitizedObject = {};
483
+ for (const key in options) {
484
+ if (Object.prototype.hasOwnProperty.call(options, key)) {
485
+ const value = options[key];
486
+ if (key === 'token' && typeof value === 'string') {
487
+ sanitizedObject[key] = this.maskToken(value);
488
+ }
489
+ else if (typeof value === 'object' && value !== null) {
490
+ sanitizedObject[key] = this.sanitizeOptions(value);
491
+ }
492
+ else {
493
+ sanitizedObject[key] = value;
494
+ }
495
+ }
496
+ }
497
+ return sanitizedObject;
498
+ }
430
499
  }
431
500
  exports.QaseReporter = QaseReporter;
@@ -29,6 +29,7 @@ export interface TestOpsOptionsType {
29
29
  */
30
30
  export declare class TestOpsReporter extends AbstractReporter {
31
31
  private api;
32
+ private withState;
32
33
  /**
33
34
  * @type {Record<TestStatusEnum, string>}
34
35
  */
@@ -105,11 +106,12 @@ export declare class TestOpsReporter extends AbstractReporter {
105
106
  * @param {LoggerInterface} logger
106
107
  * @param {ReporterOptionsType & TestOpsOptionsType} options
107
108
  * @param {QaseApiInterface} api
109
+ * @param {boolean} withState
108
110
  * @param {string | undefined} environment
109
111
  * @param {string | undefined} rootSuite
110
112
  * @param {string | undefined} baseUrl
111
113
  */
112
- constructor(logger: LoggerInterface, options: TestOpsOptionsType, api: QaseApiInterface, environment?: string, rootSuite?: string, baseUrl?: string);
114
+ constructor(logger: LoggerInterface, options: TestOpsOptionsType, api: QaseApiInterface, withState: boolean, environment?: string, rootSuite?: string, baseUrl?: string);
113
115
  /**
114
116
  * @returns {Promise<void>}
115
117
  */
@@ -19,6 +19,7 @@ const defaultChunkSize = 200;
19
19
  */
20
20
  class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
21
21
  api;
22
+ withState;
22
23
  /**
23
24
  * @type {Record<TestStatusEnum, string>}
24
25
  */
@@ -112,14 +113,16 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
112
113
  * @param {LoggerInterface} logger
113
114
  * @param {ReporterOptionsType & TestOpsOptionsType} options
114
115
  * @param {QaseApiInterface} api
116
+ * @param {boolean} withState
115
117
  * @param {string | undefined} environment
116
118
  * @param {string | undefined} rootSuite
117
119
  * @param {string | undefined} baseUrl
118
120
  */
119
- constructor(logger, options, api, environment, rootSuite, baseUrl) {
121
+ constructor(logger, options, api, withState, environment, rootSuite, baseUrl) {
120
122
  const { project, uploadAttachments, run, plan, } = options;
121
123
  super(logger);
122
124
  this.api = api;
125
+ this.withState = withState;
123
126
  this.baseUrl = this.getBaseUrl(baseUrl);
124
127
  this.projectCode = project;
125
128
  this.isUploadAttachments = uploadAttachments;
@@ -188,7 +191,9 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
188
191
  this.logger.logDebug(`Test run created: ${result.id}`);
189
192
  this.run.id = result.id;
190
193
  process.env['QASE_TESTOPS_RUN_ID'] = String(result.id);
191
- state_1.StateManager.setRunId(result.id);
194
+ if (this.withState) {
195
+ state_1.StateManager.setRunId(result.id);
196
+ }
192
197
  this.isTestRunReady = true;
193
198
  }
194
199
  /**
@@ -7,13 +7,16 @@ exports.StateManager = void 0;
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  class StateManager {
10
- static statePath = path_1.default.resolve(process.cwd(), 'reporterState.json');
10
+ static statePath = path_1.default.resolve(__dirname, 'reporterState.json');
11
11
  static getState() {
12
12
  let state = {
13
13
  RunId: undefined,
14
14
  Mode: undefined,
15
15
  IsModeChanged: undefined,
16
16
  };
17
+ if (!this.isStateExists()) {
18
+ return state;
19
+ }
17
20
  try {
18
21
  const data = (0, fs_1.readFileSync)(this.statePath, 'utf8');
19
22
  state = JSON.parse(data);
@@ -49,6 +52,9 @@ class StateManager {
49
52
  }
50
53
  }
51
54
  static clearState() {
55
+ if (!this.isStateExists()) {
56
+ return;
57
+ }
52
58
  try {
53
59
  (0, fs_1.unlinkSync)(this.statePath);
54
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.2.10",
3
+ "version": "2.2.11",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",