mocha-qase-reporter 1.0.0-beta.5 → 1.0.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
@@ -2,10 +2,10 @@
2
2
 
3
3
  Publish results simple and easy.
4
4
 
5
- To install the latest beta version, run:
5
+ To install the latest version, run:
6
6
 
7
7
  ```sh
8
- npm install -D mocha-qase-reporter@beta
8
+ npm install -D mocha-qase-reporter
9
9
  ```
10
10
 
11
11
  ## Getting started
@@ -23,15 +23,15 @@ parameterize your tests.
23
23
  For example:
24
24
 
25
25
  ```typescript
26
+ import { qase } from 'mocha-qase-reporter/mocha';
27
+
26
28
  describe('My First Test', () => {
27
- it('Several ids', () => {
28
- this.qaseId(1);
29
+ it(qase(1,'Several ids'), () => {;
29
30
  expect(true).to.equal(true);
30
31
  });
31
32
 
32
33
  // a test can check multiple test cases
33
- it('Correct test', () => {
34
- this.qaseId([2, 3]);
34
+ it(qase([2,3],'Correct test'), () => {
35
35
  expect(true).to.equal(true);
36
36
  });
37
37
 
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-mocha@1.0.0
2
+
3
+ ## What's new
4
+
5
+ Major release of the Cypress reporter package
6
+
1
7
  # qase-mocha@1.0.0-beta.5
2
8
 
3
9
  ## What's new
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StreamInterceptor = void 0;
4
4
  const stream_1 = require("stream");
5
5
  class StreamInterceptor extends stream_1.Writable {
6
+ onWrite;
6
7
  constructor(onWriteCallback) {
7
8
  super();
8
9
  this.onWrite = onWriteCallback;
package/dist/reporter.js CHANGED
@@ -13,103 +13,38 @@ const uuid_1 = require("uuid");
13
13
  const interceptor_1 = require("./interceptor");
14
14
  const Events = mocha_1.Runner.constants;
15
15
  class currentTest {
16
- constructor() {
17
- this.steps = [];
18
- this.status = 'passed';
19
- this.attachments = [];
20
- }
16
+ steps = [];
17
+ status = 'passed';
18
+ attachments = [];
21
19
  }
22
20
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return,@typescript-eslint/restrict-template-expressions
23
21
  const resolveParallelModeSetupFile = () => (0, node_path_1.join)(__dirname, `parallel${(0, node_path_1.extname)(__filename)}`);
24
22
  class MochaQaseReporter extends mocha_1.reporters.Base {
23
+ originalStdoutWrite;
24
+ originalStderrWrite;
25
+ testOutputs;
26
+ /**
27
+ * @type {Record<CypressState, TestStatusEnum>}
28
+ */
29
+ static statusMap = {
30
+ failed: qase_javascript_commons_1.TestStatusEnum.failed,
31
+ passed: qase_javascript_commons_1.TestStatusEnum.passed,
32
+ pending: qase_javascript_commons_1.TestStatusEnum.skipped,
33
+ };
34
+ /**
35
+ * @type {ReporterInterface}
36
+ * @private
37
+ */
38
+ reporter;
39
+ /**
40
+ * @type {Metadata}
41
+ * @private
42
+ */
43
+ metadata = new types_1.Metadata();
44
+ currentTest = new currentTest();
45
+ currentType = 'test';
25
46
  constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader()) {
26
47
  super(runner, options);
27
- /**
28
- * @type {Metadata}
29
- * @private
30
- */
31
- this.metadata = new types_1.Metadata();
32
- this.currentTest = new currentTest();
33
- this.currentType = 'test';
34
- this.applyListeners = () => {
35
- this.runner.on(Events.EVENT_RUN_BEGIN, () => this.onStartRun());
36
- this.runner.on(Events.EVENT_RUN_END, () => this.onEndRun());
37
- this.runner.on(Events.EVENT_TEST_BEGIN, (test) => this.addMethods(test));
38
- this.runner.on(Events.EVENT_HOOK_BEGIN, (hook) => this.addMethodsToContext(hook.ctx));
39
- this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest());
40
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
41
- this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test));
42
- };
43
- this.qaseId = (id) => {
44
- this.metadata.addQaseId(id);
45
- };
46
- this.title = (title) => {
47
- this.metadata.title = title;
48
- };
49
- this.parameters = (values) => {
50
- const stringRecord = {};
51
- for (const [key, value] of Object.entries(values)) {
52
- stringRecord[String(key)] = String(value);
53
- }
54
- this.metadata.parameters = stringRecord;
55
- };
56
- this.groupParameters = (values) => {
57
- const stringRecord = {};
58
- for (const [key, value] of Object.entries(values)) {
59
- stringRecord[String(key)] = String(value);
60
- }
61
- this.metadata.groupParameters = stringRecord;
62
- };
63
- this.fields = (values) => {
64
- const stringRecord = {};
65
- for (const [key, value] of Object.entries(values)) {
66
- stringRecord[String(key)] = String(value);
67
- }
68
- this.metadata.fields = stringRecord;
69
- };
70
- this.suite = (name) => {
71
- this.metadata.suite = name;
72
- };
73
- this.ignore = () => {
74
- this.metadata.ignore = true;
75
- };
76
- this.attach = (attach) => {
77
- this.metadata.addAttachment(attach);
78
- };
79
- this.comment = (message) => {
80
- this.metadata.addComment(message);
81
- };
82
- this.step = (title, func) => {
83
- const previousType = this.currentType;
84
- this.currentType = 'step';
85
- const step = {
86
- step_type: qase_javascript_commons_1.StepType.TEXT,
87
- data: {
88
- action: title,
89
- expected_result: null,
90
- },
91
- execution: {
92
- start_time: Date.now(),
93
- status: qase_javascript_commons_1.StepStatusEnum.passed,
94
- end_time: null,
95
- duration: null,
96
- },
97
- id: '',
98
- parent_id: null,
99
- attachments: [],
100
- steps: [],
101
- };
102
- try {
103
- func();
104
- }
105
- catch (err) {
106
- step.execution.status = qase_javascript_commons_1.StepStatusEnum.failed;
107
- this.currentTest.status = 'failed';
108
- }
109
- step.execution.end_time = Date.now();
110
- this.currentTest.steps.push(step);
111
- this.currentType = previousType;
112
- };
113
48
  const config = configLoader.load();
114
49
  this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
115
50
  ...(0, qase_javascript_commons_1.composeOptions)(options, config),
@@ -128,6 +63,15 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
128
63
  this.originalStderrWrite = process.stderr.write.bind(process.stderr);
129
64
  this.testOutputs = new Map();
130
65
  }
66
+ applyListeners = () => {
67
+ this.runner.on(Events.EVENT_RUN_BEGIN, () => this.onStartRun());
68
+ this.runner.on(Events.EVENT_RUN_END, () => this.onEndRun());
69
+ this.runner.on(Events.EVENT_TEST_BEGIN, (test) => this.addMethods(test));
70
+ this.runner.on(Events.EVENT_HOOK_BEGIN, (hook) => this.addMethodsToContext(hook.ctx));
71
+ this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest());
72
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
73
+ this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test));
74
+ };
131
75
  onStartRun() {
132
76
  this.reporter.startTestRun();
133
77
  }
@@ -304,6 +248,76 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
304
248
  }
305
249
  return suites;
306
250
  }
251
+ qaseId = (id) => {
252
+ this.metadata.addQaseId(id);
253
+ };
254
+ title = (title) => {
255
+ this.metadata.title = title;
256
+ };
257
+ parameters = (values) => {
258
+ const stringRecord = {};
259
+ for (const [key, value] of Object.entries(values)) {
260
+ stringRecord[String(key)] = String(value);
261
+ }
262
+ this.metadata.parameters = stringRecord;
263
+ };
264
+ groupParameters = (values) => {
265
+ const stringRecord = {};
266
+ for (const [key, value] of Object.entries(values)) {
267
+ stringRecord[String(key)] = String(value);
268
+ }
269
+ this.metadata.groupParameters = stringRecord;
270
+ };
271
+ fields = (values) => {
272
+ const stringRecord = {};
273
+ for (const [key, value] of Object.entries(values)) {
274
+ stringRecord[String(key)] = String(value);
275
+ }
276
+ this.metadata.fields = stringRecord;
277
+ };
278
+ suite = (name) => {
279
+ this.metadata.suite = name;
280
+ };
281
+ ignore = () => {
282
+ this.metadata.ignore = true;
283
+ };
284
+ attach = (attach) => {
285
+ this.metadata.addAttachment(attach);
286
+ };
287
+ comment = (message) => {
288
+ this.metadata.addComment(message);
289
+ };
290
+ step = (title, func) => {
291
+ const previousType = this.currentType;
292
+ this.currentType = 'step';
293
+ const step = {
294
+ step_type: qase_javascript_commons_1.StepType.TEXT,
295
+ data: {
296
+ action: title,
297
+ expected_result: null,
298
+ },
299
+ execution: {
300
+ start_time: Date.now(),
301
+ status: qase_javascript_commons_1.StepStatusEnum.passed,
302
+ end_time: null,
303
+ duration: null,
304
+ },
305
+ id: '',
306
+ parent_id: null,
307
+ attachments: [],
308
+ steps: [],
309
+ };
310
+ try {
311
+ func();
312
+ }
313
+ catch (err) {
314
+ step.execution.status = qase_javascript_commons_1.StepStatusEnum.failed;
315
+ this.currentTest.status = 'failed';
316
+ }
317
+ step.execution.end_time = Date.now();
318
+ this.currentTest.steps.push(step);
319
+ this.currentType = previousType;
320
+ };
307
321
  /**
308
322
  * @param {string} title
309
323
  * @returns {string}
@@ -316,6 +330,10 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
316
330
  }
317
331
  return title;
318
332
  }
333
+ /**
334
+ * @type {RegExp}
335
+ */
336
+ static qaseIdRegExp = /\(Qase ID: ([\d,]+)\)/;
319
337
  /**
320
338
  * @param {string} title
321
339
  * @returns {number[]}
@@ -327,15 +345,3 @@ class MochaQaseReporter extends mocha_1.reporters.Base {
327
345
  }
328
346
  }
329
347
  exports.MochaQaseReporter = MochaQaseReporter;
330
- /**
331
- * @type {Record<CypressState, TestStatusEnum>}
332
- */
333
- MochaQaseReporter.statusMap = {
334
- failed: qase_javascript_commons_1.TestStatusEnum.failed,
335
- passed: qase_javascript_commons_1.TestStatusEnum.passed,
336
- pending: qase_javascript_commons_1.TestStatusEnum.skipped,
337
- };
338
- /**
339
- * @type {RegExp}
340
- */
341
- MochaQaseReporter.qaseIdRegExp = /\(Qase ID: ([\d,]+)\)/;
package/dist/types.js CHANGED
@@ -7,6 +7,15 @@ exports.Metadata = void 0;
7
7
  const qase_javascript_commons_1 = require("qase-javascript-commons");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  class Metadata {
10
+ ids;
11
+ title;
12
+ fields;
13
+ parameters;
14
+ groupParameters;
15
+ ignore;
16
+ suite;
17
+ comment;
18
+ attachments;
10
19
  constructor() {
11
20
  this.clear();
12
21
  }
@@ -31,6 +40,7 @@ class Metadata {
31
40
  id: '',
32
41
  });
33
42
  }
43
+ return;
34
44
  }
35
45
  this.attachments?.push({
36
46
  file_name: attach.name ?? '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha-qase-reporter",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0",
4
4
  "description": "Mocha Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,