cypress-qase-reporter 2.0.2 → 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
@@ -2,27 +2,58 @@
2
2
 
3
3
  Publish results simple and easy.
4
4
 
5
- ## How to install
6
-
7
5
  To install the latest version, run:
8
6
 
9
7
  ```sh
10
8
  npm install -D cypress-qase-reporter
11
9
  ```
12
10
 
13
- ## Updating from v1
11
+ ## Updating from v1 to v2.1
12
+
13
+ You can update a test project from using version 1 to version 2.1 in several steps:
14
14
 
15
- You can update a test project from using version 1 to version 2 in several steps:
15
+ 1. Change import paths:
16
16
 
17
- 1. Change import paths:
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.
18
23
 
19
- ```diff
20
- - import { qase } from 'cypress-qase-reporter/dist/mocha'
21
- + import { qase } from 'cypress-qase-reporter/mocha'
22
- ```
24
+ 3. Set the hooks in the `e2e` section in `cypress.config.js`:
23
25
 
24
- 2. Update reporter configuration in `cypress.config.js` and/or environment variables —
25
- see the [configuration reference](#configuration) below.
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
+ ```
26
57
 
27
58
  ## Getting started
28
59
 
@@ -43,20 +74,20 @@ import { qase } from 'cypress-qase-reporter/mocha';
43
74
 
44
75
  describe('My First Test', () => {
45
76
  qase(1,
46
- it('Several ids', () => {
47
- expect(true).to.equal(true);
48
- })
77
+ it('Several ids', () => {
78
+ expect(true).to.equal(true);
79
+ })
49
80
  );
50
81
  // a test can check multiple test cases
51
82
  qase([2, 3],
52
- it('Correct test', () => {
53
- expect(true).to.equal(true);
54
- })
83
+ it('Correct test', () => {
84
+ expect(true).to.equal(true);
85
+ })
55
86
  );
56
87
  qase(4,
57
- it.skip('Skipped test', () => {
58
- expect(true).to.equal(true);
59
- })
88
+ it.skip('Skipped test', () => {
89
+ expect(true).to.equal(true);
90
+ })
60
91
  );
61
92
  });
62
93
  ```
@@ -88,11 +119,13 @@ https://app.qase.io/run/QASE_PROJECT_CODE
88
119
  ## Configuration
89
120
 
90
121
  Qase Cypress reporter can be configured in multiple ways:
122
+
91
123
  - by adding configuration block in `cypress.config.js`,
92
124
  - using a separate config file `qase.config.json`,
93
125
  - using environment variables (they override the values from the configuration files).
94
126
 
95
- 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).
96
129
 
97
130
  Example `cypress.config.js` config:
98
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-qase-reporter",
3
- "version": "2.0.2",
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,36 +0,0 @@
1
- # cypress-qase-reporter@2.0.2
2
-
3
- ## What's new
4
-
5
- 1. Cypress kills the process after the last tests.
6
- The reporter will wait for all results to be sent to Qase and will not block the process after sending.
7
-
8
- 2. The reporter will collect suites and add them to results.
9
-
10
- # cypress-qase-reporter@2.0.1
11
-
12
- ## What's new
13
-
14
- The reporter would mark the test as blocked if the test was skipped in Cypress.
15
- Now, the reporter will mark the test as skipped.
16
-
17
- # cypress-qase-reporter@2.0.0
18
-
19
- ## What's new
20
-
21
- This is the first release in the 2.x series of the Cypress reporter.
22
- It brings new and more flexible configs, uploading results in parallel with running tests,
23
- and other powerful features.
24
-
25
- This changelog entry will be updated soon.
26
- For more information about the new features and a guide for migration from v1, refer to the
27
- [reporter documentation](https://github.com/qase-tms/qase-javascript/tree/main/qase-cypress#readme)
28
-
29
- # cypress-qase-reporter@2.0.0-beta.3
30
-
31
- Fixed an issue with multiple test runs created when Cypress is running
32
- multiple tests in parallel.
33
-
34
- # cypress-qase-reporter@2.0.0-beta.2
35
-
36
- First major beta release for the version 2 series of the Qase Cypress reporter.
@@ -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,65 +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
- * @private
62
- */
63
- private preventExit;
64
- }
65
- export {};
package/dist/reporter.js DELETED
@@ -1,168 +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 mocha_1 = require("mocha");
10
- const qase_javascript_commons_1 = require("qase-javascript-commons");
11
- const traverse_dir_1 = require("./utils/traverse-dir");
12
- const configSchema_1 = require("./configSchema");
13
- const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_RUN_END, EVENT_RUN_BEGIN, } = mocha_1.Runner.constants;
14
- // eslint-disable-next-line @typescript-eslint/unbound-method
15
- const _exit = process.exit;
16
- /**
17
- * @class CypressQaseReporter
18
- * @extends reporters.Base
19
- */
20
- class CypressQaseReporter extends mocha_1.reporters.Base {
21
- /**
22
- * @param {string} title
23
- * @returns {number[]}
24
- * @private
25
- */
26
- static getCaseId(title) {
27
- const [, ids] = title.match(CypressQaseReporter.qaseIdRegExp) ?? [];
28
- return ids ? ids.split(',').map((id) => Number(id)) : [];
29
- }
30
- /**
31
- * @param {number[]} ids
32
- * @param {string} dir
33
- * @returns {Attachment[]}
34
- * @private
35
- */
36
- static findAttachments(ids, dir) {
37
- const idSet = new Set(ids);
38
- const attachments = [];
39
- try {
40
- (0, traverse_dir_1.traverseDir)(path_1.default.join(process.cwd(), dir), (filePath) => {
41
- if (CypressQaseReporter.getCaseId(filePath).some((item) => idSet.has(item))) {
42
- attachments.push({
43
- content: '',
44
- id: (0, uuid_1.v4)(),
45
- mime_type: '', size: 0,
46
- file_name: path_1.default.basename(filePath),
47
- file_path: filePath,
48
- });
49
- }
50
- });
51
- }
52
- catch (error) { /* ignore */
53
- }
54
- return attachments;
55
- }
56
- /**
57
- * @param {Runner} runner
58
- * @param {CypressQaseOptionsType} options
59
- * @param {ConfigLoaderInterface} configLoader
60
- */
61
- constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader(configSchema_1.configSchema)) {
62
- super(runner, options);
63
- const { reporterOptions } = options;
64
- const config = configLoader.load();
65
- const { framework, ...composedOptions } = (0, qase_javascript_commons_1.composeOptions)(reporterOptions, config);
66
- this.screenshotsFolder = framework?.cypress?.screenshotsFolder;
67
- this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
68
- ...composedOptions,
69
- frameworkPackage: 'cypress',
70
- frameworkName: 'cypress',
71
- reporterName: 'cypress-qase-reporter',
72
- });
73
- this.addRunnerListeners(runner);
74
- }
75
- /**
76
- * @param {Runner} runner
77
- * @private
78
- */
79
- addRunnerListeners(runner) {
80
- runner.on(EVENT_TEST_PASS, (test) => this.addTestResult(test));
81
- runner.on(EVENT_TEST_PENDING, (test) => this.addTestResult(test));
82
- runner.on(EVENT_TEST_FAIL, (test) => this.addTestResult(test));
83
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
84
- runner.on(EVENT_RUN_BEGIN, () => this.reporter.startTestRun());
85
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
86
- runner.once(EVENT_RUN_END, async () => {
87
- this.preventExit();
88
- await this.reporter.publish();
89
- if (process.exitCode !== undefined) {
90
- process.exit(process.exitCode);
91
- }
92
- });
93
- }
94
- /**
95
- * @param {Test} test
96
- * @private
97
- */
98
- addTestResult(test) {
99
- const ids = CypressQaseReporter.getCaseId(test.title);
100
- const attachments = this.screenshotsFolder
101
- ? CypressQaseReporter.findAttachments(ids, this.screenshotsFolder)
102
- : undefined;
103
- let relations = {};
104
- if (test.parent !== undefined) {
105
- const data = [];
106
- for (const suite of test.parent.titlePath()) {
107
- data.push({
108
- title: suite,
109
- public_id: null,
110
- });
111
- }
112
- relations = {
113
- suite: {
114
- data: data,
115
- },
116
- };
117
- }
118
- const result = {
119
- attachments: attachments ?? [],
120
- author: null,
121
- fields: {},
122
- message: test.err?.message ?? null,
123
- muted: false,
124
- params: {},
125
- relations: relations,
126
- run_id: null,
127
- signature: '',
128
- steps: [],
129
- id: test.id,
130
- execution: {
131
- status: test.state
132
- ? CypressQaseReporter.statusMap[test.state]
133
- : qase_javascript_commons_1.TestStatusEnum.invalid,
134
- start_time: null,
135
- end_time: null,
136
- duration: test.duration ?? 0,
137
- stacktrace: test.err?.stack ?? null,
138
- thread: null,
139
- },
140
- testops_id: ids.length > 0 ? ids : null,
141
- title: test.title,
142
- };
143
- void this.reporter.addTestResult(result);
144
- }
145
- /**
146
- * @private
147
- */
148
- preventExit() {
149
- const mutableProcess = process;
150
- mutableProcess.exit = (code) => {
151
- process.exitCode = code || 0;
152
- process.exit = _exit;
153
- };
154
- }
155
- }
156
- exports.CypressQaseReporter = CypressQaseReporter;
157
- /**
158
- * @type {RegExp}
159
- */
160
- CypressQaseReporter.qaseIdRegExp = /\(Qase ID:? ([\d,]+)\)/;
161
- /**
162
- * @type {Record<CypressState, TestStatusEnum>}
163
- */
164
- CypressQaseReporter.statusMap = {
165
- failed: qase_javascript_commons_1.TestStatusEnum.failed,
166
- passed: qase_javascript_commons_1.TestStatusEnum.passed,
167
- pending: qase_javascript_commons_1.TestStatusEnum.skipped,
168
- };
@@ -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"]
9
- }