cypress-qase-reporter 2.0.0-beta.0 → 2.0.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/dist/configSchema.d.ts +4 -0
- package/dist/configSchema.js +25 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/mocha.d.ts +2 -0
- package/dist/mocha.js +9 -0
- package/dist/options.d.ts +3 -0
- package/dist/options.js +2 -0
- package/dist/reporter.d.ts +65 -0
- package/dist/reporter.js +130 -0
- package/dist/utils/traverse-dir.d.ts +1 -0
- package/dist/utils/traverse-dir.js +25 -0
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { qase } from './mocha';
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/mocha.d.ts
ADDED
package/dist/mocha.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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 {string[]}
|
|
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
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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 mocha_1 = require("mocha");
|
|
9
|
+
const qase_javascript_commons_1 = require("qase-javascript-commons");
|
|
10
|
+
const traverse_dir_1 = require("./utils/traverse-dir");
|
|
11
|
+
const configSchema_1 = require("./configSchema");
|
|
12
|
+
const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING, EVENT_RUN_END, } = mocha_1.Runner.constants;
|
|
13
|
+
/**
|
|
14
|
+
* @class CypressQaseReporter
|
|
15
|
+
* @extends reporters.Base
|
|
16
|
+
*/
|
|
17
|
+
class CypressQaseReporter extends mocha_1.reporters.Base {
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} title
|
|
20
|
+
* @returns {number[]}
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
static getCaseId(title) {
|
|
24
|
+
const [, ids] = title.match(CypressQaseReporter.qaseIdRegExp) ?? [];
|
|
25
|
+
return ids ? ids.split(',').map((id) => Number(id)) : [];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @param {number[]} ids
|
|
29
|
+
* @param {string} dir
|
|
30
|
+
* @returns {string[]}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
static findAttachments(ids, dir) {
|
|
34
|
+
const idSet = new Set(ids);
|
|
35
|
+
const attachments = [];
|
|
36
|
+
try {
|
|
37
|
+
(0, traverse_dir_1.traverseDir)(path_1.default.join(process.cwd(), dir), (filePath) => {
|
|
38
|
+
if (CypressQaseReporter.getCaseId(filePath).some((item) => idSet.has(item))) {
|
|
39
|
+
attachments.push(filePath);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) { /* ignore */ }
|
|
44
|
+
return attachments;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {Runner} runner
|
|
48
|
+
* @param {CypressQaseOptionsType} options
|
|
49
|
+
* @param {ConfigLoaderInterface} configLoader
|
|
50
|
+
*/
|
|
51
|
+
constructor(runner, options, configLoader = new qase_javascript_commons_1.ConfigLoader(configSchema_1.configSchema)) {
|
|
52
|
+
super(runner, options);
|
|
53
|
+
const { reporterOptions } = options;
|
|
54
|
+
const config = configLoader.load();
|
|
55
|
+
const { framework, ...composedOptions } = (0, qase_javascript_commons_1.composeOptions)(reporterOptions, config);
|
|
56
|
+
this.screenshotsFolder = framework?.cypress?.screenshotsFolder;
|
|
57
|
+
this.reporter = new qase_javascript_commons_1.QaseReporter({
|
|
58
|
+
...composedOptions,
|
|
59
|
+
frameworkPackage: 'cypress',
|
|
60
|
+
frameworkName: 'cypress',
|
|
61
|
+
reporterName: 'cypress-qase-reporter',
|
|
62
|
+
});
|
|
63
|
+
this.addRunnerListeners(runner);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @param {Runner} runner
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
addRunnerListeners(runner) {
|
|
70
|
+
runner.on(EVENT_TEST_PASS, (test) => this.addTestResult(test));
|
|
71
|
+
runner.on(EVENT_TEST_PENDING, (test) => this.addTestResult(test));
|
|
72
|
+
runner.on(EVENT_TEST_FAIL, (test) => this.addTestResult(test));
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
74
|
+
runner.once(EVENT_RUN_END, async () => {
|
|
75
|
+
this.preventExit();
|
|
76
|
+
await this.reporter.publish();
|
|
77
|
+
if (process.exitCode !== undefined) {
|
|
78
|
+
process.exit(process.exitCode);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @param {Test} test
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
addTestResult(test) {
|
|
87
|
+
const ids = CypressQaseReporter.getCaseId(test.title);
|
|
88
|
+
const attachments = this.screenshotsFolder
|
|
89
|
+
? CypressQaseReporter.findAttachments(ids, this.screenshotsFolder)
|
|
90
|
+
: undefined;
|
|
91
|
+
const result = {
|
|
92
|
+
id: test.id,
|
|
93
|
+
testOpsId: ids,
|
|
94
|
+
title: test.title,
|
|
95
|
+
suiteTitle: test.parent?.titlePath(),
|
|
96
|
+
status: test.state
|
|
97
|
+
? CypressQaseReporter.statusMap[test.state]
|
|
98
|
+
: qase_javascript_commons_1.TestStatusEnum.invalid,
|
|
99
|
+
duration: test.duration ?? 0,
|
|
100
|
+
error: test.err,
|
|
101
|
+
attachments,
|
|
102
|
+
};
|
|
103
|
+
this.reporter.addTestResult(result);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
preventExit() {
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
110
|
+
const _exit = process.exit;
|
|
111
|
+
const mutableProcess = process;
|
|
112
|
+
mutableProcess.exit = (code) => {
|
|
113
|
+
process.exitCode = code || 0;
|
|
114
|
+
process.exit = _exit;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.CypressQaseReporter = CypressQaseReporter;
|
|
119
|
+
/**
|
|
120
|
+
* @type {RegExp}
|
|
121
|
+
*/
|
|
122
|
+
CypressQaseReporter.qaseIdRegExp = /\(Qase ID:? ([\d,]+)\)/;
|
|
123
|
+
/**
|
|
124
|
+
* @type {Record<CypressState, TestStatusEnum>}
|
|
125
|
+
*/
|
|
126
|
+
CypressQaseReporter.statusMap = {
|
|
127
|
+
failed: qase_javascript_commons_1.TestStatusEnum.failed,
|
|
128
|
+
passed: qase_javascript_commons_1.TestStatusEnum.passed,
|
|
129
|
+
pending: qase_javascript_commons_1.TestStatusEnum.blocked,
|
|
130
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const traverseDir: (dirPath: string, callback: (filePath: string) => void) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-qase-reporter",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Qase Cypress Reporter",
|
|
5
5
|
"homepage": "https://github.com/qase-tms/qase-javascript",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"author": "Nikita Fedorov <nik333r@gmail.com>",
|
|
45
45
|
"license": "Apache-2.0",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"qase-javascript-commons": "^2.0.0-beta.
|
|
47
|
+
"qase-javascript-commons": "^2.0.0-beta.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"cypress": ">=8.0.0"
|