cypress-qase-reporter 2.1.1 → 2.2.0-beta.1

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
@@ -4,7 +4,7 @@ Publish results simple and easy.
4
4
 
5
5
  ## Installation
6
6
 
7
- To install the latest release version (2.0.x), run:
7
+ To install the latest release version (2.1.x), run:
8
8
 
9
9
  ```sh
10
10
  npm install -D cypress-qase-reporter
@@ -13,7 +13,7 @@ npm install -D cypress-qase-reporter
13
13
  <!-- if there's no current beta, comment the next block
14
14
  -->
15
15
 
16
- To install the latest beta version (2.1.x), run:
16
+ To install the latest beta version (2.2.x), run:
17
17
 
18
18
  ```sh
19
19
  npm install -D cypress-qase-reporter@beta
@@ -30,7 +30,7 @@ run the following steps:
30
30
  - import { qase } from 'cypress-qase-reporter/dist/mocha'
31
31
  + import { qase } from 'cypress-qase-reporter/mocha'
32
32
  ```
33
-
33
+
34
34
  2. Update reporter configuration in `cypress.config.js` and/or environment variables —
35
35
  see the [configuration reference](#configuration) below.
36
36
 
@@ -68,6 +68,23 @@ run the following steps:
68
68
  ...
69
69
  ```
70
70
 
71
+ ## Updating from v2.1 to v2.2
72
+
73
+ To update an existing test project using Qase reporter from version 2.1 to version 2.2,
74
+ run the following steps:
75
+
76
+ 1. Add a metadata in the `e2e` section of `cypress.config.js`
77
+
78
+ ```diff
79
+ ...
80
+ e2e: {
81
+ setupNodeEvents(on, config) {
82
+ require('cypress-qase-reporter/plugin')(on, config)
83
+ + require('cypress-qase-reporter/metadata')(on)
84
+ }
85
+ }
86
+ ...
87
+
71
88
  ## Getting started
72
89
 
73
90
  The Cypress reporter can auto-generate test cases
@@ -80,6 +97,16 @@ from Qase.io before executing tests. It's a more reliable way to bind
80
97
  autotests to test cases, that persists when you rename, move, or
81
98
  parameterize your tests.
82
99
 
100
+ ### Metadata
101
+
102
+ - `qase.title` - set the title of the test case
103
+ - `qase.fields` - set the fields of the test case
104
+ - `qase.suite` - set the suite of the test case
105
+ - `qase.comment` - set the comment of the test case
106
+ - `qase.parameters` - set the parameters of the test case
107
+ - `qase.groupParameters` - set the group parameters of the test case
108
+ - `qase.ignore` - ignore the test case in Qase. The test will be executed, but the results will not be sent to Qase.
109
+
83
110
  For example:
84
111
 
85
112
  ```typescript
@@ -88,6 +115,7 @@ import { qase } from 'cypress-qase-reporter/mocha';
88
115
  describe('My First Test', () => {
89
116
  qase(1,
90
117
  it('Several ids', () => {
118
+ qase.title('My title');
91
119
  expect(true).to.equal(true);
92
120
  })
93
121
  );
@@ -145,8 +173,6 @@ Example `cypress.config.js` config:
145
173
  ```js
146
174
  import cypress from 'cypress';
147
175
 
148
- import plugins from './cypress/plugins/index.js';
149
-
150
176
  module.exports = cypress.defineConfig({
151
177
  reporter: 'cypress-multi-reporters',
152
178
  reporterOptions: {
@@ -180,7 +206,8 @@ module.exports = cypress.defineConfig({
180
206
  video: false,
181
207
  e2e: {
182
208
  setupNodeEvents(on, config) {
183
- return plugins(on, config);
209
+ require('cypress-qase-reporter/plugin')(on, config)
210
+ require('cypress-qase-reporter/metadata')(on)
184
211
  },
185
212
  },
186
213
  });
package/changelog.md CHANGED
@@ -1,3 +1,31 @@
1
+ # cypress-qase-reporter@2.2.0-beta.1
2
+
3
+ ## What's new
4
+
5
+ Added the ability to specify a test metadata in tests:
6
+
7
+ - `qase.title` - set the test title
8
+ - `qase.fields` - set the test fields
9
+ - `qase.suite` - set the test suite
10
+ - `qase.comment` - set the test comment
11
+ - `qase.parameters` - set the test parameters
12
+ - `qase.groupParameters` - set the test group parameters
13
+ - `qase.ignore` - ignore the test in Qase
14
+
15
+ ```ts
16
+ it('test', () => {
17
+ qase.title('Title');
18
+ qase.fields({ field: 'value' });
19
+ qase.suite('Suite');
20
+ qase.comment('Comment');
21
+ qase.parameters({ param: 'value' });
22
+ qase.groupParameters({ param: 'value' });
23
+ qase.ignore();
24
+
25
+ cy.visit('https://example.com');
26
+ });
27
+ ```
28
+
1
29
  # cypress-qase-reporter@2.1.0
2
30
 
3
31
  ## What's new
@@ -40,8 +68,8 @@ The reporter will wait for all results to be sent to Qase and will not block the
40
68
 
41
69
  ## What's new
42
70
 
43
- 1. Cypress kills the process after the last tests.
44
- The reporter will wait for all results to be sent to Qase and will not block the process after sending.
71
+ 1. Cypress kills the process after the last tests.
72
+ The reporter will wait for all results to be sent to Qase and will not block the process after sending.
45
73
 
46
74
  2. The reporter will collect suites and add them to results.
47
75
 
@@ -66,7 +94,7 @@ For more information about the new features and a guide for migration from v1, r
66
94
 
67
95
  # cypress-qase-reporter@2.0.0-beta.3
68
96
 
69
- Fixed an issue with multiple test runs created when Cypress is running
97
+ Fixed an issue with multiple test runs created when Cypress is running
70
98
  multiple tests in parallel.
71
99
 
72
100
  # cypress-qase-reporter@2.0.0-beta.2
@@ -0,0 +1,14 @@
1
+ import { Metadata } from './models';
2
+ export declare class MetadataManager {
3
+ static getMetadata(): Metadata | undefined;
4
+ static setIgnore(): void;
5
+ static setSuite(suite: string): void;
6
+ static setComment(comment: string): void;
7
+ static setTitle(title: string): void;
8
+ static setFields(fields: Record<string, string>): void;
9
+ static setParameters(parameters: Record<string, string>): void;
10
+ static setGroupParams(groupParams: Record<string, string>): void;
11
+ private static setMetadata;
12
+ static clear(): void;
13
+ static isExists(): boolean;
14
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetadataManager = void 0;
4
+ const fs_1 = require("fs");
5
+ const metadataPath = 'qaseMetadata';
6
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
7
+ class MetadataManager {
8
+ static getMetadata() {
9
+ if (!this.isExists()) {
10
+ return undefined;
11
+ }
12
+ let metadata = {
13
+ title: undefined,
14
+ fields: {},
15
+ parameters: {},
16
+ groupParams: {},
17
+ ignore: false,
18
+ suite: undefined,
19
+ comment: undefined,
20
+ };
21
+ try {
22
+ const data = (0, fs_1.readFileSync)(metadataPath, 'utf8');
23
+ metadata = JSON.parse(data);
24
+ return metadata;
25
+ }
26
+ catch (err) {
27
+ console.error('Error reading metadata file:', err);
28
+ }
29
+ return undefined;
30
+ }
31
+ static setIgnore() {
32
+ const metadata = this.getMetadata() ?? {};
33
+ metadata.ignore = true;
34
+ this.setMetadata(metadata);
35
+ }
36
+ static setSuite(suite) {
37
+ const metadata = this.getMetadata() ?? {};
38
+ metadata.suite = suite;
39
+ this.setMetadata(metadata);
40
+ }
41
+ static setComment(comment) {
42
+ const metadata = this.getMetadata() ?? {};
43
+ metadata.comment = comment;
44
+ this.setMetadata(metadata);
45
+ }
46
+ static setTitle(title) {
47
+ const metadata = this.getMetadata() ?? {};
48
+ metadata.title = title;
49
+ this.setMetadata(metadata);
50
+ }
51
+ static setFields(fields) {
52
+ const metadata = this.getMetadata() ?? {};
53
+ metadata.fields = fields;
54
+ this.setMetadata(metadata);
55
+ }
56
+ static setParameters(parameters) {
57
+ const metadata = this.getMetadata() ?? {};
58
+ metadata.parameters = parameters;
59
+ this.setMetadata(metadata);
60
+ }
61
+ static setGroupParams(groupParams) {
62
+ const metadata = this.getMetadata() ?? {};
63
+ metadata.groupParams = groupParams;
64
+ this.setMetadata(metadata);
65
+ }
66
+ static setMetadata(metadata) {
67
+ try {
68
+ const data = JSON.stringify(metadata);
69
+ (0, fs_1.writeFileSync)(metadataPath, data);
70
+ }
71
+ catch (err) {
72
+ console.error('Error writing metadata file:', err);
73
+ }
74
+ }
75
+ static clear() {
76
+ if (!this.isExists()) {
77
+ return;
78
+ }
79
+ try {
80
+ (0, fs_1.unlinkSync)(metadataPath);
81
+ }
82
+ catch (err) {
83
+ console.error('Error clearing state file:', err);
84
+ }
85
+ }
86
+ static isExists() {
87
+ return (0, fs_1.existsSync)(metadataPath);
88
+ }
89
+ }
90
+ exports.MetadataManager = MetadataManager;
@@ -0,0 +1,9 @@
1
+ export interface Metadata {
2
+ title?: string | undefined;
3
+ fields?: Record<string, string>;
4
+ parameters?: Record<string, string>;
5
+ groupParams?: Record<string, string>;
6
+ ignore?: boolean;
7
+ suite?: string | undefined;
8
+ comment?: string | undefined;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const manager_1 = require("./metadata/manager");
4
+ module.exports = function (on) {
5
+ on('task', {
6
+ qaseTitle(value) {
7
+ manager_1.MetadataManager.setTitle(value);
8
+ return null;
9
+ },
10
+ });
11
+ on('task', {
12
+ qaseFields(value) {
13
+ manager_1.MetadataManager.setFields(value);
14
+ return null;
15
+ },
16
+ });
17
+ on('task', {
18
+ qaseIgnore() {
19
+ manager_1.MetadataManager.setIgnore();
20
+ return null;
21
+ },
22
+ });
23
+ on('task', {
24
+ qaseParameters(value) {
25
+ manager_1.MetadataManager.setParameters(value);
26
+ return null;
27
+ },
28
+ });
29
+ on('task', {
30
+ qaseGroupParameters(value) {
31
+ manager_1.MetadataManager.setGroupParams(value);
32
+ return null;
33
+ },
34
+ });
35
+ on('task', {
36
+ qaseSuite(value) {
37
+ manager_1.MetadataManager.setSuite(value);
38
+ return null;
39
+ },
40
+ });
41
+ on('task', {
42
+ qaseComment(value) {
43
+ manager_1.MetadataManager.setComment(value);
44
+ return null;
45
+ },
46
+ });
47
+ };
package/dist/mocha.d.ts CHANGED
@@ -1,3 +1,74 @@
1
1
  /// <reference types="cypress" />
2
2
  import { Test } from 'mocha';
3
- export declare const qase: (caseId: number | string | number[] | string[], test: Test) => Test;
3
+ export declare const qase: {
4
+ (caseId: number | string | number[] | string[], test: Test): Test;
5
+ /**
6
+ * Set a title for the test case
7
+ * @param {string} value
8
+ * @example
9
+ * it('test', () => {
10
+ * qase.title("Title");
11
+ * cy.visit('https://example.com');
12
+ * });
13
+ */
14
+ title(value: string): void;
15
+ /**
16
+ * Set fields for the test case
17
+ * @param {Record<string, string>} values
18
+ * @example
19
+ * it('test', () => {
20
+ * qase.fields({description: "Description"});
21
+ * cy.visit('https://example.com');
22
+ * });
23
+ */
24
+ fields(values: Record<string, string>): void;
25
+ /**
26
+ * Ignore the test case result in Qase
27
+ * @example
28
+ * it('test', () => {
29
+ * qase.ignore();
30
+ * cy.visit('https://example.com');
31
+ * });
32
+ */
33
+ ignore(): void;
34
+ /**
35
+ * Set parameters for the test case
36
+ * @param {Record<string, string>} values
37
+ * @example
38
+ * it('test', () => {
39
+ * qase.parameters({param01: "value01"});
40
+ * cy.visit('https://example.com');
41
+ * });
42
+ */
43
+ parameters(values: Record<string, string>): void;
44
+ /**
45
+ * Set group parameters for the test case
46
+ * @param {Record<string, string>} values
47
+ * @example
48
+ * it('test', () => {
49
+ * qase.groupParameters({param01: "value01"});
50
+ * cy.visit('https://example.com');
51
+ * });
52
+ */
53
+ groupParameters(values: Record<string, string>): void;
54
+ /**
55
+ * Set a suite for the test case
56
+ * @param {string} value
57
+ * @example
58
+ * it('test', () => {
59
+ * qase.suite("Suite 01");
60
+ * cy.visit('https://example.com');
61
+ * });
62
+ */
63
+ suite(value: string): void;
64
+ /**
65
+ * Set a comment for the test case
66
+ * @param {string} value
67
+ * @example
68
+ * it('test', () => {
69
+ * qase.comment("Some comment");
70
+ * cy.visit('https://example.com');
71
+ * });
72
+ */
73
+ comment(value: string): void;
74
+ };
package/dist/mocha.js CHANGED
@@ -7,3 +7,100 @@ const qase = (caseId, test) => {
7
7
  return test;
8
8
  };
9
9
  exports.qase = qase;
10
+ /**
11
+ * Set a title for the test case
12
+ * @param {string} value
13
+ * @example
14
+ * it('test', () => {
15
+ * qase.title("Title");
16
+ * cy.visit('https://example.com');
17
+ * });
18
+ */
19
+ exports.qase.title = (value) => {
20
+ cy.task('qaseTitle', value).then(() => {
21
+ //
22
+ });
23
+ };
24
+ /**
25
+ * Set fields for the test case
26
+ * @param {Record<string, string>} values
27
+ * @example
28
+ * it('test', () => {
29
+ * qase.fields({description: "Description"});
30
+ * cy.visit('https://example.com');
31
+ * });
32
+ */
33
+ exports.qase.fields = (values) => {
34
+ cy.task('qaseFields', values).then(() => {
35
+ //
36
+ });
37
+ };
38
+ /**
39
+ * Ignore the test case result in Qase
40
+ * @example
41
+ * it('test', () => {
42
+ * qase.ignore();
43
+ * cy.visit('https://example.com');
44
+ * });
45
+ */
46
+ exports.qase.ignore = () => {
47
+ cy.task('qaseIgnore').then(() => {
48
+ //
49
+ });
50
+ };
51
+ /**
52
+ * Set parameters for the test case
53
+ * @param {Record<string, string>} values
54
+ * @example
55
+ * it('test', () => {
56
+ * qase.parameters({param01: "value01"});
57
+ * cy.visit('https://example.com');
58
+ * });
59
+ */
60
+ exports.qase.parameters = (values) => {
61
+ cy.task('qaseParameters', values).then(() => {
62
+ //
63
+ });
64
+ };
65
+ /**
66
+ * Set group parameters for the test case
67
+ * @param {Record<string, string>} values
68
+ * @example
69
+ * it('test', () => {
70
+ * qase.groupParameters({param01: "value01"});
71
+ * cy.visit('https://example.com');
72
+ * });
73
+ */
74
+ exports.qase.groupParameters = (values) => {
75
+ cy.task('qaseGroupParameters', values).then(() => {
76
+ //
77
+ });
78
+ };
79
+ /**
80
+ * Set a suite for the test case
81
+ * @param {string} value
82
+ * @example
83
+ * it('test', () => {
84
+ * qase.suite("Suite 01");
85
+ * cy.visit('https://example.com');
86
+ * });
87
+ */
88
+ exports.qase.suite = (value) => {
89
+ cy.task('qaseSuite', value).then(() => {
90
+ //
91
+ });
92
+ };
93
+ /**
94
+ * Set a comment for the test case
95
+ * @param {string} value
96
+ * @example
97
+ * it('test', () => {
98
+ * qase.comment("Some comment");
99
+ * cy.visit('https://example.com');
100
+ * });
101
+ */
102
+ exports.qase.comment = (value) => {
103
+ cy.task('qaseComment', value).then(() => {
104
+ //
105
+ });
106
+ };
package/dist/reporter.js CHANGED
@@ -11,6 +11,7 @@ const mocha_1 = require("mocha");
11
11
  const qase_javascript_commons_1 = require("qase-javascript-commons");
12
12
  const traverse_dir_1 = require("./utils/traverse-dir");
13
13
  const configSchema_1 = require("./configSchema");
14
+ const manager_1 = require("./metadata/manager");
14
15
  const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_RUN_END, } = mocha_1.Runner.constants;
15
16
  /**
16
17
  * @class CypressQaseReporter
@@ -97,6 +98,11 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
97
98
  * @private
98
99
  */
99
100
  addTestResult(test) {
101
+ const metadata = manager_1.MetadataManager.getMetadata();
102
+ if (metadata?.ignore) {
103
+ manager_1.MetadataManager.clear();
104
+ return;
105
+ }
100
106
  const ids = CypressQaseReporter.getCaseId(test.title);
101
107
  const attachments = this.screenshotsFolder
102
108
  ? CypressQaseReporter.findAttachments(ids, this.screenshotsFolder)
@@ -116,14 +122,36 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
116
122
  },
117
123
  };
118
124
  }
125
+ if (metadata?.suite) {
126
+ relations = {
127
+ suite: {
128
+ data: [
129
+ {
130
+ title: metadata.suite,
131
+ public_id: null,
132
+ },
133
+ ],
134
+ },
135
+ };
136
+ }
137
+ let message = null;
138
+ if (metadata?.comment) {
139
+ message = metadata.comment;
140
+ }
141
+ if (test.err?.message) {
142
+ if (message) {
143
+ message += '\n\n';
144
+ }
145
+ message += test.err.message;
146
+ }
119
147
  const result = {
120
148
  attachments: attachments ?? [],
121
149
  author: null,
122
- fields: {},
123
- message: test.err?.message ?? null,
150
+ fields: metadata?.fields ?? {},
151
+ message: message,
124
152
  muted: false,
125
- params: {},
126
- group_params: {},
153
+ params: metadata?.parameters ?? {},
154
+ group_params: metadata?.groupParams ?? {},
127
155
  relations: relations,
128
156
  run_id: null,
129
157
  signature: this.getSignature(test, ids),
@@ -140,9 +168,10 @@ class CypressQaseReporter extends mocha_1.reporters.Base {
140
168
  thread: null,
141
169
  },
142
170
  testops_id: ids.length > 0 ? ids : null,
143
- title: test.title,
171
+ title: metadata?.title ?? test.title,
144
172
  };
145
173
  void this.reporter.addTestResult(result);
174
+ manager_1.MetadataManager.clear();
146
175
  }
147
176
  /**
148
177
  * @param {Test} test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-qase-reporter",
3
- "version": "2.1.1",
3
+ "version": "2.2.0-beta.1",
4
4
  "description": "Qase Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,
@@ -12,6 +12,7 @@
12
12
  "./reporter": "./dist/reporter.js",
13
13
  "./package.json": "./package.json",
14
14
  "./plugin": "./dist/plugin.js",
15
+ "./metadata": "./dist/metadata.js",
15
16
  "./hooks": "./dist/hooks.js"
16
17
  },
17
18
  "typesVersions": {