@alex_neo/playwright-azure-reporter 1.0.3 → 1.0.4

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.
@@ -0,0 +1,45 @@
1
+ import { Reporter, TestCase, TestResult } from '@playwright/test/reporter';
2
+ import { WebApi } from 'azure-devops-node-api';
3
+ interface AzureOptions {
4
+ token: string;
5
+ planId: number;
6
+ orgUrl: string;
7
+ connection: WebApi;
8
+ projectName: string;
9
+ runId?: string;
10
+ logging?: boolean;
11
+ isDisabled?: boolean;
12
+ environment?: string | undefined;
13
+ testRunTitle: string;
14
+ uploadAttachments?: boolean;
15
+ }
16
+ declare class PlaywrightReporter implements Reporter {
17
+ private testApi;
18
+ private options;
19
+ private planId;
20
+ private runId?;
21
+ private isDisabled;
22
+ private publishedResultsCount;
23
+ private resultsToBePublished;
24
+ private orgUrl;
25
+ private connection;
26
+ private projectName;
27
+ private environment;
28
+ private logging;
29
+ private testRunTitle;
30
+ constructor(_options: AzureOptions);
31
+ onBegin(): Promise<void>;
32
+ onTestEnd(test: TestCase, testResult: TestResult): Promise<void>;
33
+ onEnd(): Promise<void>;
34
+ private log;
35
+ private getCaseIds;
36
+ private logTestItem;
37
+ private createRun;
38
+ private removePublished;
39
+ private getTestPointIdsByTCIds;
40
+ private addReportingOverride;
41
+ private getBase64;
42
+ private uploadAttachments;
43
+ private publishCaseResult;
44
+ }
45
+ export default PlaywrightReporter;
@@ -0,0 +1,445 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
29
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
30
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
+ return new (P || (P = Promise))(function (resolve, reject) {
32
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ var __generator = (this && this.__generator) || function (thisArg, body) {
39
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
40
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
41
+ function verb(n) { return function (v) { return step([n, v]); }; }
42
+ function step(op) {
43
+ if (f) throw new TypeError("Generator is already executing.");
44
+ while (_) try {
45
+ 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;
46
+ if (y = 0, t) op = [op[0] & 2, t.value];
47
+ switch (op[0]) {
48
+ case 0: case 1: t = op; break;
49
+ case 4: _.label++; return { value: op[1], done: false };
50
+ case 5: _.label++; y = op[1]; op = [0]; continue;
51
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
52
+ default:
53
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
54
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
55
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
56
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
57
+ if (t[2]) _.ops.pop();
58
+ _.trys.pop(); continue;
59
+ }
60
+ op = body.call(thisArg, _);
61
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
62
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
63
+ }
64
+ };
65
+ var __importDefault = (this && this.__importDefault) || function (mod) {
66
+ return (mod && mod.__esModule) ? mod : { "default": mod };
67
+ };
68
+ Object.defineProperty(exports, "__esModule", { value: true });
69
+ var azdev = __importStar(require("azure-devops-node-api"));
70
+ var chalk_1 = __importDefault(require("chalk"));
71
+ var fs_1 = require("fs");
72
+ var Statuses = {
73
+ passed: 'Passed',
74
+ failed: 'Failed',
75
+ skipped: 'Paused',
76
+ timedOut: 'Failed'
77
+ };
78
+ var alwaysUndefined = function () { return undefined; };
79
+ var PlaywrightReporter = /** @class */ (function () {
80
+ function PlaywrightReporter(_options) {
81
+ this.isDisabled = false;
82
+ this.publishedResultsCount = 0;
83
+ this.resultsToBePublished = [];
84
+ this.logging = true;
85
+ this.addReportingOverride = function (api) {
86
+ api.addTestResultsToTestRun = function (results, projectName, runId) {
87
+ var _this = this;
88
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
89
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
90
+ var routeValues, verData, url, options, res, err_1;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ routeValues = {
95
+ project: projectName,
96
+ runId: runId
97
+ };
98
+ _a.label = 1;
99
+ case 1:
100
+ _a.trys.push([1, 4, , 5]);
101
+ return [4 /*yield*/, this.vsoClient.getVersioningData('5.0-preview.5', 'Test', '4637d869-3a76-4468-8057-0bb02aa385cf', routeValues)];
102
+ case 2:
103
+ verData = _a.sent();
104
+ url = verData.requestUrl;
105
+ options = this.createRequestOptions('application/json', verData.apiVersion);
106
+ return [4 /*yield*/, this.rest.create(url, results, options)];
107
+ case 3:
108
+ res = _a.sent();
109
+ resolve(res);
110
+ return [3 /*break*/, 5];
111
+ case 4:
112
+ err_1 = _a.sent();
113
+ reject(err_1);
114
+ return [3 /*break*/, 5];
115
+ case 5: return [2 /*return*/];
116
+ }
117
+ });
118
+ }); });
119
+ };
120
+ return api;
121
+ };
122
+ this.options = _options;
123
+ this.orgUrl = _options.orgUrl;
124
+ this.projectName = _options.projectName;
125
+ this.environment = _options.environment || undefined;
126
+ this.planId = _options.planId;
127
+ this.logging = _options.logging || true;
128
+ this.isDisabled = _options.isDisabled || false;
129
+ this.testRunTitle = "".concat(this.environment ? "[".concat(this.environment, "]:") : '', " ").concat(_options.testRunTitle || 'Playwright Test Run') ||
130
+ "".concat(this.environment ? "[".concat(this.environment, "]:") : '', "Test plan ").concat(this.planId);
131
+ this.connection = new azdev.WebApi(this.orgUrl, azdev.getPersonalAccessTokenHandler(this.options.token));
132
+ this.options.uploadAttachments = _options.uploadAttachments || false;
133
+ if (!this.orgUrl) {
134
+ this.log((0, chalk_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{yellow 'orgUrl' is not set. Reporting is disabled.}"], ["{yellow 'orgUrl' is not set. Reporting is disabled.}"]))));
135
+ this.isDisabled = true;
136
+ return;
137
+ }
138
+ if (!this.projectName || !this.planId) {
139
+ this.log((0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{yellow 'projectName' is not set. Reporting is disabled.}"], ["{yellow 'projectName' is not set. Reporting is disabled.}"]))));
140
+ this.isDisabled = true;
141
+ return;
142
+ }
143
+ if (!this.planId) {
144
+ this.log((0, chalk_1.default)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["{yellow 'planId' is not set. Reporting is disabled.}"], ["{yellow 'planId' is not set. Reporting is disabled.}"]))));
145
+ this.isDisabled = true;
146
+ return;
147
+ }
148
+ if (!this.options.token) {
149
+ this.log((0, chalk_1.default)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["{yellow 'token' is not set. Reporting is disabled.}"], ["{yellow 'token' is not set. Reporting is disabled.}"]))));
150
+ this.isDisabled = true;
151
+ }
152
+ }
153
+ PlaywrightReporter.prototype.onBegin = function () {
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var _a;
156
+ var _this = this;
157
+ return __generator(this, function (_b) {
158
+ switch (_b.label) {
159
+ case 0:
160
+ if (this.isDisabled) {
161
+ return [2 /*return*/];
162
+ }
163
+ _a = this;
164
+ return [4 /*yield*/, this.connection.getTestApi()];
165
+ case 1:
166
+ _a.testApi = _b.sent();
167
+ return [2 /*return*/, this.createRun(this.testRunTitle, function (created) {
168
+ if (created) {
169
+ _this.runId = created.id;
170
+ _this.log((0, chalk_1.default)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), _this.runId));
171
+ }
172
+ else {
173
+ _this.log((0, chalk_1.default)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["{red Could not create run in project ", "}"], ["{red Could not create run in project ", "}"])), _this.options.projectName));
174
+ _this.isDisabled = true;
175
+ }
176
+ })];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ PlaywrightReporter.prototype.onTestEnd = function (test, testResult) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ return __generator(this, function (_a) {
184
+ if (this.isDisabled) {
185
+ return [2 /*return*/];
186
+ }
187
+ return [2 /*return*/, this.publishCaseResult(test, testResult).then(alwaysUndefined)];
188
+ });
189
+ });
190
+ };
191
+ PlaywrightReporter.prototype.onEnd = function () {
192
+ return __awaiter(this, void 0, void 0, function () {
193
+ var prevCount, runUpdate, runUpdated, err_2;
194
+ return __generator(this, function (_a) {
195
+ switch (_a.label) {
196
+ case 0:
197
+ if (this.isDisabled) {
198
+ return [2 /*return*/];
199
+ }
200
+ prevCount = this.resultsToBePublished.length;
201
+ _a.label = 1;
202
+ case 1:
203
+ if (!(this.resultsToBePublished.length > 0)) return [3 /*break*/, 3];
204
+ // need wait all results to be published
205
+ if (prevCount > this.resultsToBePublished.length) {
206
+ this.log((0, chalk_1.default)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["{gray Waiting for all results to be published. Remaining ", " results}"], ["{gray Waiting for all results to be published. Remaining ", " results}"])), this.resultsToBePublished.length));
207
+ prevCount--;
208
+ }
209
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 250); })];
210
+ case 2:
211
+ _a.sent();
212
+ return [3 /*break*/, 1];
213
+ case 3:
214
+ if (this.publishedResultsCount === 0 && !this.runId) {
215
+ this.log('No testcases were matched. Ensure that your tests are declared correctly.');
216
+ return [2 /*return*/];
217
+ }
218
+ _a.label = 4;
219
+ case 4:
220
+ _a.trys.push([4, 6, , 7]);
221
+ runUpdate = {
222
+ state: 'Completed'
223
+ };
224
+ return [4 /*yield*/, this.testApi.updateTestRun(runUpdate, this.projectName, this.runId)];
225
+ case 5:
226
+ runUpdated = _a.sent();
227
+ this.log((0, chalk_1.default)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["{green Run ", " - ", "}"], ["{green Run ", " - ", "}"])), this.runId, runUpdated.state));
228
+ return [3 /*break*/, 7];
229
+ case 6:
230
+ err_2 = _a.sent();
231
+ this.log("Error on completing run ".concat(err_2));
232
+ return [3 /*break*/, 7];
233
+ case 7: return [2 /*return*/];
234
+ }
235
+ });
236
+ });
237
+ };
238
+ PlaywrightReporter.prototype.log = function (message) {
239
+ if (this.logging) {
240
+ // eslint-disable-next-line no-console
241
+ console.log((0, chalk_1.default)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["{bold {magenta azure:} ", "}"], ["{bold {magenta azure:} ", "}"])), message));
242
+ }
243
+ };
244
+ PlaywrightReporter.prototype.getCaseIds = function (test) {
245
+ var regexp = /\[([\d,]+)\]/;
246
+ var results = regexp.exec(test.title);
247
+ if (results && results.length === 2) {
248
+ return results[1];
249
+ }
250
+ return '';
251
+ };
252
+ PlaywrightReporter.prototype.logTestItem = function (test, testResult) {
253
+ var map = {
254
+ failed: (0, chalk_1.default)(templateObject_10 || (templateObject_10 = __makeTemplateObject(["{red Test ", " ", "}"], ["{red Test ", " ", "}"])), test.title, testResult.status),
255
+ passed: (0, chalk_1.default)(templateObject_11 || (templateObject_11 = __makeTemplateObject(["{green Test ", " ", "}"], ["{green Test ", " ", "}"])), test.title, testResult.status),
256
+ skipped: (0, chalk_1.default)(templateObject_12 || (templateObject_12 = __makeTemplateObject(["{blueBright Test ", " ", "}"], ["{blueBright Test ", " ", "}"])), test.title, testResult.status),
257
+ pending: (0, chalk_1.default)(templateObject_13 || (templateObject_13 = __makeTemplateObject(["{blueBright Test ", " ", "}"], ["{blueBright Test ", " ", "}"])), test.title, testResult.status),
258
+ disabled: (0, chalk_1.default)(templateObject_14 || (templateObject_14 = __makeTemplateObject(["{gray Test ", " ", "}"], ["{gray Test ", " ", "}"])), test.title, testResult.status),
259
+ timedOut: (0, chalk_1.default)(templateObject_15 || (templateObject_15 = __makeTemplateObject(["{gray Test ", " ", "}"], ["{gray Test ", " ", "}"])), test.title, testResult.status)
260
+ };
261
+ if (testResult.status) {
262
+ this.log(map[testResult.status]);
263
+ }
264
+ };
265
+ // eslint-disable-next-line no-unused-vars
266
+ PlaywrightReporter.prototype.createRun = function (runName, cb) {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var runModel, adTestRun, e_1;
269
+ return __generator(this, function (_a) {
270
+ switch (_a.label) {
271
+ case 0:
272
+ _a.trys.push([0, 2, , 3]);
273
+ runModel = {
274
+ name: runName,
275
+ automated: true,
276
+ configurationIds: [1],
277
+ plan: { id: "".concat(this.planId) }
278
+ };
279
+ return [4 /*yield*/, this.testApi.createTestRun(runModel, this.projectName)];
280
+ case 1:
281
+ adTestRun = _a.sent();
282
+ cb(adTestRun);
283
+ return [3 /*break*/, 3];
284
+ case 2:
285
+ e_1 = _a.sent();
286
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
287
+ this.log("While creating test points ids. Error: ".concat(e_1));
288
+ this.isDisabled = true;
289
+ return [3 /*break*/, 3];
290
+ case 3: return [2 /*return*/];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ PlaywrightReporter.prototype.removePublished = function (testAlias) {
296
+ var resultIndex = this.resultsToBePublished.indexOf(testAlias);
297
+ if (resultIndex !== -1) {
298
+ this.resultsToBePublished.splice(resultIndex, 1);
299
+ }
300
+ };
301
+ PlaywrightReporter.prototype.getTestPointIdsByTCIds = function (planId, testcaseIds) {
302
+ return __awaiter(this, void 0, void 0, function () {
303
+ var pointsQuery, pointsQueryResult, pointsIds_1, e_2;
304
+ return __generator(this, function (_a) {
305
+ switch (_a.label) {
306
+ case 0:
307
+ _a.trys.push([0, 2, , 3]);
308
+ pointsQuery = {
309
+ pointsFilter: { testcaseIds: testcaseIds }
310
+ };
311
+ return [4 /*yield*/, this.testApi.getPointsByQuery(pointsQuery, this.projectName)];
312
+ case 1:
313
+ pointsQueryResult = _a.sent();
314
+ pointsIds_1 = [];
315
+ if (pointsQueryResult.points) {
316
+ pointsQueryResult.points.forEach(function (point) {
317
+ if (point.testPlan && point.testPlan.id && parseInt(point.testPlan.id, 10) === planId) {
318
+ pointsIds_1.push(point.id);
319
+ }
320
+ });
321
+ }
322
+ return [2 /*return*/, pointsIds_1];
323
+ case 2:
324
+ e_2 = _a.sent();
325
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
326
+ console.error("While getting test points ids, by test cases ids. Error: ".concat(e_2));
327
+ return [3 /*break*/, 3];
328
+ case 3: return [2 /*return*/];
329
+ }
330
+ });
331
+ });
332
+ };
333
+ PlaywrightReporter.prototype.getBase64 = function (filePath) {
334
+ return (0, fs_1.readFileSync)(filePath, { encoding: 'base64' });
335
+ };
336
+ PlaywrightReporter.prototype.uploadAttachments = function (testResult, caseId) {
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ var _this = this;
339
+ return __generator(this, function (_a) {
340
+ switch (_a.label) {
341
+ case 0:
342
+ this.log((0, chalk_1.default)(templateObject_16 || (templateObject_16 = __makeTemplateObject(["{gray Start upload attachments for test case [", "]}"], ["{gray Start upload attachments for test case [", "]}"])), caseId));
343
+ return [4 /*yield*/, Promise.all(testResult.attachments.map(function (attachment) { return __awaiter(_this, void 0, void 0, function () {
344
+ var attachments, response;
345
+ return __generator(this, function (_a) {
346
+ switch (_a.label) {
347
+ case 0:
348
+ attachments = {
349
+ attachmentType: 'GeneralAttachment',
350
+ fileName: (attachment === null || attachment === void 0 ? void 0 : attachment.name) + '.png',
351
+ stream: this.getBase64(attachment.path)
352
+ };
353
+ return [4 /*yield*/, this.testApi.createTestResultAttachment(attachments, this.projectName, this.runId, caseId)];
354
+ case 1:
355
+ response = _a.sent();
356
+ return [2 /*return*/, response.url];
357
+ }
358
+ });
359
+ }); }))];
360
+ case 1: return [2 /*return*/, _a.sent()];
361
+ }
362
+ });
363
+ });
364
+ };
365
+ PlaywrightReporter.prototype.publishCaseResult = function (test, testResult) {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ var caseId;
368
+ var _this = this;
369
+ return __generator(this, function (_a) {
370
+ this.logTestItem(test, testResult);
371
+ caseId = this.getCaseIds(test);
372
+ if (caseId === '') {
373
+ return [2 /*return*/];
374
+ }
375
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
376
+ return [2 /*return*/, new Promise(function (resolved, reject) { return __awaiter(_this, void 0, void 0, function () {
377
+ var testAlias, pointIds, results, testCaseResult, err_3;
378
+ var _a, _b, _c, _d;
379
+ return __generator(this, function (_e) {
380
+ switch (_e.label) {
381
+ case 0:
382
+ testAlias = "".concat(caseId, " - ").concat(test.title);
383
+ this.resultsToBePublished.push(testAlias);
384
+ this.log((0, chalk_1.default)(templateObject_17 || (templateObject_17 = __makeTemplateObject(["{gray Start publishing: ", "}"], ["{gray Start publishing: ", "}"])), test.title));
385
+ _e.label = 1;
386
+ case 1:
387
+ _e.trys.push([1, 9, , 10]);
388
+ _e.label = 2;
389
+ case 2:
390
+ if (!!this.runId) return [3 /*break*/, 4];
391
+ // need wait runId variable to be initialised in onBegin() hook
392
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 50); })];
393
+ case 3:
394
+ // need wait runId variable to be initialised in onBegin() hook
395
+ _e.sent();
396
+ return [3 /*break*/, 2];
397
+ case 4: return [4 /*yield*/, this.getTestPointIdsByTCIds(this.planId, [parseInt(caseId, 10)])];
398
+ case 5:
399
+ pointIds = _e.sent();
400
+ results = [
401
+ {
402
+ testCase: { id: caseId },
403
+ testPoint: { id: pointIds[0].toString() },
404
+ testCaseTitle: test.title,
405
+ outcome: Statuses[testResult.status],
406
+ state: 'Completed',
407
+ durationInMs: testResult.duration,
408
+ errorMessage: testResult.error
409
+ ? "".concat(test.title, ": ").concat((_b = (_a = testResult.error) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.replace(/\u001b\[.*?m/g, ''))
410
+ : undefined,
411
+ stackTrace: (_d = (_c = testResult.error) === null || _c === void 0 ? void 0 : _c.stack) === null || _d === void 0 ? void 0 : _d.replace(/\u001b\[.*?m/g, '')
412
+ }
413
+ ];
414
+ return [4 /*yield*/, this.addReportingOverride(this.testApi).addTestResultsToTestRun(results, this.projectName, this.runId)];
415
+ case 6:
416
+ testCaseResult = _e.sent();
417
+ if (!(this.options.uploadAttachments && testResult.attachments.length > 0)) return [3 /*break*/, 8];
418
+ return [4 /*yield*/, this.uploadAttachments(testResult, testCaseResult.result.value[0].id)];
419
+ case 7:
420
+ _e.sent();
421
+ _e.label = 8;
422
+ case 8:
423
+ this.removePublished(testAlias);
424
+ this.publishedResultsCount++;
425
+ this.log((0, chalk_1.default)(templateObject_18 || (templateObject_18 = __makeTemplateObject(["{gray Result published: ", "}"], ["{gray Result published: ", "}"])), test.title));
426
+ resolved(testCaseResult);
427
+ return [3 /*break*/, 10];
428
+ case 9:
429
+ err_3 = _e.sent();
430
+ this.removePublished(testAlias);
431
+ this.log((0, chalk_1.default)(templateObject_19 || (templateObject_19 = __makeTemplateObject(["{red ", "}"], ["{red ", "}"])), err_3));
432
+ reject(err_3);
433
+ return [3 /*break*/, 10];
434
+ case 10: return [2 /*return*/];
435
+ }
436
+ });
437
+ }); }).then(alwaysUndefined)];
438
+ });
439
+ });
440
+ };
441
+ return PlaywrightReporter;
442
+ }());
443
+ exports.default = PlaywrightReporter;
444
+ 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, templateObject_17, templateObject_18, templateObject_19;
445
+ //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,2DAA8C;AAM9C,gDAAyB;AACzB,yBAAiC;AAEjC,IAAM,QAAQ,GAAG;IACf,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;CACnB,CAAA;AAoED,IAAM,eAAe,GAAG,cAAM,OAAA,SAAS,EAAT,CAAS,CAAA;AAEvC;IAeE,4BAAoB,QAAsB;QAVlC,eAAU,GAAG,KAAK,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 @@
1
1
  {
2
2
  "name": "@alex_neo/playwright-azure-reporter",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Playwright Azure Reporter",
5
5
  "main": "./dist/playwright-azure-reporter.js",
6
6
  "types": "./dist/playwright-azure-reporter.d.js",
@@ -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