@alex_neo/playwright-azure-reporter 1.0.3 → 1.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ## [1.1.1](https://github.com/alexneo2003/playwright-azure-reporter/compare/v1.1.0...v1.1.1) (2022-07-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handling the existence of an attachment ([d16efbc](https://github.com/alexneo2003/playwright-azure-reporter/commit/d16efbcb099284ca3baa71e346199d968ed9e7cf))
7
+
8
+
9
+
10
+ # [1.1.0](https://github.com/alexneo2003/playwright-azure-reporter/compare/v1.0.4...v1.1.0) (2022-07-19)
11
+
12
+
13
+ ### Features
14
+
15
+ * added attachmentsType, full code refactoring ([b6e5c0f](https://github.com/alexneo2003/playwright-azure-reporter/commit/b6e5c0f364ff03595e6aef8240aca36ab7d91569))
16
+
17
+
18
+
package/README.md CHANGED
@@ -9,7 +9,7 @@ npm install @alex_neo/playwright-azure-reporter
9
9
  ## Usage
10
10
  You must register an ID already existing test cases from Azure DevOps before running tests.
11
11
 
12
- **You need write testCaseId inside square brackets at the test name.**
12
+ > **You need write testCaseId wraped in square brackets at the test name.**
13
13
 
14
14
  For example:
15
15
 
@@ -32,17 +32,6 @@ describe('Test suite', () => {
32
32
  })
33
33
  });
34
34
 
35
- ```
36
- You can use external file with Azure DevOps config values
37
-
38
- ```azure.config.json```
39
- ```json
40
- {
41
- "token": "AZURE-TOKEN",
42
- "orgUrl": "https://dev.azure.com/alex-neo",
43
- "projectName": "SampleProject",
44
- "testPlanId": 4
45
- }
46
35
  ```
47
36
 
48
37
  Configure Playwright Azure Reporter with `playwright-azure-reporter` package.
@@ -51,30 +40,41 @@ Configure Playwright Azure Reporter with `playwright-azure-reporter` package.
51
40
  ```typescript
52
41
  import { PlaywrightTestConfig } from '@playwright/test'
53
42
  import azureConfig from './azure.config.json'
43
+ import { AzureReporterOptions } from './src/playwright-azure-reporter'
54
44
 
45
+ /**
46
+ * See https://playwright.dev/docs/test-configuration.
47
+ */
55
48
  const config: PlaywrightTestConfig = {
56
49
  testDir: './tests',
57
50
  timeout: 30 * 1000,
51
+ expect: {
52
+ timeout: 5000
53
+ },
54
+ forbidOnly: !!process.env.CI,
55
+ retries: process.env.CI ? 2 : 0,
56
+ workers: process.env.CI ? 1 : undefined,
58
57
  reporter: [
59
58
  ['list'],
60
59
  [
61
60
  '@alex_neo/playwright-azure-reporter',
62
61
  {
63
- token: azureConfig.token,
64
- orgUrl: azureConfig.orgUrl,
65
- projectName: azureConfig.projectName,
66
- planId: azureConfig.testPlanId,
67
- environment: 'QA',
62
+ orgUrl: "https://dev.azure.com/your-organization-name",
63
+ token: "AZURE-TOKEN",
64
+ planId: 44,
65
+ projectName: "SampleSample",
66
+ environment: 'AQA',
68
67
  testRunTitle: 'Playwright Test Run',
69
- uploadAttachments: true
70
- isDisabled: false,
71
- }
68
+ uploadAttachments: true,
69
+ attachmentsType: ['screenshot', 'video', 'trace'],
70
+ } as AzureReporterOptions
72
71
  ]
73
72
  ],
74
73
  use: {
75
74
  screenshot: 'only-on-failure',
75
+ actionTimeout: 0,
76
+ trace: 'on-first-retry'
76
77
  }
77
-
78
78
  }
79
79
 
80
80
  export default config
@@ -86,11 +86,14 @@ export default config
86
86
  Reporter options (* - required):
87
87
 
88
88
  - *`token` - Azure DevOps token, you can find more information [here](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows)
89
- - *`orgUrl` - Full url for your organization space. Example: `https://dev.azure.com/alex-neo`
89
+ - *`orgUrl` - Full url for your organization space. Example: `https://dev.azure.com/your-organization-name`
90
+
91
+ > Please note that some API's (e.g. ProfileApi) can't be hit at the org level, and has to be hit at the deployment level, so url should be structured like https://vssps.dev.azure.com/{yourorgname}
90
92
  - *`projectName` - Name of your project (also can be got from run URL). Example: `https://dev.azure.com/alex-neo/SampleProject/` - __SampleProject__
91
93
  - *`planId` - Id of test plan. You can find it in test plan URL. Example: `https://dev.azure.com/alex-neo/SampleProject/_testPlans/execute?planId=4&suiteId=6` - __planId=4__
92
94
  - `environment` - Any string that will be used as environment name. Will be used as prefix for all test runs. Default: `undefined`. Example: `QA`
93
95
  - `logging` [true/false] - Enabled debug logging from reporter or not. Default: `true`.
94
96
  - `uploadAttachments` [true/false] - Uploading attachments (screenshot/video) after test ended. Default: `false`.
97
+ - `attachmentsType` - List of attachments types that will be uploaded. Default: `['screenshot']`.
95
98
  - `isDisabled` [true/false] - Disable reporter. Default: `false`.
96
- - `testRunTitle` - Title of test run. Default: `Playwright Test Run`.
99
+ - `testRunTitle` - Title of test run using to create new test run. Default: `Playwright Test Run`.
package/azure.config.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "token": "fbflfrmrw6ituk2ykeox5klqwoyzdtuvpyl4bee5fxak2ln3gqza",
3
- "orgUrl": "https://dev.azure.com/alex-neo",
2
+ "token": "token",
3
+ "orgUrl": "https://dev.azure.com/your-organization-name",
4
4
  "projectName": "SampleProject",
5
- "testPlanId": 4
6
- }
5
+ "testPlanId": 44
6
+ }
@@ -0,0 +1,51 @@
1
+ import { Reporter, TestCase, TestResult } from '@playwright/test/reporter';
2
+ export declare function createGuid(): string;
3
+ declare const attachmentTypesArray: readonly ["screenshot", "video", "trace"];
4
+ declare type TAttachmentType = Array<typeof attachmentTypesArray[number]>;
5
+ export interface AzureReporterOptions {
6
+ token: string;
7
+ planId: number;
8
+ orgUrl: string;
9
+ projectName: string;
10
+ logging?: boolean | undefined;
11
+ isDisabled?: boolean | undefined;
12
+ environment?: string | undefined;
13
+ testRunTitle?: string | undefined;
14
+ uploadAttachments?: boolean | undefined;
15
+ attachmentsType?: TAttachmentType | undefined;
16
+ }
17
+ declare class AzureDevOpsReporter implements Reporter {
18
+ private testApi;
19
+ private coreApi;
20
+ private _options;
21
+ private publishedResultsCount;
22
+ private resultsToBePublished;
23
+ private connection;
24
+ private orgUrl;
25
+ private projectName;
26
+ private environment?;
27
+ private planId;
28
+ private runId;
29
+ private logging;
30
+ private isDisabled;
31
+ private testRunTitle;
32
+ private uploadAttachments;
33
+ private attachmentsType?;
34
+ private token;
35
+ constructor(options?: AzureReporterOptions);
36
+ onBegin(): Promise<void>;
37
+ onTestEnd(test: TestCase, testResult: TestResult): Promise<void>;
38
+ onEnd(): Promise<void>;
39
+ private log;
40
+ private getCaseIds;
41
+ private logTestItem;
42
+ private createRun;
43
+ private removePublished;
44
+ private checkProject;
45
+ private getTestPointIdsByTCIds;
46
+ private addReportingOverride;
47
+ private uploadAttachmentsFunc;
48
+ private awaitForRunId;
49
+ private publishCaseResult;
50
+ }
51
+ export default AzureDevOpsReporter;
@@ -0,0 +1,597 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.createGuid = void 0;
66
+ /* eslint-disable no-control-regex */
67
+ var azdev = __importStar(require("azure-devops-node-api"));
68
+ var chalk_1 = __importDefault(require("chalk"));
69
+ var crypto_1 = __importDefault(require("crypto"));
70
+ var fs_1 = require("fs");
71
+ function createGuid() {
72
+ return crypto_1.default.randomBytes(16).toString('hex');
73
+ }
74
+ exports.createGuid = createGuid;
75
+ var Statuses = {
76
+ passed: 'Passed',
77
+ failed: 'Failed',
78
+ skipped: 'Paused',
79
+ timedOut: 'Failed'
80
+ };
81
+ var attachmentTypesArray = [
82
+ 'screenshot',
83
+ 'video',
84
+ 'trace',
85
+ ];
86
+ var AzureDevOpsReporter = /** @class */ (function () {
87
+ function AzureDevOpsReporter(options) {
88
+ if (options === void 0) { options = {}; }
89
+ this.publishedResultsCount = 0;
90
+ this.resultsToBePublished = [];
91
+ this.planId = 0;
92
+ this.logging = true;
93
+ this.isDisabled = false;
94
+ this.testRunTitle = '';
95
+ this.uploadAttachments = false;
96
+ this.token = '';
97
+ this.addReportingOverride = function (api) {
98
+ // https://github.com/microsoft/azure-devops-node-api/issues/318#issuecomment-498802402
99
+ api.addTestResultsToTestRun = function (results, projectName, runId) {
100
+ var _this = this;
101
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
102
+ var routeValues, verData, url, options, res, err_1;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ routeValues = {
107
+ project: projectName,
108
+ runId: runId
109
+ };
110
+ _a.label = 1;
111
+ case 1:
112
+ _a.trys.push([1, 4, , 5]);
113
+ return [4 /*yield*/, this.vsoClient.getVersioningData('5.0-preview.5', 'Test', '4637d869-3a76-4468-8057-0bb02aa385cf', routeValues)];
114
+ case 2:
115
+ verData = _a.sent();
116
+ url = verData.requestUrl;
117
+ options = this.createRequestOptions('application/json', verData.apiVersion);
118
+ return [4 /*yield*/, this.rest.create(url, results, options)];
119
+ case 3:
120
+ res = _a.sent();
121
+ resolve(res);
122
+ return [3 /*break*/, 5];
123
+ case 4:
124
+ err_1 = _a.sent();
125
+ reject(err_1);
126
+ return [3 /*break*/, 5];
127
+ case 5: return [2 /*return*/];
128
+ }
129
+ });
130
+ }); });
131
+ };
132
+ return api;
133
+ };
134
+ this._options = options;
135
+ this.orgUrl = this._options.orgUrl;
136
+ this.projectName = this._options.projectName;
137
+ this.environment = this._options.environment || undefined;
138
+ this.planId = this._options.planId;
139
+ this.logging = (typeof this._options.logging === 'undefined') ? true : this._options.logging;
140
+ this.isDisabled = this._options.isDisabled || false;
141
+ this.testRunTitle = "".concat(this.environment ? "[".concat(this.environment, "]:") : '', " ").concat(this._options.testRunTitle || 'Playwright Test Run') ||
142
+ "".concat(this.environment ? "[".concat(this.environment, "]:") : '', "Test plan ").concat(this.planId);
143
+ this.uploadAttachments = this._options.uploadAttachments || false;
144
+ this.attachmentsType = this._options.attachmentsType;
145
+ this.token = this._options.token;
146
+ if (!this.orgUrl || this.orgUrl.length === 0) {
147
+ this.log(chalk_1.default.yellow("'orgUrl' is not set. Reporting is disabled."));
148
+ this.isDisabled = true;
149
+ return;
150
+ }
151
+ if (!this.projectName || this.projectName.length === 0) {
152
+ this.log(chalk_1.default.yellow("'projectName' is not set. Reporting is disabled."));
153
+ this.isDisabled = true;
154
+ return;
155
+ }
156
+ if (!this.planId || this.planId === 0) {
157
+ this.log(chalk_1.default.yellow("'planId' is not set. Reporting is disabled."));
158
+ this.isDisabled = true;
159
+ return;
160
+ }
161
+ if (!this.token || this.token.length === 0) {
162
+ this.log(chalk_1.default.yellow("'token' is not set. Reporting is disabled."));
163
+ this.isDisabled = true;
164
+ }
165
+ if (this.uploadAttachments) {
166
+ if (!this.attachmentsType) {
167
+ this.log(chalk_1.default.yellow("'attachmentsType' is not set. Attachments Type will be set to 'screenshot' by default."));
168
+ this.attachmentsType = ['screenshot'];
169
+ }
170
+ }
171
+ this.connection = new azdev.WebApi(this.orgUrl, azdev.getPersonalAccessTokenHandler(this.token));
172
+ }
173
+ AzureDevOpsReporter.prototype.onBegin = function () {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var _a;
176
+ var _this = this;
177
+ return __generator(this, function (_b) {
178
+ switch (_b.label) {
179
+ case 0:
180
+ if (this.isDisabled)
181
+ return [2 /*return*/];
182
+ _a = this;
183
+ return [4 /*yield*/, this.connection.getTestApi()];
184
+ case 1:
185
+ _a.testApi = _b.sent();
186
+ this.createRun(this.testRunTitle).then(function (run) {
187
+ if (run) {
188
+ _this.runId = run.id;
189
+ _this.log(chalk_1.default.green("Using run ".concat(_this.runId, " to publish test results")));
190
+ }
191
+ else {
192
+ _this.isDisabled = true;
193
+ }
194
+ });
195
+ return [2 /*return*/];
196
+ }
197
+ });
198
+ });
199
+ };
200
+ AzureDevOpsReporter.prototype.onTestEnd = function (test, testResult) {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ var _this = this;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0: return [4 /*yield*/, this.awaitForRunId().catch(function (e) {
206
+ _this.log(chalk_1.default.red(e));
207
+ })];
208
+ case 1:
209
+ _a.sent();
210
+ if (this.isDisabled)
211
+ return [2 /*return*/];
212
+ this.logTestItem(test, testResult);
213
+ return [4 /*yield*/, this.publishCaseResult(test, testResult)];
214
+ case 2:
215
+ _a.sent();
216
+ return [2 /*return*/];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ AzureDevOpsReporter.prototype.onEnd = function () {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var prevCount, runUpdate, _a, runUpdatedResponse, err_2;
224
+ var _this = this;
225
+ return __generator(this, function (_b) {
226
+ switch (_b.label) {
227
+ case 0: return [4 /*yield*/, this.awaitForRunId().catch(function (e) {
228
+ _this.log(chalk_1.default.red(e));
229
+ })];
230
+ case 1:
231
+ _b.sent();
232
+ if (this.isDisabled)
233
+ return [2 /*return*/];
234
+ prevCount = this.resultsToBePublished.length;
235
+ _b.label = 2;
236
+ case 2:
237
+ if (!(this.resultsToBePublished.length > 0)) return [3 /*break*/, 4];
238
+ // need wait all results to be published
239
+ if (prevCount > this.resultsToBePublished.length) {
240
+ this.log(chalk_1.default.gray("Waiting for all results to be published. Remaining ".concat(this.resultsToBePublished.length, " results")));
241
+ prevCount--;
242
+ }
243
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 250); })];
244
+ case 3:
245
+ _b.sent();
246
+ return [3 /*break*/, 2];
247
+ case 4:
248
+ if (this.publishedResultsCount === 0 && !this.runId) {
249
+ this.log('No testcases were matched. Ensure that your tests are declared correctly.');
250
+ return [2 /*return*/];
251
+ }
252
+ _b.label = 5;
253
+ case 5:
254
+ _b.trys.push([5, 9, , 10]);
255
+ runUpdate = {
256
+ state: 'Completed'
257
+ };
258
+ if (!!this.testApi) return [3 /*break*/, 7];
259
+ _a = this;
260
+ return [4 /*yield*/, this.connection.getTestApi()];
261
+ case 6:
262
+ _a.testApi = _b.sent();
263
+ _b.label = 7;
264
+ case 7: return [4 /*yield*/, this.testApi.updateTestRun(runUpdate, this.projectName, this.runId)];
265
+ case 8:
266
+ runUpdatedResponse = _b.sent();
267
+ this.log(chalk_1.default.green("Run ".concat(this.runId, " - ").concat(runUpdatedResponse.state)));
268
+ return [3 /*break*/, 10];
269
+ case 9:
270
+ err_2 = _b.sent();
271
+ this.log("Error on completing run ".concat(err_2));
272
+ return [3 /*break*/, 10];
273
+ case 10: return [2 /*return*/];
274
+ }
275
+ });
276
+ });
277
+ };
278
+ AzureDevOpsReporter.prototype.log = function (message) {
279
+ if (this.logging)
280
+ console.log(chalk_1.default.magenta("azure: ".concat(message)));
281
+ };
282
+ AzureDevOpsReporter.prototype.getCaseIds = function (test) {
283
+ var regexp = /\[([\d,]+)\]/;
284
+ var results = regexp.exec(test.title);
285
+ if (results && results.length === 2)
286
+ return results[1];
287
+ return '';
288
+ };
289
+ AzureDevOpsReporter.prototype.logTestItem = function (test, testResult) {
290
+ var map = {
291
+ failed: chalk_1.default.red("Test ".concat(test.title, " - ").concat(testResult.status)),
292
+ passed: chalk_1.default.green("Test ".concat(test.title, " - ").concat(testResult.status)),
293
+ skipped: chalk_1.default.blue("Test ".concat(test.title, " - ").concat(testResult.status)),
294
+ pending: chalk_1.default.blue("Test ".concat(test.title, " - ").concat(testResult.status)),
295
+ disabled: chalk_1.default.gray("Test ".concat(test.title, " - ").concat(testResult.status)),
296
+ timedOut: chalk_1.default.gray("Test ".concat(test.title, " - ").concat(testResult.status))
297
+ };
298
+ if (testResult.status)
299
+ this.log(map[testResult.status]);
300
+ };
301
+ AzureDevOpsReporter.prototype.createRun = function (runName) {
302
+ return __awaiter(this, void 0, void 0, function () {
303
+ var _this = this;
304
+ return __generator(this, function (_a) {
305
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
306
+ var runModel, _a, adTestRun, e_1;
307
+ return __generator(this, function (_b) {
308
+ switch (_b.label) {
309
+ case 0:
310
+ _b.trys.push([0, 4, , 5]);
311
+ this.checkProject(this.projectName).catch(function (e) {
312
+ reject(e);
313
+ });
314
+ runModel = {
315
+ name: runName,
316
+ automated: true,
317
+ configurationIds: [1],
318
+ plan: { id: "".concat(this.planId) }
319
+ };
320
+ if (!!this.testApi) return [3 /*break*/, 2];
321
+ _a = this;
322
+ return [4 /*yield*/, this.connection.getTestApi()];
323
+ case 1:
324
+ _a.testApi = _b.sent();
325
+ _b.label = 2;
326
+ case 2: return [4 /*yield*/, this.testApi.createTestRun(runModel, this.projectName)];
327
+ case 3:
328
+ adTestRun = _b.sent();
329
+ resolve(adTestRun);
330
+ return [3 /*break*/, 5];
331
+ case 4:
332
+ e_1 = _b.sent();
333
+ reject(e_1);
334
+ return [3 /*break*/, 5];
335
+ case 5: return [2 /*return*/];
336
+ }
337
+ });
338
+ }); }).catch(function (e) {
339
+ _this.log(chalk_1.default.red("While creating test run.\n ".concat(e)));
340
+ _this.isDisabled = true;
341
+ throw e;
342
+ })];
343
+ });
344
+ });
345
+ };
346
+ AzureDevOpsReporter.prototype.removePublished = function (testAlias) {
347
+ var resultIndex = this.resultsToBePublished.indexOf(testAlias);
348
+ if (resultIndex !== -1)
349
+ this.resultsToBePublished.splice(resultIndex, 1);
350
+ };
351
+ AzureDevOpsReporter.prototype.checkProject = function (projectName) {
352
+ return __awaiter(this, void 0, void 0, function () {
353
+ var _this = this;
354
+ return __generator(this, function (_a) {
355
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
356
+ var _a, project, e_2;
357
+ return __generator(this, function (_b) {
358
+ switch (_b.label) {
359
+ case 0:
360
+ _b.trys.push([0, 4, , 5]);
361
+ if (!!this.coreApi) return [3 /*break*/, 2];
362
+ _a = this;
363
+ return [4 /*yield*/, this.connection.getCoreApi()];
364
+ case 1:
365
+ _a.coreApi = _b.sent();
366
+ _b.label = 2;
367
+ case 2: return [4 /*yield*/, this.coreApi.getProject(projectName)];
368
+ case 3:
369
+ project = _b.sent();
370
+ if (project)
371
+ resolve(project);
372
+ else
373
+ reject("Project ".concat(projectName, " does not exist. Reporting is disabled."));
374
+ return [3 /*break*/, 5];
375
+ case 4:
376
+ e_2 = _b.sent();
377
+ reject(e_2);
378
+ return [3 /*break*/, 5];
379
+ case 5: return [2 /*return*/];
380
+ }
381
+ });
382
+ }); }).catch(function (e) {
383
+ _this.log(e);
384
+ _this.isDisabled = true;
385
+ })];
386
+ });
387
+ });
388
+ };
389
+ AzureDevOpsReporter.prototype.getTestPointIdsByTCIds = function (planId, testcaseIds) {
390
+ return __awaiter(this, void 0, void 0, function () {
391
+ var _this = this;
392
+ return __generator(this, function (_a) {
393
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
394
+ var pointsQuery, _a, pointsQueryResult, pointsIds_1, e_3;
395
+ var _this = this;
396
+ return __generator(this, function (_b) {
397
+ switch (_b.label) {
398
+ case 0:
399
+ _b.trys.push([0, 4, , 5]);
400
+ pointsQuery = {
401
+ pointsFilter: { testcaseIds: testcaseIds }
402
+ };
403
+ if (!!this.testApi) return [3 /*break*/, 2];
404
+ _a = this;
405
+ return [4 /*yield*/, this.connection.getTestApi()];
406
+ case 1:
407
+ _a.testApi = _b.sent();
408
+ _b.label = 2;
409
+ case 2: return [4 /*yield*/, this.testApi.getPointsByQuery(pointsQuery, this.projectName)];
410
+ case 3:
411
+ pointsQueryResult = _b.sent();
412
+ pointsIds_1 = [];
413
+ if (pointsQueryResult.points) {
414
+ pointsQueryResult.points.forEach(function (point) {
415
+ if (point.testPlan && point.testPlan.id && parseInt(point.testPlan.id, 10) === planId)
416
+ pointsIds_1.push(point.id);
417
+ else
418
+ reject("Could not find test point for test case [".concat(point.testCase.id, "] associated with test plan ").concat(_this.planId, ". Check, maybe testPlanId, what you specifiyed, is incorrect."));
419
+ });
420
+ }
421
+ resolve(pointsIds_1);
422
+ return [3 /*break*/, 5];
423
+ case 4:
424
+ e_3 = _b.sent();
425
+ this.log(chalk_1.default.red("While getting test points ids, by test cases ids.\n ".concat(e_3)));
426
+ reject(e_3);
427
+ return [3 /*break*/, 5];
428
+ case 5: return [2 /*return*/];
429
+ }
430
+ });
431
+ }); })];
432
+ });
433
+ });
434
+ };
435
+ AzureDevOpsReporter.prototype.uploadAttachmentsFunc = function (testResult, caseId, testCaseId) {
436
+ return __awaiter(this, void 0, void 0, function () {
437
+ var _this = this;
438
+ return __generator(this, function (_a) {
439
+ switch (_a.label) {
440
+ case 0:
441
+ this.log(chalk_1.default.gray("Start upload attachments for test case [".concat(testCaseId, "]")));
442
+ return [4 /*yield*/, Promise.all(testResult.attachments.map(function (attachment) { return __awaiter(_this, void 0, void 0, function () {
443
+ var attachments, _a, response;
444
+ return __generator(this, function (_b) {
445
+ switch (_b.label) {
446
+ case 0:
447
+ if (!this.attachmentsType.includes(attachment.name)) return [3 /*break*/, 6];
448
+ if (!(0, fs_1.existsSync)(attachment.path)) return [3 /*break*/, 4];
449
+ attachments = {
450
+ attachmentType: 'GeneralAttachment',
451
+ fileName: "".concat(attachment.name, "-").concat(createGuid(), ".").concat(attachment.contentType.split('/')[1]),
452
+ stream: (0, fs_1.readFileSync)(attachment.path, { encoding: 'base64' })
453
+ };
454
+ if (!!this.testApi) return [3 /*break*/, 2];
455
+ _a = this;
456
+ return [4 /*yield*/, this.connection.getTestApi()];
457
+ case 1:
458
+ _a.testApi = _b.sent();
459
+ _b.label = 2;
460
+ case 2: return [4 /*yield*/, this.testApi.createTestResultAttachment(attachments, this.projectName, this.runId, caseId)];
461
+ case 3:
462
+ response = _b.sent();
463
+ return [2 /*return*/, response.url];
464
+ case 4:
465
+ this.log(chalk_1.default.red("Attachment ".concat(attachment.path, " does not exist.")));
466
+ return [2 /*return*/, ''];
467
+ case 5: return [3 /*break*/, 7];
468
+ case 6: return [2 /*return*/, ''];
469
+ case 7: return [2 /*return*/];
470
+ }
471
+ });
472
+ }); }))];
473
+ case 1: return [2 /*return*/, _a.sent()];
474
+ }
475
+ });
476
+ });
477
+ };
478
+ AzureDevOpsReporter.prototype.awaitForRunId = function () {
479
+ return __awaiter(this, void 0, void 0, function () {
480
+ var _this = this;
481
+ return __generator(this, function (_a) {
482
+ // need wait runId variable to be initialised in onBegin() hook
483
+ if (this.isDisabled)
484
+ return [2 /*return*/];
485
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
486
+ var timeout, startTime;
487
+ return __generator(this, function (_a) {
488
+ switch (_a.label) {
489
+ case 0:
490
+ timeout = 10000;
491
+ startTime = Date.now();
492
+ _a.label = 1;
493
+ case 1:
494
+ if (!(this.runId === undefined && Date.now() - startTime < timeout)) return [3 /*break*/, 3];
495
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 250); })];
496
+ case 2:
497
+ _a.sent();
498
+ return [3 /*break*/, 1];
499
+ case 3:
500
+ if (this.runId === undefined) {
501
+ this.isDisabled = true;
502
+ reject('Timeout while waiting for runId. Reporting is disabled.');
503
+ }
504
+ else {
505
+ resolve(this.runId);
506
+ }
507
+ return [2 /*return*/];
508
+ }
509
+ });
510
+ }); })];
511
+ });
512
+ });
513
+ };
514
+ AzureDevOpsReporter.prototype.publishCaseResult = function (test, testResult) {
515
+ return __awaiter(this, void 0, void 0, function () {
516
+ var caseId;
517
+ var _this = this;
518
+ return __generator(this, function (_a) {
519
+ caseId = this.getCaseIds(test);
520
+ if (caseId === '')
521
+ return [2 /*return*/];
522
+ return [2 /*return*/, new Promise(function (resolved, reject) { return __awaiter(_this, void 0, void 0, function () {
523
+ var testAlias, pointIds, results, _a, testCaseResult, err_3;
524
+ var _this = this;
525
+ var _b, _c, _d, _e;
526
+ return __generator(this, function (_f) {
527
+ switch (_f.label) {
528
+ case 0:
529
+ testAlias = "".concat(caseId, " - ").concat(test.title);
530
+ this.resultsToBePublished.push(testAlias);
531
+ this.log(chalk_1.default.gray("Start publishing: ".concat(test.title)));
532
+ return [4 /*yield*/, this.getTestPointIdsByTCIds(this.planId, [parseInt(caseId, 10)]).catch(function (e) {
533
+ _this.log(chalk_1.default.red("While getting test point ids, by test cases ids.\n ".concat(e)));
534
+ _this.removePublished(testAlias);
535
+ return;
536
+ })];
537
+ case 1:
538
+ pointIds = _f.sent();
539
+ if (!pointIds || !pointIds.length) {
540
+ this.log(chalk_1.default.red("No test points found for test case [".concat(caseId, "]")));
541
+ this.removePublished(testAlias);
542
+ return [2 /*return*/];
543
+ }
544
+ _f.label = 2;
545
+ case 2:
546
+ _f.trys.push([2, 8, , 9]);
547
+ results = [
548
+ {
549
+ testCase: { id: caseId },
550
+ testPoint: { id: pointIds[0].toString() },
551
+ testCaseTitle: test.title,
552
+ outcome: Statuses[testResult.status],
553
+ state: 'Completed',
554
+ durationInMs: testResult.duration,
555
+ errorMessage: testResult.error
556
+ ? "".concat(test.title, ": ").concat((_c = (_b = testResult.error) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.replace(/\u001b\[.*?m/g, ''))
557
+ : undefined,
558
+ stackTrace: (_e = (_d = testResult.error) === null || _d === void 0 ? void 0 : _d.stack) === null || _e === void 0 ? void 0 : _e.replace(/\u001b\[.*?m/g, '')
559
+ }
560
+ ];
561
+ if (!!this.testApi) return [3 /*break*/, 4];
562
+ _a = this;
563
+ return [4 /*yield*/, this.connection.getTestApi()];
564
+ case 3:
565
+ _a.testApi = _f.sent();
566
+ _f.label = 4;
567
+ case 4: return [4 /*yield*/, this.addReportingOverride(this.testApi).addTestResultsToTestRun(results, this.projectName, this.runId)];
568
+ case 5:
569
+ testCaseResult = _f.sent();
570
+ if (!(this.uploadAttachments && testResult.attachments.length > 0)) return [3 /*break*/, 7];
571
+ return [4 /*yield*/, this.uploadAttachmentsFunc(testResult, testCaseResult.result.value[0].id, caseId)];
572
+ case 6:
573
+ _f.sent();
574
+ _f.label = 7;
575
+ case 7:
576
+ this.removePublished(testAlias);
577
+ this.publishedResultsCount++;
578
+ this.log(chalk_1.default.gray("Result published: ".concat(test.title)));
579
+ resolved(testCaseResult);
580
+ return [3 /*break*/, 9];
581
+ case 8:
582
+ err_3 = _f.sent();
583
+ this.removePublished(testAlias);
584
+ this.log(chalk_1.default.red(err_3));
585
+ reject(err_3);
586
+ return [3 /*break*/, 9];
587
+ case 9: return [2 /*return*/];
588
+ }
589
+ });
590
+ }); })];
591
+ });
592
+ });
593
+ };
594
+ return AzureDevOpsReporter;
595
+ }());
596
+ exports.default = AzureDevOpsReporter;
597
+ //# sourceMappingURL=playwright-azure-reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-azure-reporter.js","sourceRoot":"","sources":["../src/playwright-azure-reporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,2DAA8C;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AkC,CAAC;;wCACP,qBAAM,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,EAAA;;oCAAnJ,cAAc,GAAyB,SAA+I;yCACxL,CAAA,IAAI,CAAC,iBAAiB,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAA,EAA3D,wBAA2D;oCAC7D,qBAAM,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,cAAc,CAAC,MAAM,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAA;;oCAAxF,SAAwF,CAAC;;;oCAE3F,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;oCAChC,IAAI,CAAC,qBAAqB,EAAE,CAAC;oCAC7B,IAAI,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,4BAAqB,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC;oCACxD,QAAQ,CAAC,cAAc,CAAC,CAAC;;;;oCAEzB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;oCAChC,IAAI,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,KAAG,CAAC,CAAC,CAAC;oCACzB,MAAM,CAAC,KAAG,CAAC,CAAC;;;;;yBAEf,CAAC,EAAC;;;KACJ;IACH,0BAAC;AAAD,CAAC,AAhXD,IAgXC;AAED,kBAAe,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alex_neo/playwright-azure-reporter",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "Playwright Azure Reporter",
5
5
  "main": "./dist/playwright-azure-reporter.js",
6
6
  "types": "./dist/playwright-azure-reporter.d.js",
@@ -12,7 +12,8 @@
12
12
  "clean": "rm -rf dist || true",
13
13
  "prepublishOnly": "tsc",
14
14
  "dev": "npm run lint && tsc",
15
- "dev:watch": "nodemon --watch src --exec \"npm run build\""
15
+ "dev:watch": "nodemon --watch src --exec \"npm run build\"",
16
+ "version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
16
17
  },
17
18
  "keywords": [
18
19
  "playwright",
@@ -27,17 +28,21 @@
27
28
  "email": "alexneo2003@gmail.com",
28
29
  "url": "https://github.com/alexneo2003/"
29
30
  },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/alexneo2003/playwright-azure-reporter"
34
+ },
30
35
  "license": "ISC",
31
36
  "dependencies": {
32
37
  "azure-devops-node-api": "^11.1.1",
33
- "chalk": "4.1.0"
38
+ "chalk": "^4.1.2",
39
+ "cryptojs": "^2.5.3"
34
40
  },
35
41
  "devDependencies": {
36
- "@playwright/test": "^1.22.2",
42
+ "@playwright/test": "^1.23.4",
37
43
  "@typescript-eslint/eslint-plugin": "^5.27.1",
38
44
  "@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
39
45
  "@typescript-eslint/parser": "^5.27.1",
40
- "chalk": "^4.1.0",
41
46
  "eslint": "^8.17.0",
42
47
  "eslint-config-standard": "^17.0.0",
43
48
  "eslint-plugin-import": "^2.26.0",
@@ -1,33 +1,19 @@
1
1
  import { PlaywrightTestConfig } from '@playwright/test'
2
2
  import azureConfig from './azure.config.json'
3
-
4
- /**
5
- * Read environment variables from file.
6
- * https://github.com/motdotla/dotenv
7
- */
8
- // require('dotenv').config();
3
+ import { AzureReporterOptions } from './src/playwright-azure-reporter'
9
4
 
10
5
  /**
11
6
  * See https://playwright.dev/docs/test-configuration.
12
7
  */
13
8
  const config: PlaywrightTestConfig = {
14
9
  testDir: './tests',
15
- /* Maximum time one test can run for. */
16
10
  timeout: 30 * 1000,
17
11
  expect: {
18
- /**
19
- * Maximum time expect() should wait for the condition to be met.
20
- * For example in `await expect(locator).toHaveText();`
21
- */
22
12
  timeout: 5000
23
13
  },
24
- /* Fail the build on CI if you accidentally left test.only in the source code. */
25
14
  forbidOnly: !!process.env.CI,
26
- /* Retry on CI only */
27
15
  retries: process.env.CI ? 2 : 0,
28
- /* Opt out of parallel tests on CI. */
29
16
  workers: process.env.CI ? 1 : undefined,
30
- /* Reporter to use. See https://playwright.dev/docs/test-reporters */
31
17
  reporter: [
32
18
  ['list'],
33
19
  [
@@ -37,32 +23,18 @@ const config: PlaywrightTestConfig = {
37
23
  token: azureConfig.token,
38
24
  planId: azureConfig.testPlanId,
39
25
  projectName: azureConfig.projectName,
40
- // environment: 'AQA',
26
+ environment: 'AQA',
41
27
  testRunTitle: 'Playwright Test Run',
42
- uploadAttachments: false
43
- }
28
+ uploadAttachments: true,
29
+ // attachmentsType: ['screenshot'],
30
+ } as AzureReporterOptions
44
31
  ]
45
32
  ],
46
- /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
47
33
  use: {
48
34
  screenshot: 'only-on-failure',
49
- /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
50
35
  actionTimeout: 0,
51
- /* Base URL to use in actions like `await page.goto('/')`. */
52
- // baseURL: 'http://localhost:3000',
53
-
54
- /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
55
36
  trace: 'on-first-retry'
56
37
  }
57
-
58
- /* Folder for test artifacts such as screenshots, videos, traces, etc. */
59
- // outputDir: 'test-results/',
60
-
61
- /* Run your local dev server before starting the tests */
62
- // webServer: {
63
- // command: 'npm run start',
64
- // port: 3000,
65
- // },
66
38
  }
67
39
 
68
40
  export default config
@@ -1,381 +0,0 @@
1
- /* eslint-disable no-control-regex */
2
- import * as Test from 'azure-devops-node-api/TestApi'
3
- import * as TestInterfaces from 'azure-devops-node-api/interfaces/TestInterfaces'
4
- import * as azdev from 'azure-devops-node-api'
5
-
6
- import { Reporter, TestCase, TestResult } from '@playwright/test/reporter'
7
-
8
- import { TestPoint } from 'azure-devops-node-api/interfaces/TestInterfaces'
9
- import { WebApi } from 'azure-devops-node-api'
10
- import chalk from 'chalk'
11
- import { readFileSync } from 'fs'
12
-
13
- const Statuses = {
14
- passed: 'Passed',
15
- failed: 'Failed',
16
- skipped: 'Paused',
17
- timedOut: 'Failed'
18
- }
19
-
20
- interface AzureOptions {
21
- token: string;
22
- planId: number;
23
- orgUrl: string;
24
- connection: WebApi;
25
- projectName: string;
26
- runId?: string;
27
- logging?: boolean;
28
- isDisabled?: boolean;
29
- environment?: string | undefined;
30
- testRunTitle: string;
31
- uploadAttachments?: boolean;
32
- }
33
-
34
- interface TestResultsToTestRun {
35
- statusCode: number;
36
- result: Result;
37
- headers: Headers;
38
- }
39
- interface Result {
40
- count: number;
41
- value?: ValueEntity[] | null;
42
- }
43
- interface ValueEntity {
44
- id: number;
45
- project: Project;
46
- outcome: string;
47
- testRun: TestRun;
48
- priority: number;
49
- url: string;
50
- lastUpdatedBy: LastUpdatedBy;
51
- }
52
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
53
- interface Project {
54
- }
55
- interface TestRun {
56
- id: string;
57
- }
58
- interface LastUpdatedBy {
59
- displayName?: null;
60
- id?: null;
61
- }
62
- interface Headers {
63
- 'cache-control': string;
64
- 'pragma': string;
65
- 'content-length': string;
66
- 'content-type': string;
67
- 'expires': string;
68
- 'p3p': string;
69
- 'x-tfs-processid': string;
70
- 'strict-transport-security': string;
71
- 'activityid': string;
72
- 'x-tfs-session': string;
73
- 'x-vss-e2eid': string;
74
- 'x-vss-senderdeploymentid': string;
75
- 'x-vss-userdata': string;
76
- 'x-frame-options': string;
77
- 'request-context': string;
78
- 'access-control-expose-headers': string;
79
- 'x-content-type-options': string;
80
- 'x-cache': string;
81
- 'x-msedge-ref': string;
82
- 'date': string;
83
- 'connection': string;
84
- }
85
-
86
- const alwaysUndefined = () => undefined
87
-
88
- class PlaywrightReporter implements Reporter {
89
- private testApi!: Test.ITestApi;
90
- private options: AzureOptions;
91
- private planId: number | string;
92
- private runId?: number;
93
- private isDisabled = false;
94
- private publishedResultsCount = 0;
95
- private resultsToBePublished: string[] = [];
96
- private orgUrl: string;
97
- private connection: WebApi;
98
- private projectName: string;
99
- private environment: string | undefined;
100
- private logging = true;
101
- private testRunTitle: string;
102
-
103
- public constructor (_options: AzureOptions) {
104
- this.options = _options
105
- this.orgUrl = _options.orgUrl
106
- this.projectName = _options.projectName
107
- this.environment = _options.environment || undefined
108
- this.planId = _options.planId
109
- this.logging = _options.logging || true
110
- this.isDisabled = _options.isDisabled || false
111
- this.testRunTitle = `${this.environment ? `[${this.environment}]:` : ''} ${_options.testRunTitle || 'Playwright Test Run'}` ||
112
- `${this.environment ? `[${this.environment}]:` : ''}Test plan ${this.planId}`
113
- this.connection = new azdev.WebApi(this.orgUrl, azdev.getPersonalAccessTokenHandler(this.options.token))
114
- this.options.uploadAttachments = _options.uploadAttachments || false
115
-
116
- if (!this.orgUrl) {
117
- this.log(chalk`{yellow 'orgUrl' is not set. Reporting is disabled.}`)
118
- this.isDisabled = true
119
- return
120
- }
121
- if (!this.projectName || !this.planId) {
122
- this.log(chalk`{yellow 'projectName' is not set. Reporting is disabled.}`)
123
- this.isDisabled = true
124
- return
125
- }
126
- if (!this.planId) {
127
- this.log(chalk`{yellow 'planId' is not set. Reporting is disabled.}`)
128
- this.isDisabled = true
129
- return
130
- }
131
- if (!this.options.token) {
132
- this.log(chalk`{yellow 'token' is not set. Reporting is disabled.}`)
133
- this.isDisabled = true
134
- }
135
- }
136
-
137
- public async onBegin (): Promise<void> {
138
- if (this.isDisabled) {
139
- return
140
- }
141
- this.testApi = await this.connection.getTestApi()
142
-
143
- return this.createRun(this.testRunTitle, (created) => {
144
- if (created) {
145
- this.runId = created.id
146
- this.log(chalk`{green Using run ${this.runId} to publish test results}`)
147
- } else {
148
- this.log(chalk`{red Could not create run in project ${this.options.projectName}}`)
149
- this.isDisabled = true
150
- }
151
- })
152
- }
153
-
154
- public async onTestEnd (test: TestCase, testResult: TestResult): Promise<void> {
155
- if (this.isDisabled) {
156
- return
157
- }
158
-
159
- return this.publishCaseResult(test, testResult).then(alwaysUndefined)
160
- }
161
-
162
- public async onEnd (): Promise<void> {
163
- if (this.isDisabled) {
164
- return
165
- }
166
-
167
- let prevCount = this.resultsToBePublished.length
168
- while (this.resultsToBePublished.length > 0) {
169
- // need wait all results to be published
170
- if (prevCount > this.resultsToBePublished.length) {
171
- this.log(
172
- chalk`{gray Waiting for all results to be published. Remaining ${this.resultsToBePublished.length} results}`
173
- )
174
- prevCount--
175
- }
176
- await new Promise((resolve) => setTimeout(resolve, 250))
177
- }
178
-
179
- if (this.publishedResultsCount === 0 && !this.runId) {
180
- this.log('No testcases were matched. Ensure that your tests are declared correctly.')
181
- return
182
- }
183
-
184
- try {
185
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
186
- const runUpdate: TestInterfaces.RunUpdateModel = {
187
- state: 'Completed'
188
- }
189
- const runUpdated = await this.testApi.updateTestRun(runUpdate, this.projectName, this.runId as number)
190
- this.log(chalk`{green Run ${this.runId} - ${runUpdated.state}}`)
191
- } catch (err) {
192
- this.log(`Error on completing run ${err as string}`)
193
- }
194
- }
195
-
196
- private log (message?: any) {
197
- if (this.logging) {
198
- // eslint-disable-next-line no-console
199
- console.log(chalk`{bold {magenta azure:} ${message}}`)
200
- }
201
- }
202
-
203
- private getCaseIds (test: TestCase): string {
204
- const regexp = /\[([\d,]+)\]/
205
- const results = regexp.exec(test.title)
206
- if (results && results.length === 2) {
207
- return results[1]
208
- }
209
- return ''
210
- }
211
-
212
- private logTestItem (test: TestCase, testResult: TestResult) {
213
- const map = {
214
- failed: chalk`{red Test ${test.title} ${testResult.status}}`,
215
- passed: chalk`{green Test ${test.title} ${testResult.status}}`,
216
- skipped: chalk`{blueBright Test ${test.title} ${testResult.status}}`,
217
- pending: chalk`{blueBright Test ${test.title} ${testResult.status}}`,
218
- disabled: chalk`{gray Test ${test.title} ${testResult.status}}`,
219
- timedOut: chalk`{gray Test ${test.title} ${testResult.status}}`
220
- }
221
- if (testResult.status) {
222
- this.log(map[testResult.status])
223
- }
224
- }
225
-
226
- // eslint-disable-next-line no-unused-vars
227
- private async createRun (runName: string, cb: (adTestRun: TestInterfaces.TestRun | undefined) => void): Promise<void> {
228
- try {
229
- const runModel: TestInterfaces.RunCreateModel = {
230
- name: runName,
231
- automated: true,
232
- configurationIds: [1],
233
- plan: { id: `${this.planId}` }
234
- }
235
- const adTestRun = await this.testApi.createTestRun(runModel, this.projectName)
236
- cb(adTestRun)
237
- } catch (e) {
238
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
239
- this.log(`While creating test points ids. Error: ${e}`)
240
- this.isDisabled = true
241
- }
242
- }
243
-
244
- private removePublished (testAlias: string): void {
245
- const resultIndex = this.resultsToBePublished.indexOf(testAlias)
246
- if (resultIndex !== -1) {
247
- this.resultsToBePublished.splice(resultIndex, 1)
248
- }
249
- }
250
-
251
- private async getTestPointIdsByTCIds (planId: number, testcaseIds: number[]): Promise<number[] | void> {
252
- try {
253
- const pointsQuery: TestInterfaces.TestPointsQuery = {
254
- pointsFilter: { testcaseIds }
255
- }
256
- const pointsQueryResult: TestInterfaces.TestPointsQuery = await this.testApi.getPointsByQuery(
257
- pointsQuery,
258
- this.projectName
259
- )
260
- const pointsIds: number[] = []
261
- if (pointsQueryResult.points) {
262
- pointsQueryResult.points.forEach((point: TestPoint) => {
263
- if (point.testPlan && point.testPlan.id && parseInt(point.testPlan.id, 10) === planId) {
264
- pointsIds.push(point.id)
265
- }
266
- })
267
- }
268
- return pointsIds
269
- } catch (e) {
270
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
271
- console.error(`While getting test points ids, by test cases ids. Error: ${e}`)
272
- }
273
- }
274
-
275
- private addReportingOverride = (api: Test.ITestApi): Test.ITestApi => {
276
- api.addTestResultsToTestRun = function (results, projectName, runId) {
277
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
278
- return new Promise(async (resolve, reject) => {
279
- const routeValues = {
280
- project: projectName,
281
- runId
282
- }
283
-
284
- try {
285
- const verData = await this.vsoClient.getVersioningData(
286
- '5.0-preview.5',
287
- 'Test',
288
- '4637d869-3a76-4468-8057-0bb02aa385cf',
289
- routeValues
290
- )
291
-
292
- const url = verData.requestUrl
293
- const options = this.createRequestOptions('application/json', verData.apiVersion)
294
- const res = await this.rest.create(url as string, results, options)
295
- resolve(res as any)
296
- } catch (err) {
297
- reject(err)
298
- }
299
- })
300
- }
301
- return api
302
- };
303
-
304
- private getBase64 (filePath: string): string {
305
- return readFileSync(filePath, { encoding: 'base64' })
306
- }
307
-
308
- private async uploadAttachments (testResult: TestResult, caseId: number): Promise<string[]> {
309
- this.log(chalk`{gray Start upload attachments for test case [${caseId}]}`)
310
- return await Promise.all(
311
- testResult.attachments.map(async (attachment) => {
312
- const attachments: TestInterfaces.TestAttachmentRequestModel = {
313
- attachmentType: 'GeneralAttachment',
314
- fileName: attachment?.name + '.png',
315
- stream: this.getBase64(attachment.path as string)
316
- }
317
-
318
- const response = await this.testApi.createTestResultAttachment(
319
- attachments,
320
- this.projectName,
321
- this.runId!,
322
- caseId
323
- )
324
- return response.url
325
- })
326
- )
327
- }
328
-
329
- private async publishCaseResult (test: TestCase, testResult: TestResult): Promise<void> {
330
- this.logTestItem(test, testResult)
331
- const caseId = this.getCaseIds(test)
332
- if (caseId === '') {
333
- return
334
- }
335
-
336
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
337
- return new Promise(async (resolved, reject) => {
338
- const testAlias = `${caseId} - ${test.title}`
339
- this.resultsToBePublished.push(testAlias)
340
- this.log(chalk`{gray Start publishing: ${test.title}}`)
341
- try {
342
- while (!this.runId) {
343
- // need wait runId variable to be initialised in onBegin() hook
344
- await new Promise((resolve) => setTimeout(resolve, 50))
345
- }
346
-
347
- const pointIds = await this.getTestPointIdsByTCIds(this.planId as number, [parseInt(caseId, 10)])
348
- const results: TestInterfaces.TestCaseResult[] = [
349
- {
350
- testCase: { id: caseId },
351
- testPoint: { id: (pointIds as number[])[0].toString() },
352
- testCaseTitle: test.title,
353
- outcome: Statuses[testResult.status],
354
- state: 'Completed',
355
- durationInMs: testResult.duration,
356
- errorMessage: testResult.error
357
- ? `${test.title}: ${testResult.error?.message?.replace(/\u001b\[.*?m/g, '') as string}`
358
- : undefined,
359
- stackTrace: testResult.error?.stack?.replace(/\u001b\[.*?m/g, '')
360
- }
361
- ]
362
-
363
- const testCaseResult: TestResultsToTestRun = await this.addReportingOverride(this.testApi).addTestResultsToTestRun(results, this.projectName, this.runId) as unknown as TestResultsToTestRun
364
- if (this.options.uploadAttachments && testResult.attachments.length > 0) {
365
- await this.uploadAttachments(testResult, testCaseResult.result.value![0].id)
366
- }
367
-
368
- this.removePublished(testAlias)
369
- this.publishedResultsCount++
370
- this.log(chalk`{gray Result published: ${test.title}}`)
371
- resolved(testCaseResult)
372
- } catch (err) {
373
- this.removePublished(testAlias)
374
- this.log(chalk`{red ${err}}`)
375
- reject(err)
376
- }
377
- }).then(alwaysUndefined)
378
- }
379
- }
380
-
381
- export default PlaywrightReporter