testit-adapter-mocha 2.1.1 → 2.1.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/lib/reporter.js +30 -10
- package/package.json +3 -2
package/lib/reporter.js
CHANGED
|
@@ -28,6 +28,11 @@ const emptyStep = () => ({
|
|
|
28
28
|
steps: [],
|
|
29
29
|
attachments: [],
|
|
30
30
|
});
|
|
31
|
+
const StateConstants = {
|
|
32
|
+
STATE_FAILED: 'failed',
|
|
33
|
+
STATE_PASSED: 'passed',
|
|
34
|
+
STATE_PENDING: 'pending',
|
|
35
|
+
};
|
|
31
36
|
module.exports = class extends Reporter {
|
|
32
37
|
constructor(runner, options) {
|
|
33
38
|
super(runner, options);
|
|
@@ -98,8 +103,8 @@ module.exports = class extends Reporter {
|
|
|
98
103
|
this.additions = new testit_js_commons_1.Additions(client);
|
|
99
104
|
this.runner.on(Events.EVENT_RUN_BEGIN, () => this.onStartRun());
|
|
100
105
|
this.runner.on(Events.EVENT_RUN_END, () => this.onEndRun());
|
|
101
|
-
this.runner.
|
|
102
|
-
this.runner.
|
|
106
|
+
this.runner.on(Events.EVENT_TEST_BEGIN, (test) => this.addMethods(test.ctx));
|
|
107
|
+
this.runner.on(Events.EVENT_HOOK_BEGIN, (hook) => this.addMethods(hook.ctx));
|
|
103
108
|
this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest());
|
|
104
109
|
this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test));
|
|
105
110
|
}
|
|
@@ -128,7 +133,7 @@ module.exports = class extends Reporter {
|
|
|
128
133
|
this.currentTest.startedOn = new Date();
|
|
129
134
|
}
|
|
130
135
|
onEndTest(test) {
|
|
131
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t
|
|
136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
132
137
|
const hooks = (0, utils_1.extractHooks)(test.parent);
|
|
133
138
|
const setup = [...hooks.beforeAll, ...hooks.beforeEach];
|
|
134
139
|
const teardown = [...hooks.afterEach, ...hooks.afterAll];
|
|
@@ -146,25 +151,25 @@ module.exports = class extends Reporter {
|
|
|
146
151
|
teardown,
|
|
147
152
|
workItemIds: (_p = test.ctx) === null || _p === void 0 ? void 0 : _p.workItemsIds,
|
|
148
153
|
};
|
|
149
|
-
const promise = this.strategy.loadAutotest(autotestPost, test.
|
|
154
|
+
const promise = this.strategy.loadAutotest(autotestPost, test.state == StateConstants.STATE_PASSED);
|
|
150
155
|
this.autotestsQueue.push(promise);
|
|
151
156
|
this.autotestsForTestRun.push({
|
|
152
157
|
autoTestExternalId: autotestPost.externalId,
|
|
153
|
-
outcome: test.
|
|
158
|
+
outcome: this._getOutcome(test.state),
|
|
154
159
|
startedOn: this.currentTest.startedOn,
|
|
155
160
|
completedOn: new Date(),
|
|
156
|
-
duration: (
|
|
161
|
+
duration: this._getDuration(test.duration),
|
|
157
162
|
stepResults: this.currentTest.stepResults,
|
|
158
163
|
setupResults: setup,
|
|
159
164
|
teardownResults: teardown,
|
|
160
165
|
attachments: this.currentTest.attachments,
|
|
161
166
|
links: this.additions.links,
|
|
162
|
-
message: ((
|
|
167
|
+
message: ((_q = test.err) === null || _q === void 0 ? void 0 : _q.message)
|
|
163
168
|
? this.additions.messages.concat(test.err.message).join("\n")
|
|
164
169
|
: this.additions.messages.join("\n"),
|
|
165
|
-
traces: (
|
|
166
|
-
parameters: (
|
|
167
|
-
properties: (
|
|
170
|
+
traces: (_r = test.err) === null || _r === void 0 ? void 0 : _r.stack,
|
|
171
|
+
parameters: (_s = test.ctx) === null || _s === void 0 ? void 0 : _s.parameters,
|
|
172
|
+
properties: (_t = test.ctx) === null || _t === void 0 ? void 0 : _t.properties,
|
|
168
173
|
});
|
|
169
174
|
this.resetTest(test);
|
|
170
175
|
}
|
|
@@ -180,4 +185,19 @@ module.exports = class extends Reporter {
|
|
|
180
185
|
_getClassName(path) {
|
|
181
186
|
return path && testit_js_commons_1.Utils.getFileName(path);
|
|
182
187
|
}
|
|
188
|
+
_getOutcome(state) {
|
|
189
|
+
switch (state) {
|
|
190
|
+
case StateConstants.STATE_FAILED:
|
|
191
|
+
return "Failed";
|
|
192
|
+
case StateConstants.STATE_PENDING:
|
|
193
|
+
return "Skipped";
|
|
194
|
+
default:
|
|
195
|
+
return this.currentTest.outcome;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
_getDuration(duration) {
|
|
199
|
+
return (duration !== null && duration !== void 0 ? duration : this.currentTest.startedOn)
|
|
200
|
+
? Date.now() - this.currentTest.startedOn.getTime()
|
|
201
|
+
: 0;
|
|
202
|
+
}
|
|
183
203
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testit-adapter-mocha",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Mocha adapter for Test IT",
|
|
5
5
|
"main": "lib/reporter.js",
|
|
6
6
|
"types": "lib/types.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"prebuild": "npm --prefix ../testit-js-commons run build && npm link ../testit-js-commons",
|
|
8
9
|
"build": "tsc",
|
|
9
10
|
"watch": "tsc -w"
|
|
10
11
|
},
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"mocha": "^10.2.0",
|
|
27
|
-
"testit-js-commons": "
|
|
28
|
+
"testit-js-commons": "~2.1.2"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"lib"
|