cypress-qase-reporter 2.0.3 → 2.1.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
@@ -8,19 +8,52 @@ To install the latest version, run:
8
8
  npm install -D cypress-qase-reporter
9
9
  ```
10
10
 
11
- ## Updating from v1
11
+ ## Updating from v1 to v2.1
12
12
 
13
- You can update a test project from using version 1 to version 2 in several steps:
13
+ You can update a test project from using version 1 to version 2.1 in several steps:
14
14
 
15
- 1. Change import paths:
15
+ 1. Change import paths:
16
16
 
17
- ```diff
18
- - import { qase } from 'cypress-qase-reporter/dist/mocha'
19
- + import { qase } from 'cypress-qase-reporter/mocha'
20
- ```
17
+ ```diff
18
+ - import { qase } from 'cypress-qase-reporter/dist/mocha'
19
+ + import { qase } from 'cypress-qase-reporter/mocha'
20
+ ```
21
+ 2. Update reporter configuration in `cypress.config.js` and/or environment variables —
22
+ see the [configuration reference](#configuration) below.
21
23
 
22
- 2. Update reporter configuration in `cypress.config.js` and/or environment variables —
23
- see the [configuration reference](#configuration) below.
24
+ 3. Set the hooks in the `e2e` section in `cypress.config.js`:
25
+
26
+ ```diff
27
+ ...
28
+ e2e: {
29
+ setupNodeEvents(on, config) {
30
+ + require('cypress-qase-reporter/plugin')(on, config);
31
+ }
32
+ }
33
+ ...
34
+ ```
35
+
36
+ If you are override before:run or after:run hooks, use this:
37
+
38
+ ```diff
39
+ const { beforeRunHook, afterRunHook } = require('cypress-qase-reporter/hooks');
40
+
41
+ ...
42
+ e2e: {
43
+ setupNodeEvents(on, config) {
44
+ + on('before:run', async () => {
45
+ + console.log('override before:run');
46
+ + await beforeRunHook(config);
47
+ + });
48
+
49
+ + on('after:run', async () => {
50
+ + console.log('override after:run');
51
+ + await afterRunHook(config);
52
+ + });
53
+ },
54
+ },
55
+ ...
56
+ ```
24
57
 
25
58
  ## Getting started
26
59
 
@@ -41,20 +74,20 @@ import { qase } from 'cypress-qase-reporter/mocha';
41
74
 
42
75
  describe('My First Test', () => {
43
76
  qase(1,
44
- it('Several ids', () => {
45
- expect(true).to.equal(true);
46
- })
77
+ it('Several ids', () => {
78
+ expect(true).to.equal(true);
79
+ })
47
80
  );
48
81
  // a test can check multiple test cases
49
82
  qase([2, 3],
50
- it('Correct test', () => {
51
- expect(true).to.equal(true);
52
- })
83
+ it('Correct test', () => {
84
+ expect(true).to.equal(true);
85
+ })
53
86
  );
54
87
  qase(4,
55
- it.skip('Skipped test', () => {
56
- expect(true).to.equal(true);
57
- })
88
+ it.skip('Skipped test', () => {
89
+ expect(true).to.equal(true);
90
+ })
58
91
  );
59
92
  });
60
93
  ```
@@ -86,11 +119,13 @@ https://app.qase.io/run/QASE_PROJECT_CODE
86
119
  ## Configuration
87
120
 
88
121
  Qase Cypress reporter can be configured in multiple ways:
122
+
89
123
  - by adding configuration block in `cypress.config.js`,
90
124
  - using a separate config file `qase.config.json`,
91
125
  - using environment variables (they override the values from the configuration files).
92
126
 
93
- For a full list of configuration options, see the [Configuration reference](../qase-javascript-commons/README.md#configuration).
127
+ For a full list of configuration options, see
128
+ the [Configuration reference](../qase-javascript-commons/README.md#configuration).
94
129
 
95
130
  Example `cypress.config.js` config:
96
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-qase-reporter",
3
- "version": "2.0.3",
3
+ "version": "2.1.0-beta.1",
4
4
  "description": "Qase Cypress Reporter",
5
5
  "homepage": "https://github.com/qase-tms/qase-javascript",
6
6
  "sideEffects": false,
@@ -10,7 +10,8 @@
10
10
  ".": "./dist/index.js",
11
11
  "./mocha": "./dist/mocha.js",
12
12
  "./reporter": "./dist/reporter.js",
13
- "./package.json": "./package.json"
13
+ "./package.json": "./package.json",
14
+ "./plugin": "./dist/plugin.js"
14
15
  },
15
16
  "typesVersions": {
16
17
  "*": {
@@ -44,7 +45,7 @@
44
45
  "author": "Qase Team <support@qase.io>",
45
46
  "license": "Apache-2.0",
46
47
  "dependencies": {
47
- "qase-javascript-commons": "^2.0.0",
48
+ "qase-javascript-commons": "~2.1.0-beta.1",
48
49
  "uuid": "^9.0.1"
49
50
  },
50
51
  "peerDependencies": {
@@ -58,5 +59,8 @@
58
59
  "jest": "^29.5.0",
59
60
  "mocha": "^10.2.0",
60
61
  "ts-jest": "^29.1.0"
61
- }
62
+ },
63
+ "files": [
64
+ "plugin.js"
65
+ ]
62
66
  }
package/changelog.md DELETED
@@ -1,43 +0,0 @@
1
- # cypress-qase-reporter@2.0.3
2
-
3
- ## What's new
4
-
5
- Cypress doesn't finish the process after the last test.
6
- The reporter will wait for all results to be sent to Qase and will not block the process after sending.
7
-
8
- # cypress-qase-reporter@2.0.2
9
-
10
- ## What's new
11
-
12
- 1. Cypress kills the process after the last tests.
13
- The reporter will wait for all results to be sent to Qase and will not block the process after sending.
14
-
15
- 2. The reporter will collect suites and add them to results.
16
-
17
- # cypress-qase-reporter@2.0.1
18
-
19
- ## What's new
20
-
21
- The reporter would mark the test as blocked if the test was skipped in Cypress.
22
- Now, the reporter will mark the test as skipped.
23
-
24
- # cypress-qase-reporter@2.0.0
25
-
26
- ## What's new
27
-
28
- This is the first release in the 2.x series of the Cypress reporter.
29
- It brings new and more flexible configs, uploading results in parallel with running tests,
30
- and other powerful features.
31
-
32
- This changelog entry will be updated soon.
33
- For more information about the new features and a guide for migration from v1, refer to the
34
- [reporter documentation](https://github.com/qase-tms/qase-javascript/tree/main/qase-cypress#readme)
35
-
36
- # cypress-qase-reporter@2.0.0-beta.3
37
-
38
- Fixed an issue with multiple test runs created when Cypress is running
39
- multiple tests in parallel.
40
-
41
- # cypress-qase-reporter@2.0.0-beta.2
42
-
43
- First major beta release for the version 2 series of the Qase Cypress reporter.
package/dist/child.d.ts DELETED
@@ -1 +0,0 @@
1
- declare function runChild(): Promise<void>;
package/dist/child.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- const runChild = async () => {
3
- setTimeout(() => {
4
- // do nothing
5
- }, 10000);
6
- };
7
- runChild();
@@ -1,4 +0,0 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { FrameworkOptionsType } from 'qase-javascript-commons';
3
- import { ReporterOptionsType } from './options';
4
- export declare const configSchema: JSONSchemaType<FrameworkOptionsType<'cypress', ReporterOptionsType>>;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configSchema = void 0;
4
- exports.configSchema = {
5
- type: 'object',
6
- nullable: true,
7
- properties: {
8
- framework: {
9
- type: 'object',
10
- nullable: true,
11
- properties: {
12
- cypress: {
13
- type: 'object',
14
- nullable: true,
15
- properties: {
16
- screenshotsFolder: {
17
- type: 'string',
18
- nullable: true,
19
- }
20
- }
21
- }
22
- }
23
- }
24
- }
25
- };
@@ -1 +0,0 @@
1
- export { qase } from './mocha';
package/dist/index.cjs.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.qase = void 0;
4
- var mocha_1 = require("./mocha");
5
- Object.defineProperty(exports, "qase", { enumerable: true, get: function () { return mocha_1.qase; } });
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { CypressQaseReporter } from './reporter';
2
- export = CypressQaseReporter;
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- const reporter_1 = require("./reporter");
3
- module.exports = reporter_1.CypressQaseReporter;
package/dist/mocha.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Test } from 'mocha';
2
- export declare const qase: (caseId: number | string | number[] | string[], test: Test) => Test;
package/dist/mocha.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.qase = void 0;
4
- const qase = (caseId, test) => {
5
- const caseIds = Array.isArray(caseId) ? caseId : [caseId];
6
- test.title = `${test.title} (Qase ID: ${caseIds.join(',')})`;
7
- return test;
8
- };
9
- exports.qase = qase;
package/dist/options.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export type ReporterOptionsType = {
2
- screenshotsFolder?: string;
3
- };
package/dist/options.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,72 +0,0 @@
1
- import { MochaOptions, reporters, Runner } from 'mocha';
2
- import { ConfigLoader, TestStatusEnum } from 'qase-javascript-commons';
3
- import { ReporterOptionsType } from './options';
4
- type CypressState = 'failed' | 'passed' | 'pending';
5
- export type CypressQaseOptionsType = Omit<MochaOptions, 'reporterOptions'> & {
6
- reporterOptions: ReporterOptionsType;
7
- };
8
- /**
9
- * @class CypressQaseReporter
10
- * @extends reporters.Base
11
- */
12
- export declare class CypressQaseReporter extends reporters.Base {
13
- /**
14
- * @type {RegExp}
15
- */
16
- static qaseIdRegExp: RegExp;
17
- /**
18
- * @type {Record<CypressState, TestStatusEnum>}
19
- */
20
- static statusMap: Record<CypressState, TestStatusEnum>;
21
- /**
22
- * @param {string} title
23
- * @returns {number[]}
24
- * @private
25
- */
26
- private static getCaseId;
27
- /**
28
- * @param {number[]} ids
29
- * @param {string} dir
30
- * @returns {Attachment[]}
31
- * @private
32
- */
33
- private static findAttachments;
34
- /**
35
- * @type {string | undefined}
36
- * @private
37
- */
38
- private screenshotsFolder;
39
- /**
40
- * @type {ReporterInterface}
41
- * @private
42
- */
43
- private reporter;
44
- /**
45
- * @param {Runner} runner
46
- * @param {CypressQaseOptionsType} options
47
- * @param {ConfigLoaderInterface} configLoader
48
- */
49
- constructor(runner: Runner, options: CypressQaseOptionsType, configLoader?: ConfigLoader<import("qase-javascript-commons").FrameworkOptionsType<"cypress", ReporterOptionsType>>);
50
- /**
51
- * @param {Runner} runner
52
- * @private
53
- */
54
- private addRunnerListeners;
55
- /**
56
- * @param {Test} test
57
- * @private
58
- */
59
- private addTestResult;
60
- /**
61
- * @param {Test} test
62
- * @param {number[]} ids
63
- * @private
64
- */
65
- private getSignature;
66
- /**
67
- * @param {Suite} suite
68
- * @private
69
- */
70
- private getFile;
71
- }
72
- export {};
package/dist/reporter.js DELETED
@@ -1,189 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CypressQaseReporter = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const uuid_1 = require("uuid");
9
- const child_process_1 = require("child_process");
10
- const mocha_1 = require("mocha");
11
- const qase_javascript_commons_1 = require("qase-javascript-commons");
12
- const traverse_dir_1 = require("./utils/traverse-dir");
13
- const configSchema_1 = require("./configSchema");
14
- const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_RUN_END, EVENT_RUN_BEGIN, } = mocha_1.Runner.constants;
15
- /**
16
- * @class CypressQaseReporter
17
- * @extends reporters.Base
18
- */
19
- class CypressQaseReporter extends mocha_1.reporters.Base {
20
- /**
21
- * @param {string} title
22
- * @returns {number[]}
23
- * @private
24
- */
25
- static getCaseId(title) {
26
- const [, ids] = title.match(CypressQaseReporter.qaseIdRegExp) ?? [];
27
- return ids ? ids.split(',').map((id) => Number(id)) : [];
28
- }
29
- /**
30
- * @param {number[]} ids
31
- * @param {string} dir
32
- * @returns {Attachment[]}
33
- * @private
34
- */
35
- static findAttachments(ids, dir) {
36
- const idSet = new Set(ids);
37
- const attachments = [];
38
- try {
39
- (0, traverse_dir_1.traverseDir)(path_1.default.join(process.cwd(), dir), (filePath) => {
40
- if (CypressQaseReporter.getCaseId(filePath).some((item) => idSet.has(item))) {
41
- attachments.push({
42
- content: '',
43
- id: (0, uuid_1.v4)(),
44
- mime_type: '', size: 0,
45
- file_name: path_1.default.basename(filePath),
46
- file_path: filePath,
47
- });
48
- }
49
- });
50
- }
51
- catch (error) { /* ignore */
52
- }
53
- return attachments;
54
- }
55
- /**
56
- * @param {Runner} runner
57
- * @param {CypressQaseOptionsType} options
58
- * @param {ConfigLoaderInterface} configLoader
59
- */
60
- constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader(configSchema_1.configSchema)) {
61
- super(runner, options);
62
- const { reporterOptions } = options;
63
- const config = configLoader.load();
64
- const { framework, ...composedOptions } = (0, qase_javascript_commons_1.composeOptions)(reporterOptions, config);
65
- this.screenshotsFolder = framework?.cypress?.screenshotsFolder;
66
- this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
67
- ...composedOptions,
68
- frameworkPackage: 'cypress',
69
- frameworkName: 'cypress',
70
- reporterName: 'cypress-qase-reporter',
71
- });
72
- this.addRunnerListeners(runner);
73
- }
74
- /**
75
- * @param {Runner} runner
76
- * @private
77
- */
78
- addRunnerListeners(runner) {
79
- runner.on(EVENT_TEST_PASS, (test) => this.addTestResult(test));
80
- runner.on(EVENT_TEST_PENDING, (test) => this.addTestResult(test));
81
- runner.on(EVENT_TEST_FAIL, (test) => this.addTestResult(test));
82
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
83
- runner.on(EVENT_RUN_BEGIN, () => this.reporter.startTestRun());
84
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
85
- runner.once(EVENT_RUN_END, async () => {
86
- await this.reporter.publish();
87
- (0, child_process_1.spawnSync)('node', [`${__dirname}/child.js`], { stdio: 'inherit' });
88
- });
89
- }
90
- /**
91
- * @param {Test} test
92
- * @private
93
- */
94
- addTestResult(test) {
95
- const ids = CypressQaseReporter.getCaseId(test.title);
96
- const attachments = this.screenshotsFolder
97
- ? CypressQaseReporter.findAttachments(ids, this.screenshotsFolder)
98
- : undefined;
99
- let relations = {};
100
- if (test.parent !== undefined) {
101
- const data = [];
102
- for (const suite of test.parent.titlePath()) {
103
- data.push({
104
- title: suite,
105
- public_id: null,
106
- });
107
- }
108
- relations = {
109
- suite: {
110
- data: data,
111
- },
112
- };
113
- }
114
- const result = {
115
- attachments: attachments ?? [],
116
- author: null,
117
- fields: {},
118
- message: test.err?.message ?? null,
119
- muted: false,
120
- params: {},
121
- relations: relations,
122
- run_id: null,
123
- signature: this.getSignature(test, ids),
124
- steps: [],
125
- id: test.id,
126
- execution: {
127
- status: test.state
128
- ? CypressQaseReporter.statusMap[test.state]
129
- : qase_javascript_commons_1.TestStatusEnum.invalid,
130
- start_time: null,
131
- end_time: null,
132
- duration: test.duration ?? 0,
133
- stacktrace: test.err?.stack ?? null,
134
- thread: null,
135
- },
136
- testops_id: ids.length > 0 ? ids : null,
137
- title: test.title,
138
- };
139
- void this.reporter.addTestResult(result);
140
- }
141
- /**
142
- * @param {Test} test
143
- * @param {number[]} ids
144
- * @private
145
- */
146
- getSignature(test, ids) {
147
- let signature = '';
148
- const file = test.parent ? this.getFile(test.parent) : undefined;
149
- if (file) {
150
- signature = file.split('/').join('::');
151
- }
152
- if (test.parent) {
153
- for (const suite of test.parent.titlePath()) {
154
- signature += '::' + suite.toLowerCase().replace(/\s/g, '_');
155
- }
156
- }
157
- signature += '::' + test.title.toLowerCase().replace(/\s/g, '_');
158
- if (ids.length > 0) {
159
- signature += '::' + ids.join('::');
160
- }
161
- return signature;
162
- }
163
- /**
164
- * @param {Suite} suite
165
- * @private
166
- */
167
- getFile(suite) {
168
- if (suite.file) {
169
- return suite.file;
170
- }
171
- if (suite.parent) {
172
- return this.getFile(suite.parent);
173
- }
174
- return undefined;
175
- }
176
- }
177
- exports.CypressQaseReporter = CypressQaseReporter;
178
- /**
179
- * @type {RegExp}
180
- */
181
- CypressQaseReporter.qaseIdRegExp = /\(Qase ID:? ([\d,]+)\)/;
182
- /**
183
- * @type {Record<CypressState, TestStatusEnum>}
184
- */
185
- CypressQaseReporter.statusMap = {
186
- failed: qase_javascript_commons_1.TestStatusEnum.failed,
187
- passed: qase_javascript_commons_1.TestStatusEnum.passed,
188
- pending: qase_javascript_commons_1.TestStatusEnum.skipped,
189
- };
@@ -1 +0,0 @@
1
- export declare const traverseDir: (dirPath: string, callback: (filePath: string) => void) => void;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.traverseDir = void 0;
7
- const fs_1 = require("fs");
8
- const path_1 = __importDefault(require("path"));
9
- // TODO: get rid of recursion
10
- const traverseDir = (dirPath, callback) => {
11
- const items = (0, fs_1.readdirSync)(dirPath, { withFileTypes: true });
12
- items.forEach((item) => {
13
- const itemPath = path_1.default.join(dirPath, item.name);
14
- if (item.isFile()) {
15
- callback(itemPath);
16
- }
17
- else if (item.isDirectory()) {
18
- try {
19
- (0, exports.traverseDir)(itemPath, callback);
20
- }
21
- catch (error) { /* ignore */ }
22
- }
23
- });
24
- };
25
- exports.traverseDir = traverseDir;
Binary file
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
-
4
- "compilerOptions": {
5
- "noEmit": false
6
- },
7
-
8
- "include": ["./src/**/*.ts", "./src/*.js"],
9
- }