testit-adapter-playwright 4.0.5 → 4.1.0

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
@@ -12,6 +12,12 @@ npm install testit-adapter-playwright
12
12
 
13
13
  ### Configuration
14
14
 
15
+
16
+ #### Log level
17
+
18
+ The adapter includes a custom logger; the default level is `warn`. Set another level at runtime with the `LOG_LEVEL` environment variable: `error`, `warn`, `info`, or `debug`.
19
+
20
+
15
21
  | Description | File property | Environment variable |
16
22
  |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|--------------------------------------------|
17
23
  | Location of the TMS instance | url | TMS_URL |
@@ -24,6 +30,7 @@ npm install testit-adapter-playwright
24
30
  | It enables/disables certificate validation (**It's optional**). Default value - true | certValidation | TMS_CERT_VALIDATION |
25
31
  | Mode of automatic creation test cases (**It's optional**). Default value - false. The adapter supports following modes:<br/>true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)<br/>false - in this mode, the adapter will not create a test case | automaticCreationTestCases | TMS_AUTOMATIC_CREATION_TEST_CASES |
26
32
  | Mode of automatic updation links to test cases (**It's optional**). Default value - false. The adapter supports following modes:<br/>true - in this mode, the adapter will update links to test cases<br/>false - in this mode, the adapter will not update link to test cases | automaticUpdationLinksToTestCases | TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES |
33
+ | Logger level, default value is `warn`, available values: [`error`, `warn`, `info`, `debug`] | | LOG_LEVEL |
27
34
 
28
35
  Add Adapter to Playwright file configuration:
29
36
 
@@ -20,6 +20,8 @@ declare class TmsReporter implements Reporter {
20
20
  private attachmentsMap;
21
21
  private loadTestPromises;
22
22
  private setupPromise;
23
+ private readonly adapterConfig;
24
+ private bufferedResults;
23
25
  constructor(options: ReporterOptions);
24
26
  onBegin(config: FullConfig, suite: Suite): void;
25
27
  onTestBegin(test: TestCase): void;
@@ -28,6 +30,7 @@ declare class TmsReporter implements Reporter {
28
30
  onStepBegin(test: TestCase, _result: TestResult, step: TestStep): void;
29
31
  onEnd(): Promise<void>;
30
32
  addSkippedResults(): Promise<void>;
33
+ private runLoadTest;
31
34
  printsToStdio(): boolean;
32
35
  private getDictionariesByTest;
33
36
  private getAutotestData;
package/dist/reporter.js CHANGED
@@ -21,6 +21,7 @@ const testit_js_commons_1 = require("testit-js-commons");
21
21
  const converter_1 = require("./converter");
22
22
  const utils_1 = require("./utils");
23
23
  const path_1 = __importDefault(require("path"));
24
+ const testit_js_commons_2 = require("testit-js-commons");
24
25
  class TmsReporter {
25
26
  constructor(options) {
26
27
  this.testCache = new Array();
@@ -29,10 +30,13 @@ class TmsReporter {
29
30
  this.attachmentsMap = new Map();
30
31
  this.loadTestPromises = new Array();
31
32
  this.setupPromise = Promise.resolve();
33
+ this.bufferedResults = [];
32
34
  this.options = { suiteTitle: true, detail: true, ...options };
33
35
  const config = new testit_js_commons_1.ConfigComposer().compose(options.tmsOptions);
36
+ this.adapterConfig = config;
34
37
  this.strategy = testit_js_commons_1.StrategyFactory.create(config);
35
38
  this.additions = new testit_js_commons_1.Additions(config);
39
+ testit_js_commons_2.logger.debug("[playwright] reporter init", { importRealtime: Boolean(config.importRealtime) });
36
40
  }
37
41
  onBegin(config, suite) {
38
42
  this.config = config;
@@ -43,16 +47,20 @@ class TmsReporter {
43
47
  this.testCache.push(test);
44
48
  }
45
49
  onTestEnd(test, result) {
46
- this.loadTestPromises.push(this.setupPromise.then(() => this.loadTest(test, {
50
+ const currentResult = {
47
51
  status: result.status,
48
52
  attachments: this._processAttachmentsWithExtensions(result),
49
53
  duration: result.duration,
50
54
  errors: result.errors,
51
55
  error: result.error,
52
56
  steps: result.steps,
53
- })).catch((err) => {
54
- console.log("Error processing test result. \n", err?.body ?? err?.error ?? err);
55
- }));
57
+ };
58
+ if (this.adapterConfig.importRealtime) {
59
+ testit_js_commons_2.logger.debug("[playwright] onTestEnd realtime", { title: test.title, status: result.status });
60
+ this.loadTestPromises.push(this.runLoadTest(test, currentResult));
61
+ return;
62
+ }
63
+ this.bufferedResults.push({ test, result: currentResult });
56
64
  }
57
65
  // fix issues with trace and video files on playwright
58
66
  _processAttachmentsWithExtensions(result) {
@@ -80,17 +88,24 @@ class TmsReporter {
80
88
  async onEnd() {
81
89
  try {
82
90
  await this.setupPromise.catch((err) => {
83
- console.error("TMS Playwright setup failed:", err?.body ?? err?.error ?? err);
91
+ testit_js_commons_2.logger.error("TMS Playwright setup failed:", err?.body ?? err?.error ?? err);
84
92
  });
93
+ if (!this.adapterConfig.importRealtime) {
94
+ testit_js_commons_2.logger.debug("[playwright] onEnd batch flush", { count: this.bufferedResults.length });
95
+ await Promise.allSettled(this.bufferedResults.map(({ test, result }) => this.runLoadTest(test, result)));
96
+ }
97
+ else {
98
+ testit_js_commons_2.logger.debug("[playwright] onEnd await realtime", { pending: this.loadTestPromises.length });
99
+ }
85
100
  await Promise.allSettled(this.loadTestPromises);
86
101
  await this.addSkippedResults();
87
102
  }
88
103
  catch (err) {
89
- console.error("TMS Playwright onEnd failed:", err?.body ?? err?.error ?? err);
104
+ testit_js_commons_2.logger.error("TMS Playwright onEnd failed:", err?.body ?? err?.error ?? err);
90
105
  }
91
106
  finally {
92
107
  await this.strategy.teardown().catch((err) => {
93
- console.error("TMS Playwright teardown failed:", err?.body ?? err?.error ?? err);
108
+ testit_js_commons_2.logger.error("TMS Playwright teardown failed:", err?.body ?? err?.error ?? err);
94
109
  });
95
110
  }
96
111
  }
@@ -105,9 +120,16 @@ class TmsReporter {
105
120
  errors: [],
106
121
  steps: [],
107
122
  }).catch((err) => {
108
- console.error("TMS Playwright loadTest (skipped) failed:", testCase?.title, err?.body ?? err?.error ?? err);
123
+ testit_js_commons_2.logger.error("TMS Playwright loadTest (skipped) failed:", testCase?.title, err?.body ?? err?.error ?? err);
109
124
  })));
110
125
  }
126
+ runLoadTest(test, result) {
127
+ return this.setupPromise
128
+ .then(() => this.loadTest(test, result))
129
+ .catch((err) => {
130
+ testit_js_commons_2.logger.log("Error processing test result. \n", err?.body ?? err?.error ?? err);
131
+ });
132
+ }
111
133
  printsToStdio() {
112
134
  return false;
113
135
  }
@@ -143,7 +165,7 @@ class TmsReporter {
143
165
  autotestData.addAttachments?.push(...ids);
144
166
  }
145
167
  catch (err) {
146
- console.log("Error uploading file attachment. \n", err?.body ?? err?.error ?? err);
168
+ testit_js_commons_2.logger.log("Error uploading file attachment. \n", err?.body ?? err?.error ?? err);
147
169
  }
148
170
  }
149
171
  continue;
@@ -202,13 +224,14 @@ class TmsReporter {
202
224
  autotestData.addAttachments?.push(...ids);
203
225
  }
204
226
  catch (err) {
205
- console.log("Error uploading text attachment. \n", err?.body ?? err?.error ?? err);
227
+ testit_js_commons_2.logger.log("Error uploading text attachment. \n", err?.body ?? err?.error ?? err);
206
228
  }
207
229
  }
208
230
  }
209
231
  return autotestData;
210
232
  }
211
233
  async loadTest(test, result) {
234
+ testit_js_commons_2.logger.debug("[playwright] loadTest", { title: test.title, status: result.status });
212
235
  const autotestData = await this.getAutotestData(test, result);
213
236
  const origin = await this.strategy.client.autoTests.getAutotestByExternalId(autotestData.externalId);
214
237
  if (!origin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-adapter-playwright",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
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": "4.0.5"
43
+ "testit-js-commons": "4.1.0"
44
44
  },
45
45
  "files": [
46
46
  "dist"