@arghajit/dummy 0.1.0-beta-2 → 0.1.0-beta-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.
@@ -16,7 +16,7 @@ export declare class PlaywrightPulseReporter implements Reporter {
16
16
  onBegin(config: FullConfig, suite: Suite): void;
17
17
  onTestBegin(test: TestCase): void;
18
18
  private processStep;
19
- getBrowserInfo(test: TestCase): Promise<string>;
19
+ getBrowserInfo(test: TestCase): string;
20
20
  onTestEnd(test: TestCase, result: PwTestResult): Promise<void>;
21
21
  onError(error: any): void;
22
22
  private _writeShardResults;
@@ -146,41 +146,113 @@ class PlaywrightPulseReporter {
146
146
  steps: [],
147
147
  };
148
148
  }
149
- async getBrowserInfo(test) {
150
- var _a, _b, _c;
149
+ getBrowserInfo(test) {
150
+ var _a, _b, _c, _d, _e, _f, _g, _h;
151
+ // Changed return type to string
151
152
  const project = (_a = test.parent) === null || _a === void 0 ? void 0 : _a.project();
152
- const userAgent = (_b = project === null || project === void 0 ? void 0 : project.use) === null || _b === void 0 ? void 0 : _b.userAgent;
153
- const ua = userAgent || "Unknown User Agent";
154
- const browserName = (_c = project === null || project === void 0 ? void 0 : project.use) === null || _c === void 0 ? void 0 : _c.defaultBrowserType;
155
- try {
156
- const parser = new ua_parser_js_1.UAParser(ua);
157
- const result = parser.getResult();
158
- // 1. Determine browser name
159
- let browser = result.browser.name || browserName;
160
- // 2. Handle mobile webviews
161
- if (result.engine.name === "WebKit" && result.device.type === "mobile") {
162
- browser = "Mobile Safari";
153
+ const configuredBrowserType = (_c = (_b = project === null || project === void 0 ? void 0 : project.use) === null || _b === void 0 ? void 0 : _b.defaultBrowserType) === null || _c === void 0 ? void 0 : _c.toLowerCase(); // e.g., "chromium", "firefox", "webkit"
154
+ const userAgentString = (_d = project === null || project === void 0 ? void 0 : project.use) === null || _d === void 0 ? void 0 : _d.userAgent;
155
+ let finalBrowserName = configuredBrowserType || "unknown"; // Start with the configured type or "unknown"
156
+ let version = "";
157
+ let osName = "";
158
+ let osVersion = "";
159
+ let deviceType = "";
160
+ if (userAgentString) {
161
+ try {
162
+ const parser = new ua_parser_js_1.UAParser(userAgentString);
163
+ const uaResult = parser.getResult();
164
+ deviceType = uaResult.device.type || ""; // e.g., "mobile", "tablet", "console", "smarttv"
165
+ // 1. Try UAParser's browser name
166
+ if (uaResult.browser.name) {
167
+ finalBrowserName = uaResult.browser.name;
168
+ if (uaResult.browser.version) {
169
+ // Get major version, or full version if no dot
170
+ version = ` v${uaResult.browser.version.split(".")[0]}`;
171
+ }
172
+ }
173
+ // If UAParser didn't find a browser name, but we have an engine,
174
+ // it might be more informative than just the configuredBrowserType.
175
+ else if (uaResult.engine.name &&
176
+ configuredBrowserType !== uaResult.engine.name.toLowerCase()) {
177
+ // Prefer engine name if it's more specific and different from default (e.g. WebKit for a generic device)
178
+ finalBrowserName = uaResult.engine.name;
179
+ }
180
+ // 2. Specific Overrides / Refinements
181
+ // Handling for mobile devices, especially if UAParser provides generic browser names
182
+ if (deviceType === "mobile" || deviceType === "tablet") {
183
+ if (((_e = uaResult.os.name) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes("ios")) ||
184
+ uaResult.browser.name === "Mobile Safari") {
185
+ finalBrowserName = "Mobile Safari";
186
+ }
187
+ else if ((_f = uaResult.os.name) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes("android")) {
188
+ if ((_g = uaResult.browser.name) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes("chrome")) {
189
+ finalBrowserName = "Chrome Mobile";
190
+ }
191
+ else if ((_h = uaResult.browser.name) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes("firefox")) {
192
+ finalBrowserName = "Firefox Mobile";
193
+ }
194
+ else if (uaResult.engine.name === "Blink" &&
195
+ !uaResult.browser.name) {
196
+ // Generic Android Webview
197
+ finalBrowserName = "Android WebView";
198
+ }
199
+ else if (uaResult.browser.name) {
200
+ finalBrowserName = `${uaResult.browser.name} Mobile`; // Generic, e.g., "Opera Mobile"
201
+ }
202
+ else {
203
+ finalBrowserName = "Android Browser"; // Fallback for Android
204
+ }
205
+ }
206
+ }
207
+ else if (uaResult.browser.name === "Electron") {
208
+ finalBrowserName = "Electron App"; // More descriptive for Electron
209
+ // For Electron, version might be app's version, not Chromium's.
210
+ // You might need custom logic if you want the underlying Chromium version.
211
+ }
212
+ // 3. OS Information
213
+ if (uaResult.os.name) {
214
+ osName = ` on ${uaResult.os.name}`;
215
+ if (uaResult.os.version) {
216
+ osVersion = ` ${uaResult.os.version.split(".")[0]}`; // Major OS version
217
+ }
218
+ }
219
+ }
220
+ catch (error) {
221
+ console.warn(`Pulse Reporter: Error parsing User-Agent string "${userAgentString}":`, error);
222
+ // Fallback to configuredBrowserType already set in finalBrowserName
163
223
  }
164
- // 3. Clean version string
165
- const version = result.browser.version
166
- ? ` v${result.browser.version.split(".")[0]}`
167
- : "";
168
- // 4. OS information
169
- const osInfo = result.os.name ? ` on ${result.os.name}` : "";
170
- const osVersion = result.os.version
171
- ? ` ${result.os.version.split(".")[0]}`
172
- : "";
173
- return `${browser}${version}${osInfo}${osVersion}`.trim();
174
224
  }
175
- catch (error) {
176
- return browserName || "Unknown Browser";
225
+ // If after UA parsing, we still have a generic engine name like "Blink" or "WebKit"
226
+ // and a more specific configuredBrowserType exists (like "chromium"), prefer the configured one.
227
+ if ((finalBrowserName.toLowerCase() === "blink" ||
228
+ finalBrowserName.toLowerCase() === "webkit" ||
229
+ finalBrowserName.toLowerCase() === "gecko") &&
230
+ configuredBrowserType &&
231
+ configuredBrowserType !== "unknown") {
232
+ finalBrowserName =
233
+ configuredBrowserType.charAt(0).toUpperCase() +
234
+ configuredBrowserType.slice(1); // Capitalize
235
+ }
236
+ // Construct the display string
237
+ // Prioritize showing device type for mobile/tablet if it adds clarity
238
+ let displayString = finalBrowserName;
239
+ if (version)
240
+ displayString += version;
241
+ // Add device type if it's mobile/tablet and not already obvious from browser name
242
+ if ((deviceType === "mobile" || deviceType === "tablet") &&
243
+ !finalBrowserName.toLowerCase().includes(deviceType)) {
244
+ // displayString += ` (${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)})`;
177
245
  }
246
+ if (osName)
247
+ displayString += osName;
248
+ if (osVersion && osName)
249
+ displayString += osVersion; // Only add osVersion if osName is present
250
+ return displayString.trim();
178
251
  }
179
252
  async onTestEnd(test, result) {
180
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
253
+ var _a, _b, _c, _d, _e, _f, _g, _h;
181
254
  const project = (_a = test.parent) === null || _a === void 0 ? void 0 : _a.project();
182
- const ua = (_b = project === null || project === void 0 ? void 0 : project.use) === null || _b === void 0 ? void 0 : _b.userAgent;
183
- const browserName = ((_c = project === null || project === void 0 ? void 0 : project.use) === null || _c === void 0 ? void 0 : _c.defaultBrowserType) || (project === null || project === void 0 ? void 0 : project.name) || "unknown";
255
+ const browserName = this.getBrowserInfo(test);
184
256
  const testStatus = convertStatus(result.status, test);
185
257
  const startTime = new Date(result.startTime);
186
258
  const endTime = new Date(startTime.getTime() + result.duration);
@@ -202,7 +274,7 @@ class PlaywrightPulseReporter {
202
274
  };
203
275
  let codeSnippet = undefined;
204
276
  try {
205
- if (((_d = test.location) === null || _d === void 0 ? void 0 : _d.file) && ((_e = test.location) === null || _e === void 0 ? void 0 : _e.line) && ((_f = test.location) === null || _f === void 0 ? void 0 : _f.column)) {
277
+ if (((_b = test.location) === null || _b === void 0 ? void 0 : _b.file) && ((_c = test.location) === null || _c === void 0 ? void 0 : _c.line) && ((_d = test.location) === null || _d === void 0 ? void 0 : _d.column)) {
206
278
  const relativePath = path.relative(this.config.rootDir, test.location.file);
207
279
  codeSnippet = `Test defined at: ${relativePath}:${test.location.line}:${test.location.column}`;
208
280
  }
@@ -227,16 +299,16 @@ class PlaywrightPulseReporter {
227
299
  id: uniqueTestId,
228
300
  runId: "TBD",
229
301
  name: test.titlePath().join(" > "),
230
- suiteName: (project === null || project === void 0 ? void 0 : project.name) || ((_g = this.config.projects[0]) === null || _g === void 0 ? void 0 : _g.name) || "Default Suite",
302
+ suiteName: (project === null || project === void 0 ? void 0 : project.name) || ((_e = this.config.projects[0]) === null || _e === void 0 ? void 0 : _e.name) || "Default Suite",
231
303
  status: testStatus,
232
304
  duration: result.duration,
233
305
  startTime: startTime,
234
306
  endTime: endTime,
235
307
  browser: browserName,
236
308
  retries: result.retry,
237
- steps: ((_h = result.steps) === null || _h === void 0 ? void 0 : _h.length) ? await processAllSteps(result.steps) : [],
238
- errorMessage: (_j = result.error) === null || _j === void 0 ? void 0 : _j.message,
239
- stackTrace: (_k = result.error) === null || _k === void 0 ? void 0 : _k.stack,
309
+ steps: ((_f = result.steps) === null || _f === void 0 ? void 0 : _f.length) ? await processAllSteps(result.steps) : [],
310
+ errorMessage: (_g = result.error) === null || _g === void 0 ? void 0 : _g.message,
311
+ stackTrace: (_h = result.error) === null || _h === void 0 ? void 0 : _h.stack,
240
312
  codeSnippet: codeSnippet,
241
313
  tags: test.tags.map((tag) => tag.startsWith("@") ? tag.substring(1) : tag),
242
314
  screenshots: [],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arghajit/dummy",
3
3
  "author": "Arghajit Singha",
4
- "version": "0.1.0-beta-2",
4
+ "version": "0.1.0-beta-4",
5
5
  "description": "A Playwright reporter and dashboard for visualizing test results.",
6
6
  "keywords": [
7
7
  "playwright",