testlens-playwright-reporter 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/index.ts +14 -21
  2. package/lib/index.js +15 -21
  3. package/package.json +3 -2
package/index.ts CHANGED
@@ -4,9 +4,10 @@ import * as path from 'path';
4
4
  import * as fs from 'fs';
5
5
  import * as https from 'https';
6
6
  import axios, { AxiosInstance } from 'axios';
7
- import { Reporter, TestCase, TestResult, FullConfig, Suite } from '@playwright/test/reporter';
7
+ import type { Reporter, TestCase, TestResult, FullConfig, Suite } from '@playwright/test/reporter';
8
8
  import { execSync } from 'child_process';
9
9
  import * as mime from 'mime';
10
+ import FormData from 'form-data';
10
11
  export interface TestLensReporterConfig {
11
12
  /** TestLens API endpoint URL */
12
13
  apiEndpoint?: string;
@@ -442,15 +443,20 @@ export class TestLensReporter implements Reporter {
442
443
 
443
444
  private async sendToApi(payload: any): Promise<void> {
444
445
  try {
446
+ console.log(`📤 Sending ${payload.type} event to ${this.config.apiEndpoint}`);
445
447
  const response = await this.axiosInstance.post('', payload);
446
448
  if (this.config.enableRealTimeStream) {
447
- console.log(`✅ Sent ${payload.type} event to TestLens`);
449
+ console.log(`✅ Sent ${payload.type} event to TestLens (HTTP ${response.status})`);
448
450
  }
449
451
  } catch (error: any) {
450
452
  console.error(`❌ Failed to send ${payload.type} event to TestLens:`, {
451
453
  message: error?.message || 'Unknown error',
452
454
  status: error?.response?.status,
453
- data: error?.response?.data
455
+ statusText: error?.response?.statusText,
456
+ data: error?.response?.data,
457
+ code: error?.code,
458
+ url: error?.config?.url,
459
+ method: error?.config?.method
454
460
  });
455
461
 
456
462
  // Don't throw error to avoid breaking test execution
@@ -669,7 +675,6 @@ export class TestLensReporter implements Reporter {
669
675
  const uploadUrl = `${baseUrl}/api/v1/artifacts/public/upload`;
670
676
 
671
677
  // Prepare form data for multipart upload
672
- const FormData = require('form-data');
673
678
  const form = new FormData();
674
679
 
675
680
  // Add required fields
@@ -679,7 +684,7 @@ export class TestLensReporter implements Reporter {
679
684
  form.append('artifactType', this.getArtifactType(fileName));
680
685
  form.append('file', fs.createReadStream(filePath), {
681
686
  filename: fileName,
682
- contentType: this.getContentType(path.extname(filePath).toLowerCase())
687
+ contentType: this.getContentType(fileName)
683
688
  });
684
689
 
685
690
  console.log(`📤 Uploading ${fileName} to TestLens S3 via API...`);
@@ -717,22 +722,10 @@ export class TestLensReporter implements Reporter {
717
722
  }
718
723
  }
719
724
 
720
- private getContentType(ext: string): string {
721
- const contentTypes: { [key: string]: string } = {
722
- '.mp4': 'video/mp4',
723
- '.webm': 'video/webm',
724
- '.png': 'image/png',
725
- '.jpg': 'image/jpeg',
726
- '.jpeg': 'image/jpeg',
727
- '.gif': 'image/gif',
728
- '.json': 'application/json',
729
- '.txt': 'text/plain',
730
- '.html': 'text/html',
731
- '.xml': 'application/xml',
732
- '.zip': 'application/zip',
733
- '.pdf': 'application/pdf'
734
- };
735
- return contentTypes[ext] || 'application/octet-stream';
725
+ private getContentType(fileName: string): string {
726
+ const ext = path.extname(fileName).toLowerCase();
727
+ const mimeType = mime.default.getType(ext) || 'application/octet-stream';
728
+ return mimeType;
736
729
  }
737
730
 
738
731
  private generateS3Key(runId: string, testId: string, fileName: string): string {
package/lib/index.js CHANGED
@@ -44,6 +44,8 @@ const fs = __importStar(require("fs"));
44
44
  const https = __importStar(require("https"));
45
45
  const axios_1 = __importDefault(require("axios"));
46
46
  const child_process_1 = require("child_process");
47
+ const mime = __importStar(require("mime"));
48
+ const form_data_1 = __importDefault(require("form-data"));
47
49
  class TestLensReporter {
48
50
  constructor(options) {
49
51
  this.config = {
@@ -314,16 +316,21 @@ class TestLensReporter {
314
316
  }
315
317
  async sendToApi(payload) {
316
318
  try {
319
+ console.log(`📤 Sending ${payload.type} event to ${this.config.apiEndpoint}`);
317
320
  const response = await this.axiosInstance.post('', payload);
318
321
  if (this.config.enableRealTimeStream) {
319
- console.log(`✅ Sent ${payload.type} event to TestLens`);
322
+ console.log(`✅ Sent ${payload.type} event to TestLens (HTTP ${response.status})`);
320
323
  }
321
324
  }
322
325
  catch (error) {
323
326
  console.error(`❌ Failed to send ${payload.type} event to TestLens:`, {
324
327
  message: error?.message || 'Unknown error',
325
328
  status: error?.response?.status,
326
- data: error?.response?.data
329
+ statusText: error?.response?.statusText,
330
+ data: error?.response?.data,
331
+ code: error?.code,
332
+ url: error?.config?.url,
333
+ method: error?.config?.method
327
334
  });
328
335
  // Don't throw error to avoid breaking test execution
329
336
  }
@@ -518,8 +525,7 @@ class TestLensReporter {
518
525
  const baseUrl = this.config.apiEndpoint.replace('/api/v1/webhook/playwright', '');
519
526
  const uploadUrl = `${baseUrl}/api/v1/artifacts/public/upload`;
520
527
  // Prepare form data for multipart upload
521
- const FormData = require('form-data');
522
- const form = new FormData();
528
+ const form = new form_data_1.default();
523
529
  // Add required fields
524
530
  form.append('apiKey', this.config.apiKey);
525
531
  form.append('testRunId', this.runId);
@@ -527,7 +533,7 @@ class TestLensReporter {
527
533
  form.append('artifactType', this.getArtifactType(fileName));
528
534
  form.append('file', fs.createReadStream(filePath), {
529
535
  filename: fileName,
530
- contentType: this.getContentType(path.extname(filePath).toLowerCase())
536
+ contentType: this.getContentType(fileName)
531
537
  });
532
538
  console.log(`📤 Uploading ${fileName} to TestLens S3 via API...`);
533
539
  // Make the upload request
@@ -561,22 +567,10 @@ class TestLensReporter {
561
567
  throw error; // Re-throw to prevent fallback to local storage
562
568
  }
563
569
  }
564
- getContentType(ext) {
565
- const contentTypes = {
566
- '.mp4': 'video/mp4',
567
- '.webm': 'video/webm',
568
- '.png': 'image/png',
569
- '.jpg': 'image/jpeg',
570
- '.jpeg': 'image/jpeg',
571
- '.gif': 'image/gif',
572
- '.json': 'application/json',
573
- '.txt': 'text/plain',
574
- '.html': 'text/html',
575
- '.xml': 'application/xml',
576
- '.zip': 'application/zip',
577
- '.pdf': 'application/pdf'
578
- };
579
- return contentTypes[ext] || 'application/octet-stream';
570
+ getContentType(fileName) {
571
+ const ext = path.extname(fileName).toLowerCase();
572
+ const mimeType = mime.default.getType(ext) || 'application/octet-stream';
573
+ return mimeType;
580
574
  }
581
575
  generateS3Key(runId, testId, fileName) {
582
576
  const date = new Date().toISOString().slice(0, 10);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testlens-playwright-reporter",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Universal Playwright reporter for TestLens - works with both TypeScript and JavaScript projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -36,7 +36,7 @@
36
36
  "author": {
37
37
  "name": "TestLens Team",
38
38
  "email": "support@testlens.io",
39
- "url": "https://testlens.io"
39
+ "url": "https://testlens.qa-path.com"
40
40
  },
41
41
  "license": "MIT",
42
42
  "peerDependencies": {
@@ -47,6 +47,7 @@
47
47
  "@aws-sdk/s3-request-presigner": "^3.624.0",
48
48
  "axios": "^1.11.0",
49
49
  "dotenv": "^16.4.5",
50
+ "form-data": "^4.0.1",
50
51
  "mime": "^4.0.4"
51
52
  },
52
53
  "engines": {