mocha-qase-reporter 1.1.4 → 1.1.5

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
@@ -94,6 +94,23 @@ After the tests are finished, you can complete the run:
94
94
  qasectl testops run complete --project DEMO --token token --id $(echo $QASE_TESTOPS_RUN_ID)
95
95
  ```
96
96
 
97
+ ### Extra Reporters
98
+
99
+ The reporter supports additional reporters alongside the main Qase reporter. This allows you to use multiple output formats (e.g., console output and JSON reports) without the hanging issues that can occur with `mocha-multi-reporters` in parallel mode.
100
+
101
+ ```bash
102
+ # Single extra reporter
103
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec
104
+
105
+ # Multiple extra reporters
106
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec,json
107
+
108
+ # With parallel execution
109
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec --parallel
110
+ ```
111
+
112
+ For detailed configuration options and examples, see the [Extra Reporters section](docs/usage.md#using-extra-reporters) in the usage guide.
113
+
97
114
  ## Configuration
98
115
 
99
116
  Qase Mocha reporter can be configured in multiple ways:
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-mocha@1.1.5
2
+
3
+ ## What's new
4
+
5
+ - Added support for extra reporters in the reporter. You can find more information in the [usage guide](docs/usage.md#using-extra-reporters).
6
+
1
7
  # qase-mocha@1.1.4
2
8
 
3
9
  ## What's new
@@ -0,0 +1,27 @@
1
+ import type * as Mocha from 'mocha';
2
+ export interface ExtraReporterConfig {
3
+ name: string;
4
+ options?: Record<string, unknown>;
5
+ }
6
+ export type ExtraReportersConfig = string | ExtraReporterConfig | (string | ExtraReporterConfig)[];
7
+ /**
8
+ * Parses extraReporters configuration from Mocha options
9
+ * Supports both string format and object format
10
+ */
11
+ export declare function parseExtraReporters(options: Mocha.MochaOptions): ExtraReportersConfig | undefined;
12
+ /**
13
+ * Creates and configures additional reporters based on extraReporters config
14
+ */
15
+ export declare function createExtraReporters(runner: Mocha.Runner, options: Mocha.MochaOptions, extraReportersConfig: ExtraReportersConfig): Mocha.reporters.Base[];
16
+ /**
17
+ * Checks if a reporter is compatible with parallel mode
18
+ * Some reporters are known to be incompatible with parallel execution
19
+ */
20
+ export declare function isReporterCompatibleWithParallel(reporterName: string): boolean;
21
+ /**
22
+ * Validates extraReporters configuration for parallel mode
23
+ */
24
+ export declare function validateExtraReportersForParallel(extraReportersConfig: ExtraReportersConfig): {
25
+ valid: boolean;
26
+ incompatibleReporters: string[];
27
+ };
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseExtraReporters = parseExtraReporters;
4
+ exports.createExtraReporters = createExtraReporters;
5
+ exports.isReporterCompatibleWithParallel = isReporterCompatibleWithParallel;
6
+ exports.validateExtraReportersForParallel = validateExtraReportersForParallel;
7
+ /**
8
+ * Parses extraReporters configuration from Mocha options
9
+ * Supports both string format and object format
10
+ */
11
+ function parseExtraReporters(options) {
12
+ const reporterOptions = options.reporterOptions;
13
+ if (!reporterOptions) {
14
+ return undefined;
15
+ }
16
+ // Handle different formats of extraReporters
17
+ if (typeof reporterOptions['extraReporters'] === 'string') {
18
+ return reporterOptions['extraReporters'];
19
+ }
20
+ if (Array.isArray(reporterOptions['extraReporters'])) {
21
+ return reporterOptions['extraReporters'];
22
+ }
23
+ if (typeof reporterOptions['extraReporters'] === 'object' && reporterOptions['extraReporters'] !== null) {
24
+ return reporterOptions['extraReporters'];
25
+ }
26
+ return undefined;
27
+ }
28
+ /**
29
+ * Creates and configures additional reporters based on extraReporters config
30
+ */
31
+ function createExtraReporters(runner, options, extraReportersConfig) {
32
+ const reporters = [];
33
+ if (!extraReportersConfig) {
34
+ return reporters;
35
+ }
36
+ const configs = Array.isArray(extraReportersConfig) ? extraReportersConfig : [extraReportersConfig];
37
+ for (const config of configs) {
38
+ try {
39
+ let reporterName;
40
+ let reporterOptions = {};
41
+ if (typeof config === 'string') {
42
+ reporterName = config;
43
+ }
44
+ else if (typeof config === 'object' && config.name) {
45
+ reporterName = config.name;
46
+ reporterOptions = config.options ?? {};
47
+ }
48
+ else {
49
+ console.warn('Invalid extraReporter configuration:', config);
50
+ continue;
51
+ }
52
+ // Load the reporter
53
+ let ReporterClass;
54
+ try {
55
+ // Try to load built-in reporter first
56
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
57
+ ReporterClass = require(`mocha/lib/reporters/${reporterName}`);
58
+ }
59
+ catch {
60
+ try {
61
+ // Try to load as external package
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
63
+ ReporterClass = require(reporterName);
64
+ }
65
+ catch {
66
+ console.warn(`Failed to load reporter: ${reporterName}`);
67
+ continue;
68
+ }
69
+ }
70
+ if (ReporterClass && typeof ReporterClass === 'function') {
71
+ // Create reporter instance with options
72
+ const reporterOptionsForMocha = { ...options, ...reporterOptions };
73
+ const reporter = new ReporterClass(runner, reporterOptionsForMocha);
74
+ reporters.push(reporter);
75
+ }
76
+ }
77
+ catch (error) {
78
+ console.warn(`Failed to create reporter:`, error);
79
+ }
80
+ }
81
+ return reporters;
82
+ }
83
+ /**
84
+ * Checks if a reporter is compatible with parallel mode
85
+ * Some reporters are known to be incompatible with parallel execution
86
+ */
87
+ function isReporterCompatibleWithParallel(reporterName) {
88
+ const incompatibleReporters = [
89
+ 'markdown',
90
+ 'progress',
91
+ 'json-stream',
92
+ 'mocha-multi-reporters', // This is the main culprit
93
+ 'mocha-jenkins-reporter',
94
+ 'mocha-junit-reporter'
95
+ ];
96
+ return !incompatibleReporters.includes(reporterName);
97
+ }
98
+ /**
99
+ * Validates extraReporters configuration for parallel mode
100
+ */
101
+ function validateExtraReportersForParallel(extraReportersConfig) {
102
+ const incompatibleReporters = [];
103
+ if (!extraReportersConfig) {
104
+ return { valid: true, incompatibleReporters: [] };
105
+ }
106
+ const configs = Array.isArray(extraReportersConfig) ? extraReportersConfig : [extraReportersConfig];
107
+ for (const config of configs) {
108
+ let reporterName;
109
+ if (typeof config === 'string') {
110
+ reporterName = config;
111
+ }
112
+ else if (typeof config === 'object' && config.name) {
113
+ reporterName = config.name;
114
+ }
115
+ else {
116
+ continue;
117
+ }
118
+ if (!isReporterCompatibleWithParallel(reporterName)) {
119
+ incompatibleReporters.push(reporterName);
120
+ }
121
+ }
122
+ return {
123
+ valid: incompatibleReporters.length === 0,
124
+ incompatibleReporters
125
+ };
126
+ }
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Writable } from 'stream';
4
2
  export interface TestOutput {
5
3
  stdout: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { MochaOptions, reporters, Runner } from 'mocha';
3
2
  import { ConfigLoader, TestStatusEnum } from 'qase-javascript-commons';
4
3
  type MochaState = 'failed' | 'passed' | 'pending';
package/dist/reporter.js CHANGED
@@ -11,6 +11,7 @@ const deasync_promise_1 = __importDefault(require("deasync-promise"));
11
11
  const node_path_1 = require("node:path");
12
12
  const uuid_1 = require("uuid");
13
13
  const interceptor_1 = require("./interceptor");
14
+ const extraReporters_1 = require("./extraReporters");
14
15
  const Events = mocha_1.Runner.constants;
15
16
  class currentTest {
16
17
  steps = [];
@@ -23,6 +24,7 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
23
24
  originalStdoutWrite;
24
25
  originalStderrWrite;
25
26
  testOutputs;
27
+ // readonly #extraReporters: reporters.Base[] = [];
26
28
  /**
27
29
  * @type {Record<CypressState, TestStatusEnum>}
28
30
  */
@@ -47,12 +49,30 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
47
49
  constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader()) {
48
50
  super(runner, options);
49
51
  const config = configLoader.load();
52
+ // Parse and validate extraReporters configuration
53
+ const extraReportersConfig = (0, extraReporters_1.parseExtraReporters)(options);
50
54
  this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
51
55
  ...(0, qase_javascript_commons_1.composeOptions)(options, config),
52
56
  frameworkPackage: 'mocha',
53
57
  frameworkName: 'mocha',
54
58
  reporterName: 'mocha-qase-reporter',
55
59
  });
60
+ // Create extra reporters in both modes, but validate compatibility for parallel mode
61
+ if (extraReportersConfig) {
62
+ if (options.parallel) {
63
+ const validation = (0, extraReporters_1.validateExtraReportersForParallel)(extraReportersConfig);
64
+ if (validation.valid) {
65
+ (0, extraReporters_1.createExtraReporters)(runner, options, extraReportersConfig);
66
+ }
67
+ else {
68
+ console.warn(`Warning: The following reporters are incompatible with parallel mode: ${validation.incompatibleReporters.join(', ')}. ` +
69
+ 'They will be ignored in parallel mode to prevent hanging issues.');
70
+ }
71
+ }
72
+ else {
73
+ (0, extraReporters_1.createExtraReporters)(runner, options, extraReportersConfig);
74
+ }
75
+ }
56
76
  if (options.parallel) {
57
77
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
58
78
  options.require = [...(options.require ?? []), resolveParallelModeSetupFile()];
package/dist/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="mocha" />
2
- /// <reference types="node" />
3
1
  import { Attachment } from 'qase-javascript-commons';
4
2
  declare module 'mocha' {
5
3
  interface Context extends Methods {
package/docs/usage.md CHANGED
@@ -271,6 +271,94 @@ describe('User Authentication', function() {
271
271
 
272
272
  ---
273
273
 
274
+ ## Using Extra Reporters
275
+
276
+ The Qase reporter supports additional reporters alongside the main Qase reporter. This is useful when you need multiple output formats (e.g., console output and JSON reports) without using `mocha-multi-reporters`, which can cause hanging issues in parallel mode.
277
+
278
+ ### Configuration
279
+
280
+ You can configure extra reporters using the `extraReporters` option in the reporter options:
281
+
282
+ #### Command Line
283
+
284
+ ```bash
285
+ # Single extra reporter
286
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec
287
+
288
+ # Multiple extra reporters
289
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec,json
290
+
291
+ # With parallel execution
292
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec --parallel
293
+ ```
294
+
295
+ #### Configuration File
296
+
297
+ ```json
298
+ {
299
+ "reporter": "mocha-qase-reporter",
300
+ "reporterOptions": {
301
+ "extraReporters": "spec"
302
+ }
303
+ }
304
+ ```
305
+
306
+ #### Multiple Reporters
307
+
308
+ ```json
309
+ {
310
+ "reporter": "mocha-qase-reporter",
311
+ "reporterOptions": {
312
+ "extraReporters": ["spec", "json"]
313
+ }
314
+ }
315
+ ```
316
+
317
+ #### Reporters with Options
318
+
319
+ ```json
320
+ {
321
+ "reporter": "mocha-qase-reporter",
322
+ "reporterOptions": {
323
+ "extraReporters": [
324
+ "spec",
325
+ {
326
+ "name": "json",
327
+ "options": {
328
+ "output": "results.json"
329
+ }
330
+ }
331
+ ]
332
+ }
333
+ }
334
+ ```
335
+
336
+ ### Parallel Mode Compatibility
337
+
338
+ Some reporters are incompatible with parallel mode and will be automatically filtered out with a warning:
339
+
340
+ - `markdown`
341
+ - `progress`
342
+ - `json-stream`
343
+ - `mocha-multi-reporters`
344
+ - `mocha-jenkins-reporter`
345
+ - `mocha-junit-reporter`
346
+
347
+ ### Example Usage
348
+
349
+ ```bash
350
+ # Basic usage with spec reporter
351
+ npm run test:extra
352
+
353
+ # Parallel execution with spec reporter
354
+ npm run test:extra-parallel
355
+
356
+ # Multiple reporters
357
+ QASE_MODE=testops mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec,json --parallel
358
+ ```
359
+
360
+ ---
361
+
274
362
  ### Parallel Execution
275
363
 
276
364
  The reporter supports parallel execution of tests. First, create a new run in Qase.io using the Qase CLI:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha-qase-reporter",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
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.0.0",
45
45
  "deasync-promise": "^1.0.1",
46
- "qase-javascript-commons": "~2.4.4",
46
+ "qase-javascript-commons": "~2.4.8",
47
47
  "uuid": "^9.0.1"
48
48
  },
49
49
  "devDependencies": {