mocha-qase-reporter 1.1.8 → 1.2.0

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/README.md CHANGED
@@ -67,6 +67,12 @@ A test run will be performed and available at:
67
67
  https://app.qase.io/run/QASE_PROJECT_CODE
68
68
  ```
69
69
 
70
+ ### Multi-Project Support
71
+
72
+ Qase Mocha Reporter supports sending test results to multiple Qase projects simultaneously. You can specify different test case IDs for each project using `qase.projects(mapping, name)`.
73
+
74
+ For detailed information, configuration, and examples, see the [Multi-Project Support Guide](docs/MULTI_PROJECT.md).
75
+
70
76
  ### Parallel execution
71
77
 
72
78
  The reporter supports parallel execution of tests.
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-mocha@1.2.0
2
+
3
+ ## What's new
4
+
5
+ - Added support for multi-project support.
6
+
1
7
  # qase-mocha@1.1.8
2
8
 
3
9
  ## What's new
package/dist/mocha.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /** Project code → test case IDs for multi-project (testops_multi) mode. */
2
+ export type ProjectMapping = Record<string, number[]>;
1
3
  /**
2
4
  * Set IDs for the test case
3
5
  *
@@ -9,4 +11,7 @@
9
11
  * });
10
12
  * @returns {string}
11
13
  */
12
- export declare const qase: (caseId: number | string | number[] | string[], name: string) => string;
14
+ export declare const qase: {
15
+ (caseId: number | string | number[] | string[], name: string): string;
16
+ projects(mapping: ProjectMapping, name: string): string;
17
+ };
package/dist/mocha.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.qase = void 0;
4
+ const qase_javascript_commons_1 = require("qase-javascript-commons");
4
5
  /**
5
6
  * Set IDs for the test case
6
7
  *
@@ -30,3 +31,12 @@ const qase = (caseId, name) => {
30
31
  return `${name} (Qase ID: ${caseIds.join(',')})`;
31
32
  };
32
33
  exports.qase = qase;
34
+ /**
35
+ * Build test name with multi-project markers (for testops_multi mode).
36
+ * @param mapping — e.g. { PROJ1: [1, 2], PROJ2: [3] }
37
+ * @param name — test title
38
+ * @example it(qase.projects({ PROJ1: [100], PROJ2: [200] }, 'Login flow'), function() { ... });
39
+ */
40
+ exports.qase.projects = (mapping, name) => {
41
+ return (0, qase_javascript_commons_1.formatTitleWithProjectMapping)(name, mapping);
42
+ };
@@ -76,13 +76,8 @@ export declare class MochaQaseReporter extends reporters.Base {
76
76
  /**
77
77
  * @type {RegExp}
78
78
  */
79
+ /** @deprecated Use parseProjectMappingFromTitle from qase-javascript-commons for multi-project support. */
79
80
  static qaseIdRegExp: RegExp;
80
- /**
81
- * @param {string} title
82
- * @returns {number[]}
83
- * @private
84
- */
85
- private static getCaseId;
86
81
  /**
87
82
  * Extract expected result and data from step title and return cleaned string
88
83
  * @param {string} input
package/dist/reporter.js CHANGED
@@ -159,10 +159,12 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
159
159
  this.currentTest = new currentTest();
160
160
  return;
161
161
  }
162
+ const fromTitle = (0, qase_javascript_commons_1.parseProjectMappingFromTitle)(test.title);
162
163
  const ids = this.getQaseId();
163
164
  if (ids.length === 0) {
164
- ids.push(...MochaQaseReporter.getCaseId(test.title));
165
+ ids.push(...fromTitle.legacyIds);
165
166
  }
167
+ const hasProjectMapping = Object.keys(fromTitle.projectMapping).length > 0;
166
168
  const suites = this.getSuites(test);
167
169
  let relations = {};
168
170
  if (suites.length > 0) {
@@ -193,7 +195,7 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
193
195
  group_params: this.metadata.groupParameters ?? {},
194
196
  relations: relations,
195
197
  run_id: null,
196
- signature: this.getSignature(test, ids, this.metadata.parameters ?? {}),
198
+ signature: this.getSignature(test, hasProjectMapping ? [] : ids, this.metadata.parameters ?? {}),
197
199
  steps: this.currentTest.steps,
198
200
  id: (0, uuid_1.v4)(),
199
201
  execution: {
@@ -204,8 +206,9 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
204
206
  stacktrace: test.err?.stack ?? null,
205
207
  thread: null,
206
208
  },
207
- testops_id: ids.length > 0 ? ids : null,
208
- title: this.metadata.title && this.metadata.title != '' ? this.metadata.title : this.removeQaseIdsFromTitle(test.title),
209
+ testops_id: hasProjectMapping ? null : (ids.length > 0 ? ids : null),
210
+ testops_project_mapping: hasProjectMapping ? fromTitle.projectMapping : null,
211
+ title: this.metadata.title && this.metadata.title != '' ? this.metadata.title : (fromTitle.cleanedTitle || this.removeQaseIdsFromTitle(test.title)),
209
212
  };
210
213
  void this.reporter.addTestResult(result);
211
214
  this.metadata.clear();
@@ -360,16 +363,8 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
360
363
  /**
361
364
  * @type {RegExp}
362
365
  */
366
+ /** @deprecated Use parseProjectMappingFromTitle from qase-javascript-commons for multi-project support. */
363
367
  static qaseIdRegExp = /\(Qase ID: ([\d,]+)\)/;
364
- /**
365
- * @param {string} title
366
- * @returns {number[]}
367
- * @private
368
- */
369
- static getCaseId(title) {
370
- const [, ids] = title.match(MochaQaseReporter.qaseIdRegExp) ?? [];
371
- return ids ? ids.split(',').map((id) => Number(id)) : [];
372
- }
373
368
  /**
374
369
  * Extract expected result and data from step title and return cleaned string
375
370
  * @param {string} input
@@ -0,0 +1,53 @@
1
+ # Multi-Project Support in Mocha
2
+
3
+ Qase Mocha Reporter supports sending test results to multiple Qase projects simultaneously. This feature allows you to report the same test execution to different projects with different test case IDs, which is useful when:
4
+
5
+ * You need to report the same test to different projects
6
+ * Different projects track the same functionality with different test case IDs
7
+ * You want to maintain separate test runs for different environments or teams
8
+
9
+ ## Configuration
10
+
11
+ For detailed configuration options, refer to the [qase-javascript-commons README](../../qase-javascript-commons/README.md#multi-project-support).
12
+
13
+ ### Basic Multi-Project Configuration
14
+
15
+ Set `mode` to `testops_multi` in your Mocha reporter options (e.g. in `.mocharc.js` or `qase.config.json`) and add the `testops_multi` section with `default_project` and `projects`.
16
+
17
+ ## Using `qase.projects(mapping, name)`
18
+
19
+ Use `qase.projects(mapping, name)` to set the test title with multi-project markers. Use the returned string as the first argument to `it()`:
20
+
21
+ ```javascript
22
+ const { qase } = require('mocha-qase-reporter');
23
+
24
+ // Single project
25
+ it(qase(100, 'login flow'), function () { ... });
26
+
27
+ // Multi-project
28
+ it(qase.projects({ PROJ1: [100], PROJ2: [200] }, 'login flow'), function () { ... });
29
+
30
+ // Multiple IDs per project
31
+ it(qase.projects({ PROJ1: [10, 11], PROJ2: [20] }, 'checkout'), function () { ... });
32
+ ```
33
+
34
+ Project codes (e.g. `PROJ1`, `PROJ2`) must match `testops_multi.projects[].code` in your config.
35
+
36
+ ## Tests Without Project Mapping
37
+
38
+ Tests that do not use `qase.projects()` and have no `(Qase PROJ: ids)` in the title are sent to the `default_project`. If they use `qase(id, name)` (single-project), that ID is used for the default project.
39
+
40
+ ## Important Notes
41
+
42
+ 1. **Project codes must match**: Codes in `qase.projects({ PROJ1: [1], ... })` must match `testops_multi.projects[].code`.
43
+ 2. **Mode**: Set `mode` to `testops_multi` in reporter config.
44
+ 3. **Title format**: The helper produces a title like `Name (Qase PROJ1: 1,2) (Qase PROJ2: 3)` so the reporter can parse the mapping.
45
+
46
+ ## Examples
47
+
48
+ See the [multi-project Mocha example](../../examples/multiProject/mocha/) for a complete runnable setup.
49
+
50
+ ## Troubleshooting
51
+
52
+ * Verify `mode` is `testops_multi` and project codes in `qase.projects()` match the config.
53
+ * Ensure the first argument to `it()` is the string returned by `qase.projects(mapping, name)` (or an equivalent title with markers).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha-qase-reporter",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Mocha Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "mocha": "^11.7.5",
45
45
  "deasync-promise": "^1.0.1",
46
- "qase-javascript-commons": "~2.4.13",
46
+ "qase-javascript-commons": "~2.5.0",
47
47
  "uuid": "^9.0.1"
48
48
  },
49
49
  "devDependencies": {