testit-adapter-mocha 3.7.7 → 3.7.8

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
@@ -1,5 +1,5 @@
1
1
  # Test IT TMS adapters for Mocha
2
- ![Test IT](https://raw.githubusercontent.com/testit-tms/adapters-js/master/images/banner.png)
2
+ ![Test IT](https://raw.githubusercontent.com/testit-tms/adapters-js/main/images/banner.png)
3
3
 
4
4
  ## Getting Started
5
5
 
package/lib/reporter.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -40,7 +31,6 @@ const StateConstants = {
40
31
  };
41
32
  class TmsReporter extends Reporter {
42
33
  constructor(runner, options) {
43
- var _a;
44
34
  super(runner, options);
45
35
  this.attachmentsQueue = [];
46
36
  this.autotestsQueue = [];
@@ -67,8 +57,7 @@ class TmsReporter extends Reporter {
67
57
  ? this.additions.addAttachments(pathsOrContent, fileName)
68
58
  : this.additions.addAttachments(pathsOrContent);
69
59
  promise.then((attachments) => {
70
- var _a;
71
- (_a = target.attachments) === null || _a === void 0 ? void 0 : _a.push(...attachments);
60
+ target.attachments?.push(...attachments);
72
61
  });
73
62
  this.attachmentsQueue.push(promise);
74
63
  return promise;
@@ -80,13 +69,12 @@ class TmsReporter extends Reporter {
80
69
  this.additions.addMessage(message);
81
70
  };
82
71
  this.addSteps = (title, stepConstructor) => {
83
- var _a;
84
72
  const start = new Date();
85
73
  const prevType = this.currentType;
86
74
  this.currentType = "step";
87
75
  const step = new step_1.TestStep(title);
88
76
  try {
89
- stepConstructor === null || stepConstructor === void 0 ? void 0 : stepConstructor(step);
77
+ stepConstructor?.(step);
90
78
  this.currentStep.outcome = "Passed";
91
79
  }
92
80
  catch (err) {
@@ -100,31 +88,29 @@ class TmsReporter extends Reporter {
100
88
  this.currentStep.startedOn = start;
101
89
  this.currentStep.completedOn = new Date();
102
90
  this.currentStep.duration = Date.now() - start.getTime();
103
- (_a = this.currentTest.stepResults) === null || _a === void 0 ? void 0 : _a.push(this.currentStep);
91
+ this.currentTest.stepResults?.push(this.currentStep);
104
92
  this.currentType = prevType;
105
93
  this.currentStep = emptyStep();
106
94
  };
107
- const config = new testit_js_commons_1.ConfigComposer().compose(options === null || options === void 0 ? void 0 : options.tmsOptions);
95
+ const config = new testit_js_commons_1.ConfigComposer().compose(options?.tmsOptions);
108
96
  this.strategy = testit_js_commons_1.StrategyFactory.create(config);
109
97
  this.additions = new testit_js_commons_1.Additions(config);
110
98
  if (options.parallel) {
111
- options.require = [...((_a = options.require) !== null && _a !== void 0 ? _a : []), (0, utils_1.resolveParallelModeSetupFile)()];
99
+ options.require = [...(options.require ?? []), (0, utils_1.resolveParallelModeSetupFile)()];
112
100
  }
113
101
  else {
114
102
  this.applyListeners();
115
103
  }
116
104
  }
117
- teardown() {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- yield Promise.all(this.attachmentsQueue).catch((err) => {
120
- console.log("Error loading attachments. \n", err.body);
121
- });
122
- yield Promise.all(this.autotestsQueue);
123
- yield this.strategy.loadTestRun(this.autotestsForTestRun).catch((err) => {
124
- console.log("Error load test run. \n", err.body);
125
- });
126
- yield this.strategy.teardown();
105
+ async teardown() {
106
+ await Promise.all(this.attachmentsQueue).catch((err) => {
107
+ console.log("Error loading attachments. \n", err.body);
108
+ });
109
+ await Promise.all(this.autotestsQueue);
110
+ await this.strategy.loadTestRun(this.autotestsForTestRun).catch((err) => {
111
+ console.log("Error load test run. \n", err.body);
127
112
  });
113
+ await this.strategy.teardown();
128
114
  }
129
115
  clearContext(ctx) {
130
116
  ctx.externalId = undefined;
@@ -152,24 +138,23 @@ class TmsReporter extends Reporter {
152
138
  this.currentTest.startedOn = new Date();
153
139
  }
154
140
  onEndTest(test) {
155
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
156
141
  const hooks = (0, utils_1.extractHooks)(test.parent);
157
142
  const setup = [...hooks.beforeAll, ...hooks.beforeEach];
158
143
  const teardown = [...hooks.afterEach, ...hooks.afterAll];
159
144
  const autotestPost = {
160
- externalId: (_b = (_a = test.ctx) === null || _a === void 0 ? void 0 : _a.externalId) !== null && _b !== void 0 ? _b : testit_js_commons_1.Utils.getHash(test.title),
161
- name: (_d = (_c = test.ctx) === null || _c === void 0 ? void 0 : _c.displayName) !== null && _d !== void 0 ? _d : test.title,
162
- description: (_e = test.ctx) === null || _e === void 0 ? void 0 : _e.description,
163
- title: (_f = test.ctx) === null || _f === void 0 ? void 0 : _f.title,
164
- links: (_g = test.ctx) === null || _g === void 0 ? void 0 : _g.links,
165
- labels: (_j = (_h = test.ctx) === null || _h === void 0 ? void 0 : _h.labels) === null || _j === void 0 ? void 0 : _j.map((label) => ({ name: label })),
166
- tags: (_k = test.ctx) === null || _k === void 0 ? void 0 : _k.tags,
167
- namespace: (_m = (_l = test.ctx) === null || _l === void 0 ? void 0 : _l.namespace) !== null && _m !== void 0 ? _m : this._getNameSpace(test.file),
168
- classname: (_p = (_o = test.ctx) === null || _o === void 0 ? void 0 : _o.classname) !== null && _p !== void 0 ? _p : this._getClassName(test.file),
145
+ externalId: test.ctx?.externalId ?? testit_js_commons_1.Utils.getHash(test.title),
146
+ name: test.ctx?.displayName ?? test.title,
147
+ description: test.ctx?.description,
148
+ title: test.ctx?.title,
149
+ links: test.ctx?.links,
150
+ labels: test.ctx?.labels?.map((label) => ({ name: label })),
151
+ tags: test.ctx?.tags,
152
+ namespace: test.ctx?.namespace ?? this._getNameSpace(test.file),
153
+ classname: test.ctx?.classname ?? this._getClassName(test.file),
169
154
  steps: this.currentTest.stepResults,
170
155
  setup,
171
156
  teardown,
172
- workItemIds: (_q = test.ctx) === null || _q === void 0 ? void 0 : _q.workItemsIds,
157
+ workItemIds: test.ctx?.workItemsIds,
173
158
  externalKey: test.title,
174
159
  };
175
160
  const promise = this.strategy.loadAutotest(autotestPost, this._getOutcome(test.state));
@@ -185,12 +170,12 @@ class TmsReporter extends Reporter {
185
170
  teardownResults: teardown,
186
171
  attachments: this.currentTest.attachments,
187
172
  links: this.additions.links,
188
- message: ((_r = test.err) === null || _r === void 0 ? void 0 : _r.message)
173
+ message: test.err?.message
189
174
  ? this.additions.messages.concat(test.err.message).join("\n")
190
175
  : this.additions.messages.join("\n"),
191
- traces: (_s = test.err) === null || _s === void 0 ? void 0 : _s.stack,
192
- parameters: (_t = test.ctx) === null || _t === void 0 ? void 0 : _t.parameters,
193
- properties: (_u = test.ctx) === null || _u === void 0 ? void 0 : _u.properties,
176
+ traces: test.err?.stack,
177
+ parameters: test.ctx?.parameters,
178
+ properties: test.ctx?.properties,
194
179
  });
195
180
  this.resetTest(test);
196
181
  }
@@ -217,7 +202,7 @@ class TmsReporter extends Reporter {
217
202
  }
218
203
  }
219
204
  _getDuration(duration) {
220
- return (duration !== null && duration !== void 0 ? duration : this.currentTest.startedOn)
205
+ return duration ?? this.currentTest.startedOn
221
206
  ? Date.now() - this.currentTest.startedOn.getTime()
222
207
  : 0;
223
208
  }
package/lib/utils.js CHANGED
@@ -5,10 +5,9 @@ exports.hookToStep = hookToStep;
5
5
  exports.extractHooks = extractHooks;
6
6
  const path_1 = require("path");
7
7
  function hookToStep(hook) {
8
- var _a;
9
8
  return {
10
9
  title: hook.title,
11
- duration: (_a = hook.duration) !== null && _a !== void 0 ? _a : 0,
10
+ duration: hook.duration ?? 0,
12
11
  };
13
12
  }
14
13
  function extractHooks(suite) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-adapter-mocha",
3
- "version": "3.7.7",
3
+ "version": "3.7.8",
4
4
  "description": "Mocha adapter for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/types.d.ts",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "mocha": "^10.2.0",
33
33
  "deasync-promise": "^1.0.1",
34
- "testit-js-commons": "3.7.7"
34
+ "testit-js-commons": "3.7.8"
35
35
  },
36
36
  "files": [
37
37
  "lib"