testit-adapter-playwright 5.0.7 → 5.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/result.d.ts +2 -0
- package/dist/reporter.d.ts +11 -0
- package/dist/reporter.js +112 -38
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +11 -13
- package/package.json +2 -2
package/dist/models/result.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface Result {
|
|
|
6
6
|
duration: number;
|
|
7
7
|
error?: TestError;
|
|
8
8
|
errors: Array<TestError>;
|
|
9
|
+
/** Playwright retry attempt index (0 = first run). */
|
|
10
|
+
retry: number;
|
|
9
11
|
/** Full Playwright step tree (fixtures, hooks, test.step); preferred over reporter cache. */
|
|
10
12
|
steps?: TestStep[];
|
|
11
13
|
}
|
package/dist/reporter.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ declare class TmsReporter implements Reporter {
|
|
|
22
22
|
private setupPromise;
|
|
23
23
|
private readonly adapterConfig;
|
|
24
24
|
private bufferedResults;
|
|
25
|
+
/** Autotests already registered in this reporter run (avoid AlreadyExists on retry PUT). */
|
|
26
|
+
private readonly registeredExternalIds;
|
|
25
27
|
constructor(options: ReporterOptions);
|
|
26
28
|
onBegin(config: FullConfig, suite: Suite): void;
|
|
27
29
|
onTestBegin(test: TestCase): void;
|
|
@@ -30,6 +32,11 @@ declare class TmsReporter implements Reporter {
|
|
|
30
32
|
private metadataContext;
|
|
31
33
|
onStepBegin(test: TestCase, _result: TestResult, step: TestStep): void;
|
|
32
34
|
onEnd(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Group buffered attempts by Playwright retry index and POST one testResults batch per stream.
|
|
37
|
+
* Same externalId never appears twice in one stream; retries of different tests share a stream.
|
|
38
|
+
*/
|
|
39
|
+
private flushBufferedByRetryStreams;
|
|
33
40
|
addSkippedResults(): Promise<void>;
|
|
34
41
|
private runLoadTest;
|
|
35
42
|
printsToStdio(): boolean;
|
|
@@ -40,6 +47,10 @@ declare class TmsReporter implements Reporter {
|
|
|
40
47
|
private readAttachmentBuffer;
|
|
41
48
|
/** Each testit.*() call may add a separate tms-metadata.json; merge all of them. */
|
|
42
49
|
private applyMetadataAttachments;
|
|
50
|
+
/**
|
|
51
|
+
* Build AutotestResult for one attempt. Registers autotest in TMS only once per externalId.
|
|
52
|
+
*/
|
|
53
|
+
private prepareTestResult;
|
|
43
54
|
private loadTest;
|
|
44
55
|
}
|
|
45
56
|
export default TmsReporter;
|
package/dist/reporter.js
CHANGED
|
@@ -22,7 +22,6 @@ const converter_1 = require("./converter");
|
|
|
22
22
|
const metadata_store_1 = require("./metadata-store");
|
|
23
23
|
const utils_1 = require("./utils");
|
|
24
24
|
const path_1 = __importDefault(require("path"));
|
|
25
|
-
const testit_js_commons_2 = require("testit-js-commons");
|
|
26
25
|
class TmsReporter {
|
|
27
26
|
constructor(options) {
|
|
28
27
|
this.testCache = new Array();
|
|
@@ -32,12 +31,14 @@ class TmsReporter {
|
|
|
32
31
|
this.loadTestPromises = new Array();
|
|
33
32
|
this.setupPromise = Promise.resolve();
|
|
34
33
|
this.bufferedResults = [];
|
|
34
|
+
/** Autotests already registered in this reporter run (avoid AlreadyExists on retry PUT). */
|
|
35
|
+
this.registeredExternalIds = new Set();
|
|
35
36
|
this.options = { suiteTitle: true, detail: true, ...options };
|
|
36
37
|
const config = new testit_js_commons_1.ConfigComposer().compose(options.tmsOptions);
|
|
37
38
|
this.adapterConfig = config;
|
|
38
39
|
this.strategy = testit_js_commons_1.StrategyFactory.create(config);
|
|
39
40
|
this.additions = new testit_js_commons_1.Additions(config);
|
|
40
|
-
|
|
41
|
+
testit_js_commons_1.logger.debug("[playwright] reporter init", { importRealtime: Boolean(config.importRealtime) });
|
|
41
42
|
}
|
|
42
43
|
onBegin(config, suite) {
|
|
43
44
|
this.config = config;
|
|
@@ -54,10 +55,15 @@ class TmsReporter {
|
|
|
54
55
|
duration: result.duration,
|
|
55
56
|
errors: result.errors,
|
|
56
57
|
error: result.error,
|
|
58
|
+
retry: result.retry,
|
|
57
59
|
steps: result.steps,
|
|
58
60
|
};
|
|
59
61
|
if (this.adapterConfig.importRealtime) {
|
|
60
|
-
|
|
62
|
+
testit_js_commons_1.logger.debug("[playwright] onTestEnd realtime", {
|
|
63
|
+
title: test.title,
|
|
64
|
+
status: result.status,
|
|
65
|
+
retry: result.retry,
|
|
66
|
+
});
|
|
61
67
|
this.loadTestPromises.push(this.runLoadTest(test, currentResult));
|
|
62
68
|
return;
|
|
63
69
|
}
|
|
@@ -100,26 +106,71 @@ class TmsReporter {
|
|
|
100
106
|
async onEnd() {
|
|
101
107
|
try {
|
|
102
108
|
await this.setupPromise.catch((err) => {
|
|
103
|
-
|
|
109
|
+
testit_js_commons_1.logger.error("TMS Playwright setup failed:", err?.body ?? err?.error ?? err);
|
|
104
110
|
});
|
|
105
111
|
if (!this.adapterConfig.importRealtime) {
|
|
106
|
-
|
|
107
|
-
await
|
|
112
|
+
testit_js_commons_1.logger.debug("[playwright] onEnd batch flush", { count: this.bufferedResults.length });
|
|
113
|
+
await this.flushBufferedByRetryStreams();
|
|
108
114
|
}
|
|
109
115
|
else {
|
|
110
|
-
|
|
116
|
+
testit_js_commons_1.logger.debug("[playwright] onEnd await realtime", { pending: this.loadTestPromises.length });
|
|
111
117
|
}
|
|
112
118
|
await Promise.allSettled(this.loadTestPromises);
|
|
113
119
|
await this.addSkippedResults();
|
|
114
120
|
}
|
|
115
121
|
catch (err) {
|
|
116
|
-
|
|
122
|
+
testit_js_commons_1.logger.error("TMS Playwright onEnd failed:", err?.body ?? err?.error ?? err);
|
|
117
123
|
}
|
|
118
124
|
finally {
|
|
119
125
|
await this.strategy.teardown().catch((err) => {
|
|
120
|
-
|
|
126
|
+
testit_js_commons_1.logger.error("TMS Playwright teardown failed:", err?.body ?? err?.error ?? err);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Group buffered attempts by Playwright retry index and POST one testResults batch per stream.
|
|
132
|
+
* Same externalId never appears twice in one stream; retries of different tests share a stream.
|
|
133
|
+
*/
|
|
134
|
+
async flushBufferedByRetryStreams() {
|
|
135
|
+
await this.setupPromise.catch(() => undefined);
|
|
136
|
+
const byRetry = new Map();
|
|
137
|
+
for (const item of this.bufferedResults) {
|
|
138
|
+
const retry = item.result.retry ?? 0;
|
|
139
|
+
const group = byRetry.get(retry) ?? [];
|
|
140
|
+
group.push(item);
|
|
141
|
+
byRetry.set(retry, group);
|
|
142
|
+
}
|
|
143
|
+
const retries = [...byRetry.keys()].sort((a, b) => a - b);
|
|
144
|
+
const testsToRelease = new Map();
|
|
145
|
+
for (const retry of retries) {
|
|
146
|
+
const group = byRetry.get(retry) ?? [];
|
|
147
|
+
const autotestResults = [];
|
|
148
|
+
for (const { test, result } of group) {
|
|
149
|
+
try {
|
|
150
|
+
const prepared = await this.prepareTestResult(test, result);
|
|
151
|
+
if (prepared) {
|
|
152
|
+
autotestResults.push(prepared);
|
|
153
|
+
}
|
|
154
|
+
testsToRelease.set(test.id, test);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
testit_js_commons_1.logger.log("Error preparing test result. \n", test.title, err?.body ?? err?.error ?? err);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (autotestResults.length === 0) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
testit_js_commons_1.logger.debug("[playwright] flush retry stream", {
|
|
164
|
+
retry,
|
|
165
|
+
count: autotestResults.length,
|
|
166
|
+
});
|
|
167
|
+
await this.strategy.loadTestRun(autotestResults).catch((err) => {
|
|
168
|
+
testit_js_commons_1.logger.log("Error loadTestRun for retry stream. \n", retry, err?.body ?? err?.error ?? err);
|
|
121
169
|
});
|
|
122
170
|
}
|
|
171
|
+
for (const test of testsToRelease.values()) {
|
|
172
|
+
(0, metadata_store_1.releaseTestMetadata)(this.metadataContext(test));
|
|
173
|
+
}
|
|
123
174
|
}
|
|
124
175
|
async addSkippedResults() {
|
|
125
176
|
const unprocessedCases = this.suite
|
|
@@ -130,16 +181,17 @@ class TmsReporter {
|
|
|
130
181
|
attachments: [],
|
|
131
182
|
duration: 0,
|
|
132
183
|
errors: [],
|
|
184
|
+
retry: 0,
|
|
133
185
|
steps: [],
|
|
134
186
|
}).catch((err) => {
|
|
135
|
-
|
|
187
|
+
testit_js_commons_1.logger.error("TMS Playwright loadTest (skipped) failed:", testCase?.title, err?.body ?? err?.error ?? err);
|
|
136
188
|
})));
|
|
137
189
|
}
|
|
138
190
|
runLoadTest(test, result) {
|
|
139
191
|
return this.setupPromise
|
|
140
192
|
.then(() => this.loadTest(test, result))
|
|
141
193
|
.catch((err) => {
|
|
142
|
-
|
|
194
|
+
testit_js_commons_1.logger.log("Error processing test result. \n", err?.body ?? err?.error ?? err);
|
|
143
195
|
});
|
|
144
196
|
}
|
|
145
197
|
printsToStdio() {
|
|
@@ -185,7 +237,7 @@ class TmsReporter {
|
|
|
185
237
|
autotestData.addAttachments?.push(...ids);
|
|
186
238
|
}
|
|
187
239
|
catch (err) {
|
|
188
|
-
|
|
240
|
+
testit_js_commons_1.logger.log("Error uploading file attachment. \n", err?.body ?? err?.error ?? err);
|
|
189
241
|
}
|
|
190
242
|
}
|
|
191
243
|
continue;
|
|
@@ -194,14 +246,15 @@ class TmsReporter {
|
|
|
194
246
|
const step = this.attachmentStepsCache.find((step) => step.title === attachment.name);
|
|
195
247
|
try {
|
|
196
248
|
const ids = await this.additions.addAttachments(attachment.body, attachment.name.replace(utils_1.stepAttachRegexp, ""));
|
|
197
|
-
|
|
198
|
-
|
|
249
|
+
const parentStep = (0, utils_1.resolveAttachmentParentStep)(step);
|
|
250
|
+
if (parentStep) {
|
|
251
|
+
this.attachmentsMap.set(ids[0], parentStep);
|
|
199
252
|
continue;
|
|
200
253
|
}
|
|
201
254
|
autotestData.addAttachments?.push(...ids);
|
|
202
255
|
}
|
|
203
256
|
catch (err) {
|
|
204
|
-
|
|
257
|
+
testit_js_commons_1.logger.log("Error uploading text attachment. \n", err?.body ?? err?.error ?? err);
|
|
205
258
|
}
|
|
206
259
|
}
|
|
207
260
|
}
|
|
@@ -209,7 +262,7 @@ class TmsReporter {
|
|
|
209
262
|
const stored = (0, metadata_store_1.resolveTestMetadata)(this.metadataContext(test));
|
|
210
263
|
if (stored) {
|
|
211
264
|
(0, metadata_store_1.applyMetadataTo)(autotestData, stored);
|
|
212
|
-
|
|
265
|
+
testit_js_commons_1.logger.debug("[playwright] metadata from store", {
|
|
213
266
|
title: test.title,
|
|
214
267
|
namespace: autotestData.namespace,
|
|
215
268
|
classname: autotestData.classname,
|
|
@@ -254,31 +307,52 @@ class TmsReporter {
|
|
|
254
307
|
}
|
|
255
308
|
(0, metadata_store_1.applyMetadataTo)(autotestData, merged);
|
|
256
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Build AutotestResult for one attempt. Registers autotest in TMS only once per externalId.
|
|
312
|
+
*/
|
|
313
|
+
async prepareTestResult(test, result) {
|
|
314
|
+
testit_js_commons_1.logger.debug("[playwright] prepareTestResult", {
|
|
315
|
+
title: test.title,
|
|
316
|
+
status: result.status,
|
|
317
|
+
retry: result.retry,
|
|
318
|
+
});
|
|
319
|
+
const autotestData = await this.getAutotestData(test, result);
|
|
320
|
+
const dictionaries = this.getDictionariesByTest(test);
|
|
321
|
+
const pathNamespace = dictionaries.slice(0, -1).join(path_1.default.sep);
|
|
322
|
+
const pathClassname = dictionaries[dictionaries.length - 1];
|
|
323
|
+
// Prefer testit.namespace / testit.classname from metadata; file path only when missing.
|
|
324
|
+
if (pathNamespace.length > 0 && autotestData.namespace == null) {
|
|
325
|
+
autotestData.namespace = pathNamespace;
|
|
326
|
+
}
|
|
327
|
+
if (pathClassname?.length && autotestData.classname == null) {
|
|
328
|
+
autotestData.classname = pathClassname;
|
|
329
|
+
}
|
|
330
|
+
const externalId = autotestData.externalId;
|
|
331
|
+
const autotest = converter_1.Converter.convertTestCaseToAutotestPost(autotestData);
|
|
332
|
+
const rawSteps = result.steps?.length
|
|
333
|
+
? result.steps
|
|
334
|
+
: [...this.stepsMap.keys()].filter((step) => this.stepsMap.get(step) === test);
|
|
335
|
+
const stepResults = converter_1.Converter.convertTestStepsToSteps(rawSteps, this.attachmentsMap);
|
|
336
|
+
autotest.steps = converter_1.Converter.convertTestStepsToShortSteps(rawSteps);
|
|
337
|
+
if (!this.registeredExternalIds.has(externalId)) {
|
|
338
|
+
await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus));
|
|
339
|
+
this.registeredExternalIds.add(externalId);
|
|
340
|
+
}
|
|
341
|
+
const autotestResult = converter_1.Converter.convertAutotestPostToAutotestResult(autotestData, test, result);
|
|
342
|
+
autotestResult.stepResults = stepResults;
|
|
343
|
+
return autotestResult;
|
|
344
|
+
}
|
|
257
345
|
async loadTest(test, result) {
|
|
258
|
-
|
|
346
|
+
testit_js_commons_1.logger.debug("[playwright] loadTest", {
|
|
347
|
+
title: test.title,
|
|
348
|
+
status: result.status,
|
|
349
|
+
retry: result.retry,
|
|
350
|
+
});
|
|
259
351
|
try {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const pathClassname = dictionaries[dictionaries.length - 1];
|
|
264
|
-
// Prefer testit.namespace / testit.classname from metadata; file path only when missing.
|
|
265
|
-
if (pathNamespace.length > 0 && autotestData.namespace == null) {
|
|
266
|
-
autotestData.namespace = pathNamespace;
|
|
267
|
-
}
|
|
268
|
-
if (pathClassname?.length && autotestData.classname == null) {
|
|
269
|
-
autotestData.classname = pathClassname;
|
|
352
|
+
const autotestResult = await this.prepareTestResult(test, result);
|
|
353
|
+
if (autotestResult) {
|
|
354
|
+
await this.strategy.loadTestRun([autotestResult]);
|
|
270
355
|
}
|
|
271
|
-
const autotest = converter_1.Converter.convertTestCaseToAutotestPost(autotestData);
|
|
272
|
-
const rawSteps = result.steps?.length
|
|
273
|
-
? result.steps
|
|
274
|
-
: [...this.stepsMap.keys()].filter((step) => this.stepsMap.get(step) === test);
|
|
275
|
-
const stepResults = converter_1.Converter.convertTestStepsToSteps(rawSteps, this.attachmentsMap);
|
|
276
|
-
result.status = (0, utils_1.getTestStatus)(test);
|
|
277
|
-
autotest.steps = converter_1.Converter.convertTestStepsToShortSteps(rawSteps);
|
|
278
|
-
await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus));
|
|
279
|
-
const autotestResult = converter_1.Converter.convertAutotestPostToAutotestResult(autotestData, test, result);
|
|
280
|
-
autotestResult.stepResults = stepResults;
|
|
281
|
-
await this.strategy.loadTestRun([autotestResult]);
|
|
282
356
|
}
|
|
283
357
|
finally {
|
|
284
358
|
(0, metadata_store_1.releaseTestMetadata)(this.metadataContext(test));
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TestError, TestStep } from "@playwright/test/reporter";
|
|
2
2
|
import { Step } from "testit-js-commons";
|
|
3
3
|
import { ResultAttachment } from "./models/result";
|
|
4
4
|
export type StatusDetails = {
|
|
@@ -7,8 +7,8 @@ export type StatusDetails = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function getStatusDetails(error: TestError): StatusDetails;
|
|
9
9
|
export declare function isAllStepsWithPassedOutcome(steps: Step[]): boolean;
|
|
10
|
-
export declare function getTestStatus(test: TestCase): TestStatus;
|
|
11
10
|
export declare function isStep(step: TestStep): boolean;
|
|
11
|
+
export declare function resolveAttachmentParentStep(step: TestStep | undefined): TestStep | undefined;
|
|
12
12
|
export declare function stripAscii(str: string): string;
|
|
13
13
|
export declare const stepAttachRegexp: RegExp;
|
|
14
14
|
export declare function processAttachmentExtensions(attachment: ResultAttachment): ResultAttachment;
|
package/dist/utils.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.stepAttachRegexp = void 0;
|
|
4
4
|
exports.getStatusDetails = getStatusDetails;
|
|
5
5
|
exports.isAllStepsWithPassedOutcome = isAllStepsWithPassedOutcome;
|
|
6
|
-
exports.getTestStatus = getTestStatus;
|
|
7
6
|
exports.isStep = isStep;
|
|
7
|
+
exports.resolveAttachmentParentStep = resolveAttachmentParentStep;
|
|
8
8
|
exports.stripAscii = stripAscii;
|
|
9
9
|
exports.processAttachmentExtensions = processAttachmentExtensions;
|
|
10
10
|
exports.processAttachmentNameExtensions = processAttachmentNameExtensions;
|
|
@@ -25,21 +25,19 @@ function getStatusDetails(error) {
|
|
|
25
25
|
function isAllStepsWithPassedOutcome(steps) {
|
|
26
26
|
return !steps.find((step) => step.info !== undefined);
|
|
27
27
|
}
|
|
28
|
-
const statusMap = {
|
|
29
|
-
["expected"]: "passed",
|
|
30
|
-
["unexpected"]: "failed",
|
|
31
|
-
["flaky"]: "failed",
|
|
32
|
-
["skipped"]: "skipped",
|
|
33
|
-
};
|
|
34
|
-
function getTestStatus(test) {
|
|
35
|
-
if (!test.ok()) {
|
|
36
|
-
return "failed";
|
|
37
|
-
}
|
|
38
|
-
return statusMap[test.outcome()];
|
|
39
|
-
}
|
|
40
28
|
function isStep(step) {
|
|
41
29
|
return step.category === "test.step" && !step.title.match(exports.stepAttachRegexp);
|
|
42
30
|
}
|
|
31
|
+
function resolveAttachmentParentStep(step) {
|
|
32
|
+
let current = step?.parent;
|
|
33
|
+
while (current) {
|
|
34
|
+
if (isStep(current)) {
|
|
35
|
+
return current;
|
|
36
|
+
}
|
|
37
|
+
current = current.parent;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
43
41
|
function stripAscii(str) {
|
|
44
42
|
return str.replace(asciiRegex, "");
|
|
45
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testit-adapter-playwright",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.8",
|
|
4
4
|
"description": "Playwright adapter for Test IT",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"prettier": "^3.0.1"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"testit-js-commons": "5.0.
|
|
43
|
+
"testit-js-commons": "5.0.8"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|