newman-reporter-qase 2.0.0-beta.0 → 2.0.0-beta.2
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 +6 -5
- package/changelog.md +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/reporter.d.ts +57 -0
- package/dist/reporter.js +175 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
>
|
|
3
|
-
> Publish results simple and easy.
|
|
1
|
+
# Qase TMS Newman reporter
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Publish results simple and easy.
|
|
4
|
+
|
|
5
|
+
The Newman reporter is currently in the closed beta stage.
|
|
6
|
+
To install the latest beta version, run:
|
|
6
7
|
|
|
7
8
|
```bash
|
|
8
|
-
npm install newman-reporter-qase
|
|
9
|
+
npm install newman-reporter-qase@beta
|
|
9
10
|
```
|
|
10
11
|
|
|
11
12
|
## Example of usage
|
package/changelog.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ConfigType, ConfigLoader } from 'qase-javascript-commons';
|
|
4
|
+
export type NewmanQaseOptionsType = ConfigType;
|
|
5
|
+
/**
|
|
6
|
+
* @class NewmanQaseReporter
|
|
7
|
+
*/
|
|
8
|
+
export declare class NewmanQaseReporter {
|
|
9
|
+
/**
|
|
10
|
+
* @type {RegExp}
|
|
11
|
+
*/
|
|
12
|
+
static qaseIdRegExp: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* @param {EventList} eventList
|
|
15
|
+
* @returns {number[]}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
private static getCaseIds;
|
|
19
|
+
/**
|
|
20
|
+
* @param {PropertyBase<PropertyBaseDefinition>} item
|
|
21
|
+
* @param {string[]} titles
|
|
22
|
+
* @returns {string[]}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private static getParentTitles;
|
|
26
|
+
/**
|
|
27
|
+
* @type {ReporterInterface}
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
private reporter;
|
|
31
|
+
/**
|
|
32
|
+
* @type {Map<string, TestResultType>}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private pendingResultMap;
|
|
36
|
+
/**
|
|
37
|
+
* @type {Map<string, number>}
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
private timerMap;
|
|
41
|
+
/**
|
|
42
|
+
* @param {EventEmitter} emitter
|
|
43
|
+
* @param {NewmanQaseOptionsType} options
|
|
44
|
+
* @param {unknown} _
|
|
45
|
+
* @param {ConfigLoaderInterface} configLoader
|
|
46
|
+
*/
|
|
47
|
+
constructor(emitter: EventEmitter, options: NewmanQaseOptionsType, _: unknown, configLoader?: ConfigLoader<Partial<ConfigType> & Record<string, unknown>>);
|
|
48
|
+
/**
|
|
49
|
+
* @param {EventEmitter} runner
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
private addRunnerListeners;
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private preventExit;
|
|
57
|
+
}
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
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.NewmanQaseReporter = void 0;
|
|
7
|
+
const semver_1 = __importDefault(require("semver"));
|
|
8
|
+
const qase_javascript_commons_1 = require("qase-javascript-commons");
|
|
9
|
+
/**
|
|
10
|
+
* @class NewmanQaseReporter
|
|
11
|
+
*/
|
|
12
|
+
class NewmanQaseReporter {
|
|
13
|
+
/**
|
|
14
|
+
* @param {EventList} eventList
|
|
15
|
+
* @returns {number[]}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
static getCaseIds(eventList) {
|
|
19
|
+
const ids = [];
|
|
20
|
+
eventList.each((event) => {
|
|
21
|
+
if (event.listen === 'test' && event.script.exec) {
|
|
22
|
+
event.script.exec.forEach((line) => {
|
|
23
|
+
const [, match] = line.match(NewmanQaseReporter.qaseIdRegExp) ?? [];
|
|
24
|
+
if (match) {
|
|
25
|
+
ids.push(...match.split(',').map((id) => Number(id)));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return ids;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @param {PropertyBase<PropertyBaseDefinition>} item
|
|
34
|
+
* @param {string[]} titles
|
|
35
|
+
* @returns {string[]}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
static getParentTitles(item) {
|
|
39
|
+
const titles = [];
|
|
40
|
+
if ('name' in item) {
|
|
41
|
+
titles.push(String(item.name));
|
|
42
|
+
}
|
|
43
|
+
const parent = item.parent();
|
|
44
|
+
if (parent) {
|
|
45
|
+
titles.concat(NewmanQaseReporter.getParentTitles(parent));
|
|
46
|
+
}
|
|
47
|
+
return titles;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @param {EventEmitter} emitter
|
|
51
|
+
* @param {NewmanQaseOptionsType} options
|
|
52
|
+
* @param {unknown} _
|
|
53
|
+
* @param {ConfigLoaderInterface} configLoader
|
|
54
|
+
*/
|
|
55
|
+
constructor(emitter, options, _, configLoader = new qase_javascript_commons_1.ConfigLoader()) {
|
|
56
|
+
/**
|
|
57
|
+
* @type {Map<string, TestResultType>}
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
this.pendingResultMap = new Map();
|
|
61
|
+
/**
|
|
62
|
+
* @type {Map<string, number>}
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
this.timerMap = new Map();
|
|
66
|
+
const config = configLoader.load();
|
|
67
|
+
this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
|
|
68
|
+
...(0, qase_javascript_commons_1.composeOptions)(options, config),
|
|
69
|
+
frameworkPackage: 'newman',
|
|
70
|
+
frameworkName: 'newman',
|
|
71
|
+
reporterName: 'newman-reporter-qase',
|
|
72
|
+
});
|
|
73
|
+
this.addRunnerListeners(emitter);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @param {EventEmitter} runner
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
addRunnerListeners(runner) {
|
|
80
|
+
runner.on('start', () => {
|
|
81
|
+
this.reporter.startTestRun();
|
|
82
|
+
});
|
|
83
|
+
runner.on('beforeItem', (_err, exec) => {
|
|
84
|
+
const { item } = exec;
|
|
85
|
+
const parent = item.parent();
|
|
86
|
+
const suites = parent ? NewmanQaseReporter.getParentTitles(parent) : [];
|
|
87
|
+
let relation = null;
|
|
88
|
+
if (suites.length > 0) {
|
|
89
|
+
const data = suites.map(title => {
|
|
90
|
+
return {
|
|
91
|
+
title: title,
|
|
92
|
+
public_id: null,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
relation = {
|
|
96
|
+
suite: {
|
|
97
|
+
data: data,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const ids = NewmanQaseReporter.getCaseIds(item.events);
|
|
102
|
+
this.pendingResultMap.set(item.id, {
|
|
103
|
+
attachments: [],
|
|
104
|
+
author: null,
|
|
105
|
+
execution: {
|
|
106
|
+
status: qase_javascript_commons_1.TestStatusEnum.passed,
|
|
107
|
+
start_time: 0,
|
|
108
|
+
end_time: 0,
|
|
109
|
+
duration: 0,
|
|
110
|
+
stacktrace: null,
|
|
111
|
+
thread: null,
|
|
112
|
+
},
|
|
113
|
+
fields: {},
|
|
114
|
+
message: null,
|
|
115
|
+
muted: false,
|
|
116
|
+
params: {},
|
|
117
|
+
relations: relation,
|
|
118
|
+
run_id: null,
|
|
119
|
+
signature: '',
|
|
120
|
+
steps: [],
|
|
121
|
+
testops_id: ids.length > 0 ? ids : null,
|
|
122
|
+
id: item.id,
|
|
123
|
+
title: item.name,
|
|
124
|
+
});
|
|
125
|
+
this.timerMap.set(item.id, Date.now());
|
|
126
|
+
});
|
|
127
|
+
runner.on('assertion', (err, exec) => {
|
|
128
|
+
const { item } = exec;
|
|
129
|
+
const pendingResult = this.pendingResultMap.get(item.id);
|
|
130
|
+
if (pendingResult && err) {
|
|
131
|
+
pendingResult.execution.status = qase_javascript_commons_1.TestStatusEnum.failed;
|
|
132
|
+
pendingResult.execution.stacktrace = err.stack ?? null;
|
|
133
|
+
pendingResult.message = err.message;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
runner.on('item', (_err, exec) => {
|
|
137
|
+
const { item } = exec;
|
|
138
|
+
const pendingResult = this.pendingResultMap.get(item.id);
|
|
139
|
+
if (pendingResult) {
|
|
140
|
+
const timer = this.timerMap.get(item.id);
|
|
141
|
+
if (timer) {
|
|
142
|
+
const now = Date.now();
|
|
143
|
+
pendingResult.execution.duration = now - timer;
|
|
144
|
+
}
|
|
145
|
+
void this.reporter.addTestResult(pendingResult);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
runner.on('beforeDone', () => {
|
|
149
|
+
void this.reporter.publish();
|
|
150
|
+
});
|
|
151
|
+
runner.on('done', () => {
|
|
152
|
+
this.preventExit();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
preventExit() {
|
|
159
|
+
const newmanVersion = (0, qase_javascript_commons_1.getPackageVersion)('newman');
|
|
160
|
+
if (!newmanVersion || semver_1.default.lt(newmanVersion, '5.3.2')) {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
162
|
+
const _exit = process.exit;
|
|
163
|
+
const mutableProcess = process;
|
|
164
|
+
mutableProcess.exit = (code) => {
|
|
165
|
+
process.exitCode = code;
|
|
166
|
+
process.exit = _exit;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.NewmanQaseReporter = NewmanQaseReporter;
|
|
172
|
+
/**
|
|
173
|
+
* @type {RegExp}
|
|
174
|
+
*/
|
|
175
|
+
NewmanQaseReporter.qaseIdRegExp = /\/\/\s*?[qQ]ase:\s?((?:[\d]+[\s,]{0,})+)/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "newman-reporter-qase",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Qase TMS Newman Reporter",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"author": "Parviz Khavari <havaripa@gmail.com>",
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"qase-javascript-commons": "^2.0.
|
|
42
|
+
"qase-javascript-commons": "^2.0.8",
|
|
43
43
|
"semver": "^7.5.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|