testit-adapter-playwright 5.0.6 → 5.0.8-TMS-5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -143,7 +143,6 @@ Description of metadata methods:
143
143
  - `testit.title` - title in the autotest card
144
144
  - `testit.description` - description in the autotest card
145
145
  - `testit.labels` - labels in the autotest card
146
- - `testit.layer` - test pyramid layer in the autotest card (source **Run**). Use `TestLayers` from `testit-js-commons` for recommended values (`E2E`, `UI`, `API`, `Contract`, `Integration`, `Component`, `Unit`), or any custom string
147
146
  - `testit.tags` - tags in the autotest card
148
147
  - `testit.links` - links in the autotest card
149
148
  - `testit.namespace` - directory in the TMS system (default - directory's name of test)
@@ -161,7 +160,6 @@ Description of methods:
161
160
  ```js
162
161
  import { test } from "@playwright/test";
163
162
  import { testit } from "testit-adapter-playwright";
164
- import { TestLayers } from "testit-js-commons";
165
163
 
166
164
  test('All annotations', async () => {
167
165
  testit.externalId('all_annotations');
@@ -169,7 +167,6 @@ test('All annotations', async () => {
169
167
  testit.title('All annotations title');
170
168
  testit.description('Test with all annotations');
171
169
  testit.labels(['label1', 'label2']);
172
- await testit.layer(TestLayers.API);
173
170
 
174
171
  testit.addMessage('This is a message');
175
172
  testit.addLinks([
package/dist/converter.js CHANGED
@@ -16,7 +16,6 @@ class Converter {
16
16
  title: autotestData.title,
17
17
  description: autotestData.description,
18
18
  labels: autotestData.labels,
19
- layer: autotestData.layer,
20
19
  tags: autotestData.tags,
21
20
  links: autotestData.links,
22
21
  namespace: autotestData.namespace,
package/dist/labels.d.ts CHANGED
@@ -6,7 +6,6 @@ export interface MetadataMessage {
6
6
  title?: string;
7
7
  description?: string;
8
8
  labels?: Label[];
9
- layer?: string;
10
9
  tags?: string[];
11
10
  links?: Link[];
12
11
  namespace?: string;
@@ -59,7 +58,6 @@ export declare class testit {
59
58
  static title(value: string): Promise<void>;
60
59
  static description(value: string): Promise<void>;
61
60
  static labels(value: string[]): Promise<void>;
62
- static layer(value: string): Promise<void>;
63
61
  static tags(value: string[]): Promise<void>;
64
62
  static links(value: Link[]): Promise<void>;
65
63
  static namespace(value: string): Promise<void>;
package/dist/labels.js CHANGED
@@ -136,11 +136,6 @@ class testit {
136
136
  labels: value.map((label) => ({ name: label })),
137
137
  });
138
138
  }
139
- static async layer(value) {
140
- await this.addMetadataAttachment({
141
- layer: value,
142
- });
143
- }
144
139
  static async tags(value) {
145
140
  await this.addMetadataAttachment({
146
141
  tags: value,
@@ -77,9 +77,6 @@ function applyMetadataTo(target, source) {
77
77
  if (source.labels) {
78
78
  target.labels = source.labels;
79
79
  }
80
- if (source.layer) {
81
- target.layer = source.layer;
82
- }
83
80
  if (source.tags) {
84
81
  target.tags = source.tags;
85
82
  }
@@ -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
  }
@@ -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
- testit_js_commons_2.logger.debug("[playwright] reporter init", { importRealtime: Boolean(config.importRealtime) });
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
- testit_js_commons_2.logger.debug("[playwright] onTestEnd realtime", { title: test.title, status: result.status });
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,27 +106,72 @@ class TmsReporter {
100
106
  async onEnd() {
101
107
  try {
102
108
  await this.setupPromise.catch((err) => {
103
- testit_js_commons_2.logger.error("TMS Playwright setup failed:", err?.body ?? err?.error ?? err);
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
- testit_js_commons_2.logger.debug("[playwright] onEnd batch flush", { count: this.bufferedResults.length });
107
- await Promise.allSettled(this.bufferedResults.map(({ test, result }) => this.runLoadTest(test, result)));
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
- testit_js_commons_2.logger.debug("[playwright] onEnd await realtime", { pending: this.loadTestPromises.length });
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
- testit_js_commons_2.logger.error("TMS Playwright onEnd failed:", err?.body ?? err?.error ?? err);
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
- testit_js_commons_2.logger.error("TMS Playwright teardown failed:", err?.body ?? err?.error ?? err);
126
+ testit_js_commons_1.logger.error("TMS Playwright teardown failed:", err?.body ?? err?.error ?? err);
121
127
  });
122
128
  }
123
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);
169
+ });
170
+ }
171
+ for (const test of testsToRelease.values()) {
172
+ (0, metadata_store_1.releaseTestMetadata)(this.metadataContext(test));
173
+ }
174
+ }
124
175
  async addSkippedResults() {
125
176
  const unprocessedCases = this.suite
126
177
  .allTests()
@@ -130,27 +181,33 @@ class TmsReporter {
130
181
  attachments: [],
131
182
  duration: 0,
132
183
  errors: [],
184
+ retry: 0,
133
185
  steps: [],
134
186
  }).catch((err) => {
135
- testit_js_commons_2.logger.error("TMS Playwright loadTest (skipped) failed:", testCase?.title, err?.body ?? err?.error ?? err);
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
- testit_js_commons_2.logger.log("Error processing test result. \n", err?.body ?? err?.error ?? err);
194
+ testit_js_commons_1.logger.log("Error processing test result. \n", err?.body ?? err?.error ?? err);
143
195
  });
144
196
  }
145
197
  printsToStdio() {
146
198
  return false;
147
199
  }
148
200
  getDictionariesByTest(test) {
149
- const location = test.parent.title;
150
- if (location == undefined) {
201
+ const file = test.location?.file;
202
+ if (!file) {
151
203
  return [];
152
204
  }
153
- return location.split(path_1.default.sep);
205
+ const rootDir = this.config?.rootDir;
206
+ const relative = rootDir ? path_1.default.relative(rootDir, file) : file;
207
+ if (!relative || relative.startsWith("..")) {
208
+ return path_1.default.basename(file) ? [path_1.default.basename(file)] : [];
209
+ }
210
+ return relative.split(/[/\\]/).filter(Boolean);
154
211
  }
155
212
  async getAutotestData(test, result) {
156
213
  const autotestData = {
@@ -180,7 +237,7 @@ class TmsReporter {
180
237
  autotestData.addAttachments?.push(...ids);
181
238
  }
182
239
  catch (err) {
183
- testit_js_commons_2.logger.log("Error uploading file attachment. \n", err?.body ?? err?.error ?? err);
240
+ testit_js_commons_1.logger.log("Error uploading file attachment. \n", err?.body ?? err?.error ?? err);
184
241
  }
185
242
  }
186
243
  continue;
@@ -189,14 +246,15 @@ class TmsReporter {
189
246
  const step = this.attachmentStepsCache.find((step) => step.title === attachment.name);
190
247
  try {
191
248
  const ids = await this.additions.addAttachments(attachment.body, attachment.name.replace(utils_1.stepAttachRegexp, ""));
192
- if (step?.parent) {
193
- this.attachmentsMap.set(ids[0], step.parent);
249
+ const parentStep = (0, utils_1.resolveAttachmentParentStep)(step);
250
+ if (parentStep) {
251
+ this.attachmentsMap.set(ids[0], parentStep);
194
252
  continue;
195
253
  }
196
254
  autotestData.addAttachments?.push(...ids);
197
255
  }
198
256
  catch (err) {
199
- testit_js_commons_2.logger.log("Error uploading text attachment. \n", err?.body ?? err?.error ?? err);
257
+ testit_js_commons_1.logger.log("Error uploading text attachment. \n", err?.body ?? err?.error ?? err);
200
258
  }
201
259
  }
202
260
  }
@@ -204,7 +262,7 @@ class TmsReporter {
204
262
  const stored = (0, metadata_store_1.resolveTestMetadata)(this.metadataContext(test));
205
263
  if (stored) {
206
264
  (0, metadata_store_1.applyMetadataTo)(autotestData, stored);
207
- testit_js_commons_2.logger.debug("[playwright] metadata from store", {
265
+ testit_js_commons_1.logger.debug("[playwright] metadata from store", {
208
266
  title: test.title,
209
267
  namespace: autotestData.namespace,
210
268
  classname: autotestData.classname,
@@ -249,31 +307,52 @@ class TmsReporter {
249
307
  }
250
308
  (0, metadata_store_1.applyMetadataTo)(autotestData, merged);
251
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
+ }
252
345
  async loadTest(test, result) {
253
- testit_js_commons_2.logger.debug("[playwright] loadTest", { title: test.title, status: result.status });
346
+ testit_js_commons_1.logger.debug("[playwright] loadTest", {
347
+ title: test.title,
348
+ status: result.status,
349
+ retry: result.retry,
350
+ });
254
351
  try {
255
- const autotestData = await this.getAutotestData(test, result);
256
- const dictionaries = this.getDictionariesByTest(test);
257
- const pathNamespace = dictionaries.slice(0, -1).join(path_1.default.sep);
258
- const pathClassname = dictionaries[dictionaries.length - 1];
259
- // Prefer testit.namespace / testit.classname from metadata; file path only when missing.
260
- if (pathNamespace.length > 0 && autotestData.namespace == null) {
261
- autotestData.namespace = pathNamespace;
262
- }
263
- if (pathClassname?.length && autotestData.classname == null) {
264
- autotestData.classname = pathClassname;
352
+ const autotestResult = await this.prepareTestResult(test, result);
353
+ if (autotestResult) {
354
+ await this.strategy.loadTestRun([autotestResult]);
265
355
  }
266
- const autotest = converter_1.Converter.convertTestCaseToAutotestPost(autotestData);
267
- const rawSteps = result.steps?.length
268
- ? result.steps
269
- : [...this.stepsMap.keys()].filter((step) => this.stepsMap.get(step) === test);
270
- const stepResults = converter_1.Converter.convertTestStepsToSteps(rawSteps, this.attachmentsMap);
271
- result.status = (0, utils_1.getTestStatus)(test);
272
- autotest.steps = converter_1.Converter.convertTestStepsToShortSteps(rawSteps);
273
- await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus));
274
- const autotestResult = converter_1.Converter.convertAutotestPostToAutotestResult(autotestData, test, result);
275
- autotestResult.stepResults = stepResults;
276
- await this.strategy.loadTestRun([autotestResult]);
277
356
  }
278
357
  finally {
279
358
  (0, metadata_store_1.releaseTestMetadata)(this.metadataContext(test));
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TestCase, TestError, TestStatus, TestStep } from "@playwright/test/reporter";
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.6",
3
+ "version": "5.0.8-TMS-5.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.6"
43
+ "testit-js-commons": "5.0.8-TMS-5.8"
44
44
  },
45
45
  "files": [
46
46
  "dist"