mocha-qase-reporter 1.1.6 → 1.1.8

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,9 @@
1
+ # qase-mocha@1.1.8
2
+
3
+ ## What's new
4
+
5
+ - Added support for expected results and data for steps.
6
+
1
7
  # qase-mocha@1.1.6
2
8
 
3
9
  ## What's new
@@ -83,19 +83,14 @@ function createExtraReporters(runner, options, extraReportersConfig) {
83
83
  // Create reporter instance with clean options (without main reporter options)
84
84
  const cleanOptions = {
85
85
  ...options,
86
- // Remove main reporter specific options
86
+ // Remove main reporter property
87
87
  reporter: undefined,
88
- reporterOptions: undefined,
89
- 'reporter-option': undefined,
90
- reporterOption: undefined,
91
- // Add extra reporter specific options
92
- ...reporterOptions
88
+ // Add extra reporter specific options to all reporter option properties
89
+ // This ensures compatibility with different reporters that may expect different property names
90
+ reporterOptions,
91
+ reporterOption: reporterOptions,
92
+ 'reporter-option': reporterOptions
93
93
  };
94
- // Special handling for JSON reporter
95
- if (reporterName === 'json' && reporterOptions['output']) {
96
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
97
- cleanOptions.reporterOption = { output: reporterOptions['output'] };
98
- }
99
94
  const reporter = new ReporterClass(runner, cleanOptions);
100
95
  reporters.push(reporter);
101
96
  }
@@ -66,7 +66,7 @@ export declare class MochaQaseReporter extends reporters.Base {
66
66
  contentType?: string;
67
67
  }) => void;
68
68
  comment: (message: string) => void;
69
- step: (title: string, func: () => void) => void;
69
+ step: (title: string, func: () => void, expectedResult?: string, data?: string) => void;
70
70
  /**
71
71
  * @param {string} title
72
72
  * @returns {string}
@@ -83,5 +83,12 @@ export declare class MochaQaseReporter extends reporters.Base {
83
83
  * @private
84
84
  */
85
85
  private static getCaseId;
86
+ /**
87
+ * Extract expected result and data from step title and return cleaned string
88
+ * @param {string} input
89
+ * @returns {{expectedResult: string | null, data: string | null, cleanedString: string}}
90
+ * @private
91
+ */
92
+ private extractAndCleanStep;
86
93
  }
87
94
  export {};
package/dist/reporter.js CHANGED
@@ -129,11 +129,9 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
129
129
  output.stderr += data;
130
130
  this.testOutputs.set(test.title, output);
131
131
  });
132
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
133
- // @ts-expect-error
132
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
134
133
  process.stdout.write = stdoutInterceptor.write.bind(stdoutInterceptor);
135
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
136
- // @ts-expect-error
134
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
137
135
  process.stderr.write = stderrInterceptor.write.bind(stderrInterceptor);
138
136
  this.testOutputs.set(test.title, { stdout: '', stderr: '' });
139
137
  this.addMethodsToContext(test.ctx);
@@ -311,15 +309,19 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
311
309
  comment = (message) => {
312
310
  this.metadata.addComment(message);
313
311
  };
314
- step = (title, func) => {
312
+ step = (title, func, expectedResult, data) => {
315
313
  const previousType = this.currentType;
316
314
  this.currentType = 'step';
315
+ const stepTitle = expectedResult || data
316
+ ? `${title} QaseExpRes:${expectedResult ? `: ${expectedResult}` : ''} QaseData:${data ? `: ${data}` : ''}`
317
+ : title;
318
+ const stepData = this.extractAndCleanStep(stepTitle);
317
319
  const step = {
318
320
  step_type: qase_javascript_commons_1.StepType.TEXT,
319
321
  data: {
320
- action: title,
321
- expected_result: null,
322
- data: null,
322
+ action: stepData.cleanedString,
323
+ expected_result: stepData.expectedResult,
324
+ data: stepData.data,
323
325
  },
324
326
  execution: {
325
327
  start_time: Date.now(),
@@ -368,5 +370,31 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
368
370
  const [, ids] = title.match(MochaQaseReporter.qaseIdRegExp) ?? [];
369
371
  return ids ? ids.split(',').map((id) => Number(id)) : [];
370
372
  }
373
+ /**
374
+ * Extract expected result and data from step title and return cleaned string
375
+ * @param {string} input
376
+ * @returns {{expectedResult: string | null, data: string | null, cleanedString: string}}
377
+ * @private
378
+ */
379
+ extractAndCleanStep(input) {
380
+ let expectedResult = null;
381
+ let data = null;
382
+ let cleanedString = input;
383
+ const hasExpectedResult = input.includes('QaseExpRes:');
384
+ const hasData = input.includes('QaseData:');
385
+ if (hasExpectedResult || hasData) {
386
+ const regex = /QaseExpRes:\s*:?\s*(.*?)\s*(?=QaseData:|$)QaseData:\s*:?\s*(.*)?/;
387
+ const match = input.match(regex);
388
+ if (match) {
389
+ expectedResult = match[1]?.trim() ?? null;
390
+ data = match[2]?.trim() ?? null;
391
+ cleanedString = input
392
+ .replace(/QaseExpRes:\s*:?\s*.*?(?=QaseData:|$)/, '')
393
+ .replace(/QaseData:\s*:?\s*.*/, '')
394
+ .trim();
395
+ }
396
+ }
397
+ return { expectedResult, data, cleanedString };
398
+ }
371
399
  }
372
400
  exports.MochaQaseReporter = MochaQaseReporter;
package/dist/types.d.ts CHANGED
@@ -29,7 +29,7 @@ export interface Methods {
29
29
  contentType?: string;
30
30
  }): void;
31
31
  comment(message: string): void;
32
- step(title: string, func: () => void): void;
32
+ step(title: string, func: () => void, expectedResult?: string, data?: string): void;
33
33
  }
34
34
  export declare class Metadata {
35
35
  ids?: number[];
package/docs/usage.md CHANGED
@@ -184,7 +184,7 @@ describe('User Authentication', function() {
184
184
  ## Adding Steps to a Test
185
185
 
186
186
  You can add custom steps to your test cases using the `this.step()` method. Each step should
187
- have a title and optionally a function.
187
+ have a title and optionally a function. You can also provide an expected result and input data for each step, which will be displayed in Qase.
188
188
 
189
189
  ### Example
190
190
 
@@ -210,6 +210,26 @@ describe('User Authentication', function() {
210
210
  });
211
211
  ```
212
212
 
213
+ ### Example with Expected Result and Data
214
+
215
+ ```javascript
216
+ const { qase } = require('mocha-qase-reporter/mocha');
217
+
218
+ describe('User Authentication', function() {
219
+ it('test with steps including expected results and data', function() {
220
+ this.step('Click button', function() {
221
+ // Click action
222
+ }, 'Button should be clicked', 'Button data');
223
+
224
+ this.step('Fill form', function() {
225
+ // Form filling action
226
+ }, 'Form should be filled', 'Form input data');
227
+
228
+ expect(true).to.equal(true);
229
+ });
230
+ });
231
+ ```
232
+
213
233
  ---
214
234
 
215
235
  ## Attaching Files to a Test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha-qase-reporter",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Mocha Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,
@@ -41,19 +41,19 @@
41
41
  "author": "Qase Team <support@qase.io>",
42
42
  "license": "Apache-2.0",
43
43
  "dependencies": {
44
- "mocha": "^11.0.0",
44
+ "mocha": "^11.7.5",
45
45
  "deasync-promise": "^1.0.1",
46
- "qase-javascript-commons": "~2.4.8",
46
+ "qase-javascript-commons": "~2.4.13",
47
47
  "uuid": "^9.0.1"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/deasync-promise": "^1.0.2",
51
- "@types/mocha": "^10.0.1",
52
- "@types/node": "^20.2.4",
53
- "@types/request": "^2.48.8",
54
- "@typescript-eslint/eslint-plugin": "^5.59.7",
55
- "@typescript-eslint/parser": "^5.59.7",
56
- "eslint": "^8.41.0",
51
+ "@types/mocha": "^10.0.10",
52
+ "@types/node": "^20.19.25",
53
+ "@types/request": "^2.48.13",
54
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
55
+ "@typescript-eslint/parser": "^5.62.0",
56
+ "eslint": "^8.57.1",
57
57
  "prettier": "^2.8.8"
58
58
  }
59
59
  }
@@ -2,7 +2,9 @@
2
2
  "extends": "./tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
- "noEmit": false
5
+ "noEmit": false,
6
+ "skipLibCheck": true,
7
+ "types": []
6
8
  },
7
9
 
8
10
  "include": ["./src/**/*.ts"]