cypress-qase-reporter 1.4.1 → 1.4.2-alpha.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 CHANGED
@@ -38,16 +38,38 @@ describe('My First Test', () => {
38
38
  );
39
39
  });
40
40
 
41
+ ```
42
+ You should also have an active item in the project settings at
43
+ ```
44
+ https://app.qase.io/project/QASE_PROJECT_CODE/settings/options
45
+ ```
46
+ option in the `Test Runs` block:
47
+ ```
48
+ Allow submitting results in bulk
49
+ ```
50
+ If you are going to use several specifications for execution and you have in config
51
+ ```bash
52
+ "runComplete": true
53
+ ```
54
+ then it is necessary to additionally set in the project settings
55
+ ```
56
+ Allow to add results for cases in closed runs.
41
57
  ```
42
58
 
43
- To run tests and create a test run, execute the command:
59
+ To run tests and create a test run, execute the command (for example from folder examples):
44
60
  ```bash
45
61
  QASE_REPORT=1 npx cypress run
46
62
  ```
47
-
48
- ![Reporter in console](docs/stdout.png)
63
+ or
64
+ ```bash
65
+ npm test
66
+ ```
67
+ <p align="center">
68
+ <img width="65%" src="./examples/screenshots/screenshot.png">
69
+ </p>
49
70
 
50
71
  A test run will be performed and available at:
72
+
51
73
  ```
52
74
  https://app.qase.io/run/QASE_PROJECT_CODE
53
75
  ```
@@ -63,6 +85,11 @@ Reporter options (* - required):
63
85
  `DEMOTR` is project code here)
64
86
  - `runId` - Run ID from Qase TMS (also can be got from run URL)
65
87
  - `logging` [true/false] - Enabled debug logging from reporter or not
88
+ - `environmentId` - To execute with the sending of the envinroment information
89
+ - `basePath` - URL Qase.io
90
+ - `screenshotFolder` - Folder for save screenshot cypress,
91
+ - `sendScreenshot` [true/false] - Permission to send screenshots to Qase TMS
92
+ - `runComplete` [true/false] - Permission for automatic completion of the test run
66
93
 
67
94
  Example `cypress.json` config:
68
95
 
@@ -73,7 +100,8 @@ Example `cypress.json` config:
73
100
  "apiToken": "api_key",
74
101
  "projectCode": "project_code",
75
102
  "runId": 45,
76
- "logging": true
103
+ "logging": true,
104
+ "basePath": "https://api.qase.io/v1"
77
105
  }
78
106
  }
79
107
  ```
@@ -87,6 +115,13 @@ Supported ENV variables:
87
115
  - `QASE_RUN_ID` - Pass Run ID from ENV and override reporter options
88
116
  - `QASE_RUN_NAME` - Set custom Run name, when new run is created
89
117
  - `QASE_RUN_DESCRIPTION` - Set custom Run description, when new run is created
118
+ - `QASE_API_TOKEN` - Token for API access, you can find more information
119
+ [here](https://developers.qase.io/#authentication)
120
+ - `QASE_API_BASE_URL` - URL Qase.io, default value `https://api.qase.io/v1`
121
+ - `QASE_ENVIRONMENT_ID` - To execute with the sending of the envinroment information
122
+ - `QASE_SCREENSHOT_FOLDER` - Folder for save screenshot cypress
123
+ - `QASE_SCREENSHOT_SENDING` - Permission to send screenshots to Qase TMS
124
+ - `QASE_RUN_COMPLETE` - Permission for automatic completion of the test run
90
125
 
91
126
  <!-- references -->
92
127
 
package/dist/index.d.ts CHANGED
@@ -1,21 +1,27 @@
1
1
  import { MochaOptions, Runner, reporters } from 'mocha';
2
2
  declare class CypressQaseReporter extends reporters.Base {
3
+ testCasesForPublishingCount: number;
3
4
  private api;
4
5
  private pending;
5
- private results;
6
6
  private shouldPublish;
7
+ private results;
7
8
  private options;
8
9
  private runId?;
10
+ private isDisabled;
11
+ private resultsForPublishing;
9
12
  constructor(runner: Runner, options: MochaOptions);
13
+ private static getEnv;
14
+ private static getCaseId;
15
+ private static createRunObject;
16
+ private static createHeaders;
17
+ private static getPackageVersion;
10
18
  private log;
11
19
  private addRunnerListeners;
12
20
  private checkProject;
13
21
  private createRun;
14
22
  private checkRun;
15
- private getEnv;
16
23
  private saveRunId;
17
- private getCaseId;
18
24
  private logTestItem;
19
- private publishCaseResult;
25
+ private transformCaseResultToBulkObject;
20
26
  }
21
27
  export = CypressQaseReporter;
package/dist/index.js CHANGED
@@ -16,6 +16,53 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
16
16
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
17
17
  return cooked;
18
18
  };
19
+ var __assign = (this && this.__assign) || function () {
20
+ __assign = Object.assign || function(t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
24
+ t[p] = s[p];
25
+ }
26
+ return t;
27
+ };
28
+ return __assign.apply(this, arguments);
29
+ };
30
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
+ return new (P || (P = Promise))(function (resolve, reject) {
33
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
37
+ });
38
+ };
39
+ var __generator = (this && this.__generator) || function (thisArg, body) {
40
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
41
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
42
+ function verb(n) { return function (v) { return step([n, v]); }; }
43
+ function step(op) {
44
+ if (f) throw new TypeError("Generator is already executing.");
45
+ while (_) try {
46
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
47
+ if (y = 0, t) op = [op[0] & 2, t.value];
48
+ switch (op[0]) {
49
+ case 0: case 1: t = op; break;
50
+ case 4: _.label++; return { value: op[1], done: false };
51
+ case 5: _.label++; y = op[1]; op = [0]; continue;
52
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
53
+ default:
54
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
55
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
56
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
57
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
58
+ if (t[2]) _.ops.pop();
59
+ _.trys.pop(); continue;
60
+ }
61
+ op = body.call(thisArg, _);
62
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
63
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
64
+ }
65
+ };
19
66
  var __spreadArrays = (this && this.__spreadArrays) || function () {
20
67
  for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
21
68
  for (var r = Array(s), k = 0, i = 0; i < il; i++)
@@ -27,68 +74,147 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
74
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
75
  };
29
76
  /* eslint-disable no-console */
77
+ /* eslint-disable camelcase */
78
+ /* eslint-disable @typescript-eslint/unbound-method */
79
+ var src_1 = require("qaseio/dist/src");
30
80
  var mocha_1 = require("mocha");
31
- var models_1 = require("qaseio/dist/src/models");
81
+ var child_process_1 = require("child_process");
32
82
  var qaseio_1 = require("qaseio");
33
83
  var chalk_1 = __importDefault(require("chalk"));
84
+ var fs_1 = require("fs");
34
85
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35
86
  var _a = mocha_1.Runner.constants, EVENT_TEST_FAIL = _a.EVENT_TEST_FAIL, EVENT_TEST_PASS = _a.EVENT_TEST_PASS, EVENT_TEST_PENDING = _a.EVENT_TEST_PENDING, EVENT_RUN_END = _a.EVENT_RUN_END;
36
87
  var Envs;
37
88
  (function (Envs) {
38
89
  Envs["report"] = "QASE_REPORT";
39
90
  Envs["apiToken"] = "QASE_API_TOKEN";
91
+ Envs["basePath"] = "QASE_API_BASE_URL";
40
92
  Envs["runId"] = "QASE_RUN_ID";
41
93
  Envs["runName"] = "QASE_RUN_NAME";
42
94
  Envs["runDescription"] = "QASE_RUN_DESCRIPTION";
95
+ Envs["environmentId"] = "QASE_ENVIRONMENT_ID";
96
+ Envs["screenshotFolder"] = "QASE_SCREENSHOT_FOLDER";
97
+ Envs["sendScreenshot"] = "QASE_SCREENSHOT_SENDING";
98
+ Envs["runComplete"] = "QASE_RUN_COMPLETE";
43
99
  })(Envs || (Envs = {}));
44
100
  var CypressQaseReporter = /** @class */ (function (_super) {
45
101
  __extends(CypressQaseReporter, _super);
46
102
  function CypressQaseReporter(runner, options) {
47
103
  var _this = _super.call(this, runner, options) || this;
104
+ _this.testCasesForPublishingCount = 0;
48
105
  _this.pending = [];
106
+ _this.shouldPublish = [];
49
107
  _this.results = [];
50
- _this.shouldPublish = 0;
108
+ _this.isDisabled = false;
109
+ _this.resultsForPublishing = [];
51
110
  _this.options = options.reporterOptions;
52
- _this.api = new qaseio_1.QaseApi(_this.options.apiToken || _this.getEnv(Envs.apiToken) || '');
53
- if (!_this.getEnv(Envs.report)) {
111
+ _this.api = new qaseio_1.QaseApi(_this.options.apiToken || CypressQaseReporter.getEnv(Envs.apiToken) || '', CypressQaseReporter.getEnv(Envs.basePath) || _this.options.basePath, CypressQaseReporter.createHeaders());
112
+ if (!CypressQaseReporter.getEnv(Envs.report)) {
54
113
  return _this;
55
114
  }
56
115
  _this.log(chalk_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{yellow Current PID: ", "}"], ["{yellow Current PID: ", "}"])), process.pid));
57
116
  _this.addRunnerListeners(runner);
58
- _this.checkProject(_this.options.projectCode, function (prjExists) {
59
- if (prjExists) {
60
- _this.log(chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{green Project ", " exists}"], ["{green Project ", " exists}"])), _this.options.projectCode));
61
- if (_this.getEnv(Envs.runId) || _this.options.runId) {
62
- _this.saveRunId(_this.getEnv(Envs.runId) || _this.options.runId);
63
- _this.checkRun(_this.runId, function (runExists) {
64
- var run = _this.runId;
65
- if (runExists) {
66
- _this.log(chalk_1.default(templateObject_3 || (templateObject_3 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), run));
67
- }
68
- else {
69
- _this.log(chalk_1.default(templateObject_4 || (templateObject_4 = __makeTemplateObject(["{red Run ", " does not exist}"], ["{red Run ", " does not exist}"])), run));
70
- }
71
- });
117
+ void _this.checkProject(_this.options.projectCode, function (prjExists) { return __awaiter(_this, void 0, void 0, function () {
118
+ var _this = this;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ if (!prjExists) return [3 /*break*/, 5];
123
+ this.log(chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{green Project ", " exists}"], ["{green Project ", " exists}"])), this.options.projectCode));
124
+ if (!(CypressQaseReporter.getEnv(Envs.runId) || this.options.runId)) return [3 /*break*/, 2];
125
+ this.saveRunId(CypressQaseReporter.getEnv(Envs.runId) || this.options.runId);
126
+ return [4 /*yield*/, this.checkRun(this.runId, function (runExists) {
127
+ var run = _this.runId;
128
+ if (runExists) {
129
+ _this.log(chalk_1.default(templateObject_3 || (templateObject_3 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), run));
130
+ }
131
+ else {
132
+ _this.log(chalk_1.default(templateObject_4 || (templateObject_4 = __makeTemplateObject(["{red Run ", " does not exist}"], ["{red Run ", " does not exist}"])), run));
133
+ }
134
+ })];
135
+ case 1:
136
+ _a.sent();
137
+ return [3 /*break*/, 4];
138
+ case 2:
139
+ if (!!this.runId) return [3 /*break*/, 4];
140
+ return [4 /*yield*/, this.createRun(CypressQaseReporter.getEnv(Envs.runName), CypressQaseReporter.getEnv(Envs.runDescription), function (created) {
141
+ var _a;
142
+ if (created) {
143
+ _this.runId = (_a = created.result) === null || _a === void 0 ? void 0 : _a.id;
144
+ process.env.QASE_RUN_ID = String(_this === null || _this === void 0 ? void 0 : _this.runId);
145
+ _this.log(chalk_1.default(templateObject_5 || (templateObject_5 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), _this.runId));
146
+ }
147
+ else {
148
+ _this.log(chalk_1.default(templateObject_6 || (templateObject_6 = __makeTemplateObject(["{red Could not create run in project ", "}"], ["{red Could not create run in project ", "}"])), _this.options.projectCode));
149
+ _this.isDisabled = true;
150
+ }
151
+ })];
152
+ case 3:
153
+ _a.sent();
154
+ _a.label = 4;
155
+ case 4: return [3 /*break*/, 6];
156
+ case 5:
157
+ this.log(chalk_1.default(templateObject_7 || (templateObject_7 = __makeTemplateObject(["{red Project ", " does not exist}"], ["{red Project ", " does not exist}"])), this.options.projectCode));
158
+ _a.label = 6;
159
+ case 6: return [2 /*return*/];
72
160
  }
73
- else if (!_this.runId) {
74
- _this.createRun(_this.getEnv(Envs.runName), _this.getEnv(Envs.runDescription), function (created) {
75
- if (created) {
76
- _this.saveRunId(created.id);
77
- process.env.QASE_RUN_ID = created.id.toString();
78
- _this.log(chalk_1.default(templateObject_5 || (templateObject_5 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), _this.runId));
79
- }
80
- else {
81
- _this.log(chalk_1.default(templateObject_6 || (templateObject_6 = __makeTemplateObject(["{red Could not create run in project ", "}"], ["{red Could not create run in project ", "}"])), _this.options.projectCode));
82
- }
161
+ });
162
+ }); });
163
+ return _this;
164
+ }
165
+ CypressQaseReporter.getEnv = function (name) {
166
+ return process.env[name];
167
+ };
168
+ CypressQaseReporter.getCaseId = function (test) {
169
+ var regexp = /(\(Qase ID: ([\d,]+)\))/;
170
+ var results = regexp.exec(test.title);
171
+ if (results && results.length === 3) {
172
+ return results[2].split(',').map(function (value) { return Number.parseInt(value, 10); });
173
+ }
174
+ return [];
175
+ };
176
+ CypressQaseReporter.createRunObject = function (name, cases, args) {
177
+ return __assign({ title: name, cases: cases }, args);
178
+ };
179
+ CypressQaseReporter.createHeaders = function () {
180
+ var nodeVersion = process.version, os = process.platform, arch = process.arch;
181
+ var npmVersion = child_process_1.execSync('npm -v', { encoding: 'utf8' }).replace(/['"\n]+/g, '');
182
+ var qaseapiVersion = CypressQaseReporter.getPackageVersion('qaseio');
183
+ var cypressVersion = CypressQaseReporter.getPackageVersion('cypress');
184
+ var cypressCaseReporterVersion = this.getPackageVersion('cypress-qase-reporter');
185
+ var xPlatformHeader = "node=" + nodeVersion + "; npm=" + npmVersion + "; os=" + os + "; arch=" + arch;
186
+ var xClientHeader = "cypress=" + cypressVersion + "; qase-cypress=" + cypressCaseReporterVersion + "; qaseapi=" + qaseapiVersion;
187
+ return {
188
+ 'X-Client': xClientHeader,
189
+ 'X-Platform': xPlatformHeader,
190
+ };
191
+ };
192
+ CypressQaseReporter.getPackageVersion = function (name) {
193
+ var UNDEFINED = 'undefined';
194
+ try {
195
+ var pathToPackageJson = require.resolve(name + "/package.json", {
196
+ paths: [process.cwd()],
197
+ });
198
+ if (pathToPackageJson) {
199
+ try {
200
+ var packageString = fs_1.readFileSync(pathToPackageJson, {
201
+ encoding: 'utf8',
83
202
  });
203
+ if (packageString) {
204
+ var packageObject = JSON.parse(packageString);
205
+ return packageObject.version;
206
+ }
207
+ return UNDEFINED;
208
+ }
209
+ catch (error) {
210
+ return UNDEFINED;
84
211
  }
85
212
  }
86
- else {
87
- _this.log(chalk_1.default(templateObject_7 || (templateObject_7 = __makeTemplateObject(["{red Project ", " does not exist}"], ["{red Project ", " does not exist}"])), _this.options.projectCode));
88
- }
89
- });
90
- return _this;
91
- }
213
+ }
214
+ catch (error) {
215
+ return UNDEFINED;
216
+ }
217
+ };
92
218
  CypressQaseReporter.prototype.log = function (message) {
93
219
  var optionalParams = [];
94
220
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -101,67 +227,124 @@ var CypressQaseReporter = /** @class */ (function (_super) {
101
227
  CypressQaseReporter.prototype.addRunnerListeners = function (runner) {
102
228
  var _this = this;
103
229
  runner.on(EVENT_TEST_PASS, function (test) {
104
- _this.publishCaseResult(test, models_1.ResultStatus.PASSED);
230
+ _this.transformCaseResultToBulkObject(test, src_1.ResultCreateStatusEnum.PASSED);
105
231
  });
106
232
  runner.on(EVENT_TEST_PENDING, function (test) {
107
- _this.publishCaseResult(test, models_1.ResultStatus.SKIPPED);
233
+ _this.transformCaseResultToBulkObject(test, src_1.ResultCreateStatusEnum.SKIPPED);
108
234
  });
109
235
  runner.on(EVENT_TEST_FAIL, function (test) {
110
- _this.publishCaseResult(test, models_1.ResultStatus.FAILED);
236
+ _this.transformCaseResultToBulkObject(test, src_1.ResultCreateStatusEnum.FAILED);
111
237
  });
112
- runner.on(EVENT_RUN_END, function () {
113
- if (_this.results.length === 0 && _this.shouldPublish === 0) {
114
- _this.log('No testcases were matched. Ensure that your tests are declared correctly.');
238
+ runner.addListener(EVENT_RUN_END, function () {
239
+ if (_this.resultsForPublishing.length === 0) {
240
+ _this.log('Nothing to send.');
115
241
  }
116
- if (_this.runId && _this.shouldPublish !== 0) {
117
- _this.log(chalk_1.default(templateObject_9 || (templateObject_9 = __makeTemplateObject(["{blue Waiting for 30 seconds to publish pending results}"], ["{blue Waiting for 30 seconds to publish pending results}"]))));
118
- var endTime = Date.now() + 30e3;
119
- while ((_this.shouldPublish !== 0) && (Date.now() < endTime)) {
120
- // sleep 500 ms
121
- var sharedArrayBuffer = new SharedArrayBuffer(8);
122
- var int32array = new Int32Array(sharedArrayBuffer);
123
- Atomics.wait(int32array, 0, 0, 500);
124
- }
125
- if (_this.runId && _this.shouldPublish !== 0) {
126
- _this.log(chalk_1.default(templateObject_10 || (templateObject_10 = __makeTemplateObject(["{red Could not send all results for 30 seconds after run. Please contact Qase Team.}"], ["{red Could not send all results for 30 seconds after run. Please contact Qase Team.}"]))));
127
- }
242
+ else if (_this.runId) {
243
+ var config = {
244
+ apiToken: CypressQaseReporter.getEnv(Envs.apiToken) || _this.options.apiToken || '',
245
+ basePath: CypressQaseReporter.getEnv(Envs.basePath) || _this.options.basePath,
246
+ headers: CypressQaseReporter.createHeaders(),
247
+ code: _this.options.projectCode,
248
+ runId: Number(_this.runId),
249
+ body: {
250
+ results: _this.resultsForPublishing,
251
+ },
252
+ runComplete: CypressQaseReporter.getEnv(Envs.runComplete) || _this.options.runComplete || false,
253
+ };
254
+ var screenshotsConfig = {
255
+ screenshotFolder: CypressQaseReporter.getEnv(Envs.screenshotFolder)
256
+ || _this.options.screenshotFolder
257
+ || 'screenshots',
258
+ sendScreenshot: CypressQaseReporter.getEnv(Envs.screenshotFolder)
259
+ || _this.options.sendScreenshot
260
+ || false,
261
+ };
262
+ child_process_1.spawnSync('node', [__dirname + "/reportBulk.js"], {
263
+ stdio: 'inherit',
264
+ env: Object.assign(process.env, {
265
+ reporting_config: JSON.stringify(config),
266
+ screenshots_config: JSON.stringify(screenshotsConfig),
267
+ }),
268
+ });
128
269
  }
129
270
  });
130
271
  };
131
272
  CypressQaseReporter.prototype.checkProject = function (projectCode, cb) {
132
- var _this = this;
133
- this.api.projects.exists(projectCode)
134
- .then(cb)
135
- .catch(function (err) {
136
- _this.log(err);
273
+ var _a;
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ var resp, err_1;
276
+ return __generator(this, function (_b) {
277
+ switch (_b.label) {
278
+ case 0:
279
+ _b.trys.push([0, 3, , 4]);
280
+ return [4 /*yield*/, this.api.projects.getProject(projectCode)];
281
+ case 1:
282
+ resp = _b.sent();
283
+ return [4 /*yield*/, cb(Boolean((_a = resp.data.result) === null || _a === void 0 ? void 0 : _a.code))];
284
+ case 2:
285
+ _b.sent();
286
+ return [3 /*break*/, 4];
287
+ case 3:
288
+ err_1 = _b.sent();
289
+ this.log(err_1);
290
+ this.isDisabled = true;
291
+ return [3 /*break*/, 4];
292
+ case 4: return [2 /*return*/];
293
+ }
294
+ });
137
295
  });
138
296
  };
139
297
  CypressQaseReporter.prototype.createRun = function (name, description, cb) {
140
- var _this = this;
141
- this.api.runs.create(this.options.projectCode, new models_1.RunCreate(name || "Automated run " + new Date().toISOString(), [],
142
- // eslint-disable-next-line camelcase
143
- { description: description || 'Cypress automated run', is_autotest: true }))
144
- .then(function (res) { return res.data; })
145
- .then(cb)
146
- .catch(function (err) {
147
- _this.log("Error on creating run " + err);
298
+ return __awaiter(this, void 0, void 0, function () {
299
+ var environmentId, runObject, res, err_2;
300
+ return __generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0:
303
+ _a.trys.push([0, 2, , 3]);
304
+ environmentId = Number(CypressQaseReporter.getEnv(Envs.environmentId)) ||
305
+ this.options.environmentId;
306
+ runObject = CypressQaseReporter.createRunObject(name || "Automated run " + new Date().toISOString(), [], {
307
+ description: description || 'Cypress automated run',
308
+ environment_id: environmentId,
309
+ is_autotest: true,
310
+ });
311
+ return [4 /*yield*/, this.api.runs.createRun(this.options.projectCode, runObject)];
312
+ case 1:
313
+ res = _a.sent();
314
+ cb(res.data);
315
+ return [3 /*break*/, 3];
316
+ case 2:
317
+ err_2 = _a.sent();
318
+ this.log("Error on creating run " + err_2);
319
+ this.isDisabled = true;
320
+ return [3 /*break*/, 3];
321
+ case 3: return [2 /*return*/];
322
+ }
323
+ });
148
324
  });
149
325
  };
326
+ // eslint-disable-next-line @typescript-eslint/require-await
150
327
  CypressQaseReporter.prototype.checkRun = function (runId, cb) {
151
- var _this = this;
152
- if (runId !== undefined) {
153
- this.api.runs.exists(this.options.projectCode, runId)
154
- .then(cb)
155
- .catch(function (err) {
156
- _this.log("Error on checking run " + err);
328
+ return __awaiter(this, void 0, void 0, function () {
329
+ var _this = this;
330
+ return __generator(this, function (_a) {
331
+ if (runId === undefined) {
332
+ cb(false);
333
+ return [2 /*return*/];
334
+ }
335
+ return [2 /*return*/, this.api.runs
336
+ .getRun(this.options.projectCode, Number(runId))
337
+ .then(function (resp) {
338
+ var _a, _b;
339
+ _this.log("Get run result on checking run " + ((_a = resp.data.result) === null || _a === void 0 ? void 0 : _a.id));
340
+ cb(Boolean((_b = resp.data.result) === null || _b === void 0 ? void 0 : _b.id));
341
+ })
342
+ .catch(function (err) {
343
+ _this.log("Error on checking run " + err);
344
+ _this.isDisabled = true;
345
+ })];
157
346
  });
158
- }
159
- else {
160
- cb(false);
161
- }
162
- };
163
- CypressQaseReporter.prototype.getEnv = function (name) {
164
- return process.env[name];
347
+ });
165
348
  };
166
349
  CypressQaseReporter.prototype.saveRunId = function (runId) {
167
350
  this.runId = runId;
@@ -175,62 +358,36 @@ var CypressQaseReporter = /** @class */ (function (_super) {
175
358
  }
176
359
  }
177
360
  };
178
- CypressQaseReporter.prototype.getCaseId = function (test) {
179
- var regexp = /(\(Qase ID: ([\d,]+)\))/;
180
- var results = regexp.exec(test.title);
181
- if (results && results.length === 3) {
182
- return results[2].split(',').map(function (value) { return Number.parseInt(value, 10); });
183
- }
184
- return [];
185
- };
186
361
  CypressQaseReporter.prototype.logTestItem = function (test) {
187
362
  var map = {
188
- failed: chalk_1.default(templateObject_11 || (templateObject_11 = __makeTemplateObject(["{red Test ", " ", "}"], ["{red Test ", " ", "}"])), test.title, test.state),
189
- passed: chalk_1.default(templateObject_12 || (templateObject_12 = __makeTemplateObject(["{green Test ", " ", "}"], ["{green Test ", " ", "}"])), test.title, test.state),
190
- pending: chalk_1.default(templateObject_13 || (templateObject_13 = __makeTemplateObject(["{blueBright Test ", " ", "}"], ["{blueBright Test ", " ", "}"])), test.title, test.state),
363
+ failed: chalk_1.default(templateObject_9 || (templateObject_9 = __makeTemplateObject(["{red Test ", " ", "}"], ["{red Test ", " ", "}"])), test.title, test.state),
364
+ passed: chalk_1.default(templateObject_10 || (templateObject_10 = __makeTemplateObject(["{green Test ", " ", "}"], ["{green Test ", " ", "}"])), test.title, test.state),
365
+ pending: chalk_1.default(templateObject_11 || (templateObject_11 = __makeTemplateObject(["{blueBright Test ", " ", "}"], ["{blueBright Test ", " ", "}"])), test.title, test.state),
191
366
  };
192
367
  if (test.state) {
193
368
  this.log(map[test.state]);
194
369
  }
195
370
  };
196
- CypressQaseReporter.prototype.publishCaseResult = function (test, status) {
371
+ CypressQaseReporter.prototype.transformCaseResultToBulkObject = function (test, status) {
197
372
  var _this = this;
198
373
  this.logTestItem(test);
199
- var caseIds = this.getCaseId(test);
374
+ var caseIds = CypressQaseReporter.getCaseId(test);
200
375
  caseIds.forEach(function (caseId) {
201
- _this.shouldPublish++;
202
- var publishTest = function (runId) {
203
- var _a;
204
- if (caseId) {
205
- var add_1 = caseIds.length > 1 ? chalk_1.default(templateObject_14 || (templateObject_14 = __makeTemplateObject([" {white For case ", "}"], [" {white For case ", "}"])), caseId) : '';
206
- _this.log(chalk_1.default(templateObject_15 || (templateObject_15 = __makeTemplateObject(["{gray Start publishing: ", "}", ""], ["{gray Start publishing: ", "}", ""])), test.title, add_1));
207
- _this.api.results.create(_this.options.projectCode, runId, new models_1.ResultCreate(caseId, status, {
208
- // eslint-disable-next-line camelcase
209
- time_ms: test.duration,
210
- stacktrace: (_a = test.err) === null || _a === void 0 ? void 0 : _a.stack,
211
- comment: test.err ? test.err.name + ": " + test.err.message : undefined,
212
- }))
213
- .then(function (res) {
214
- _this.results.push({ test: test, result: res.data });
215
- _this.log(chalk_1.default(templateObject_16 || (templateObject_16 = __makeTemplateObject(["{gray Result published: ", " ", "}", ""], ["{gray Result published: ", " ", "}", ""])), test.title, res.data.hash, add_1));
216
- _this.shouldPublish--;
217
- })
218
- .catch(function (err) {
219
- _this.log(err);
220
- _this.shouldPublish--;
221
- });
222
- }
223
- };
224
- if (_this.runId) {
225
- publishTest(_this.runId);
226
- }
227
- else {
228
- _this.pending.push(publishTest);
376
+ var _a;
377
+ if (caseId) {
378
+ var caseResultBulkObject = {
379
+ status: status,
380
+ case_id: caseId,
381
+ time_ms: test.duration || 0,
382
+ stacktrace: (_a = test.err) === null || _a === void 0 ? void 0 : _a.stack,
383
+ comment: test.err ? test.err.name + ": " + test.err.message : '',
384
+ };
385
+ _this.resultsForPublishing.push(caseResultBulkObject);
229
386
  }
230
387
  });
231
388
  };
232
389
  return CypressQaseReporter;
233
390
  }(mocha_1.reporters.Base));
234
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16;
391
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11;
235
392
  module.exports = CypressQaseReporter;
236
393
  //# sourceMappingURL=index.js.map