testlens-playwright-reporter 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TestLens Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,238 @@
1
+ ````markdown
2
+ # TestLens Playwright Reporter
3
+
4
+ A modern, feature-rich Playwright reporter that works with both TypeScript and JavaScript projects, integrating seamlessly with your TestLens dashboard.
5
+
6
+ ## ๐Ÿš€ Features
7
+
8
+ - โœ… **Universal Compatibility** - Works with both TypeScript and JavaScript Playwright projects
9
+ - ๐Ÿ”„ **Real-time Streaming** - Live test results streaming to TestLens dashboard
10
+ - ๐Ÿ“Š **Comprehensive Reporting** - Test results, artifacts, and detailed metrics
11
+ - ๐ŸŒฟ **Git Integration** - Automatic collection of Git information (branch, commit, author, etc.)
12
+ - ๐Ÿ“ **Code Block Extraction** - Intelligent extraction of test code for better debugging
13
+ - ๐Ÿ”„ **Retry Logic** - Robust error handling and retry mechanisms
14
+ - ๐ŸŽฏ **Artifact Support** - Screenshots, videos, traces, and custom attachments with S3 storage
15
+ - โ˜๏ธ **S3 Integration** - Automatic upload of artifacts to Amazon S3 for persistent storage
16
+
17
+ ## ๐Ÿ“ฆ Installation
18
+
19
+ ### Option 1: npm install (Recommended)
20
+
21
+ ```bash
22
+ # Install the TestLens Playwright Reporter
23
+ npm install @testlens/playwright-reporter --save-dev
24
+
25
+ # Install the TestLens Playwright Reporter uisng the file locally
26
+ npm install --save-dev ./testlens-playwright-reporter-x.y.z.tgz
27
+
28
+ # Or using yarn
29
+ yarn add @testlens/playwright-reporter --dev
30
+
31
+ # Or using pnpm
32
+ pnpm add -D @testlens/playwright-reporter
33
+ ```
34
+
35
+ ### Option 2: Use from centralized location
36
+
37
+ ```bash
38
+ # Clone or copy the testlens-reporter to a central location
39
+ git clone https://github.com/alternative-path/testlens-reporter.git D:\Experiment\AP\testlens-reporter
40
+
41
+ # Install dependencies
42
+ cd D:\Experiment\AP\testlens-reporter
43
+ npm install
44
+
45
+ # Reference from your Playwright projects using absolute path or environment variable
46
+ ```
47
+
48
+ ## โš™๏ธ Configuration
49
+
50
+ ### 1. Environment Variables
51
+
52
+ No environment file is required! All configuration is embedded in the package. However, you can still override settings if needed by creating a `.env` file:
53
+
54
+ ```env
55
+ # Optional: TestLens API endpoint (defaults to embedded configuration)
56
+ TEST_API_ENDPOINT=http://localhost:3001/api/v1/webhook/playwright
57
+ ```
58
+
59
+ **Note**:
60
+ - S3 configuration is pre-configured and embedded in the package. No additional S3 setup is required.
61
+ - API key must be provided directly in your Playwright configuration file, not in environment variables.
62
+
63
+ ### 2. Playwright Configuration
64
+
65
+ #### For JavaScript projects (`playwright.config.js`):
66
+
67
+ ```javascript
68
+ // @ts-check
69
+ const { defineConfig } = require('@playwright/test');
70
+
71
+ module.exports = defineConfig({
72
+ // ... your existing config
73
+
74
+ reporter: [
75
+ ['list'], // Keep the default console reporter
76
+ ['@testlens/playwright-reporter', {
77
+ // API key is required - provide it directly in config
78
+ apiKey: 'your-api-key-here', // Required: Your TestLens API key
79
+ // Optional overrides (these have embedded defaults)
80
+ apiEndpoint: 'http://localhost:3001/api/v1/webhook/playwright',
81
+ enableRealTimeStream: true,
82
+ enableGitInfo: true,
83
+ enableArtifacts: true,
84
+ enableS3Upload: true, // S3 configuration is embedded
85
+ retryAttempts: 3,
86
+ timeout: 30000
87
+ }]
88
+ ],
89
+
90
+ // ... rest of your config
91
+ });
92
+ ```
93
+
94
+ #### For TypeScript projects (`playwright.config.ts`):
95
+
96
+ ```typescript
97
+ import { defineConfig } from '@playwright/test';
98
+
99
+ export default defineConfig({
100
+ // ... your existing config
101
+
102
+ reporter: [
103
+ ['list'], // Keep the default console reporter
104
+ ['@testlens/playwright-reporter', {
105
+ // API key is required - provide it directly in config
106
+ apiKey: 'your-api-key-here', // Required: Your TestLens API key
107
+ // Optional overrides (these have embedded defaults)
108
+ apiEndpoint: 'http://localhost:3001/api/v1/webhook/playwright',
109
+ enableRealTimeStream: true,
110
+ enableGitInfo: true,
111
+ enableArtifacts: true,
112
+ enableS3Upload: true, // S3 configuration is embedded
113
+ retryAttempts: 3,
114
+ timeout: 30000
115
+ }]
116
+ ],
117
+
118
+ // ... rest of your config
119
+ });
120
+ ```
121
+
122
+ ## ๐Ÿ”ง Configuration Options
123
+
124
+ | Option | Type | Default | Description |
125
+ |--------|------|---------|-------------|
126
+ | `apiEndpoint` | string | `process.env.TEST_API_ENDPOINT` | **Required.** TestLens API endpoint URL |
127
+ | `apiKey` | string | *none* | **Required.** API key for authentication - must be provided in config |
128
+ | `enableRealTimeStream` | boolean | `true` | Enable real-time streaming of test events |
129
+ | `enableGitInfo` | boolean | `true` | Enable Git information collection |
130
+ | `enableArtifacts` | boolean | `true` | Enable artifact processing (screenshots, videos, etc.) |
131
+ | `enableS3Upload` | boolean | `true` | Enable S3 upload for artifacts (S3 configuration is embedded in the package) |
132
+ | `batchSize` | number | `10` | Batch size for API requests |
133
+ | `flushInterval` | number | `5000` | Flush interval in milliseconds |
134
+ | `retryAttempts` | number | `3` | Number of retry attempts for failed API calls |
135
+ | `timeout` | number | `30000` | Request timeout in milliseconds |
136
+
137
+ ## ๐Ÿšฆ Usage
138
+
139
+ Once configured, simply run your Playwright tests as usual:
140
+
141
+ ```bash
142
+ # Run all tests
143
+ npx playwright test
144
+
145
+ # Run specific test file
146
+ npx playwright test tests/login.spec.ts
147
+
148
+ # Run tests in headed mode
149
+ npx playwright test --headed
150
+
151
+ # Run tests with specific reporter only
152
+ npx playwright test --reporter=./testlens-reporter
153
+ ```
154
+
155
+ ## ๐Ÿ“Š What Gets Reported
156
+
157
+ ### Test Execution Data
158
+ - โœ… Test results (passed/failed/skipped)
159
+ - โฑ๏ธ Test duration and timing
160
+ - ๐Ÿ”„ Retry attempts and status
161
+ - ๐Ÿ“ Error messages and stack traces
162
+ - ๐Ÿท๏ธ Test annotations and tags
163
+
164
+ ### System Information
165
+ - ๐ŸŒฟ Git branch, commit, author, and message
166
+ - ๐Ÿ’ป OS and Node.js version
167
+ - ๐ŸŽญ Playwright version
168
+ - ๐ŸŒ Environment information
169
+
170
+ ### Artifacts
171
+ - ๐Ÿ“ธ Screenshots
172
+ - ๐ŸŽฅ Videos
173
+ - ๐Ÿ” Traces
174
+ - ๐Ÿ“Ž Custom attachments
175
+ - โ˜๏ธ **S3 Storage** - Automatic upload to Amazon S3 with presigned URLs for access
176
+
177
+ ### Code Blocks
178
+ - ๐Ÿงช Extracted test code blocks
179
+ - ๐Ÿ“ Test structure and context
180
+ - ๐Ÿ” Searchable test content
181
+
182
+ ## ๐Ÿ› Troubleshooting
183
+
184
+ ### Common Issues
185
+
186
+ #### 1. "TEST_API_ENDPOINT is required" error
187
+ Make sure you have set the `TEST_API_ENDPOINT` environment variable or passed it as a configuration option.
188
+
189
+ #### 2. Connection errors
190
+ - Verify that your TestLens backend is running and accessible
191
+ - Check firewall settings and network connectivity
192
+ - Ensure the API endpoint URL is correct
193
+
194
+ #### 3. Git information not collected
195
+ - Ensure you're running tests from within a Git repository
196
+ - Check that Git is installed and accessible from the command line
197
+ - Git information collection can be disabled with `enableGitInfo: false`
198
+
199
+ ### Debug Mode
200
+
201
+ Enable debug logging by setting environment variable:
202
+
203
+ ```bash
204
+ DEBUG=testlens:* npx playwright test
205
+ ```
206
+
207
+ ## ๐Ÿค Integration with TestLens Dashboard
208
+
209
+ This reporter integrates with your TestLens dashboard to provide:
210
+
211
+ - ๐Ÿ“Š **Real-time Test Results** - See tests as they run
212
+ - ๐Ÿ“ˆ **Historical Trends** - Track test performance over time
213
+ - ๐Ÿ” **Code Block Visualization** - View actual test code in the dashboard
214
+ - ๐ŸŒฟ **Git Integration** - Link test results to commits and branches
215
+ - ๐Ÿ“ฑ **Artifact Gallery** - Browse screenshots, videos, and traces
216
+
217
+ ## ๐Ÿ“„ License
218
+
219
+ MIT License - see LICENSE file for details.
220
+
221
+ ## ๐Ÿค Contributing
222
+
223
+ 1. Fork the repository
224
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
225
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
226
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
227
+ 5. Open a Pull Request
228
+
229
+ ## ๐Ÿ“ž Support
230
+
231
+ For issues and questions:
232
+ - ๐Ÿ› [Report bugs](https://github.com/alternative-path/testlens/issues)
233
+ - ๐Ÿ’ฌ [Discussions](https://github.com/alternative-path/testlens/discussions)
234
+ - ๐Ÿ“ง [Email support](mailto:support@testlens.io)
235
+
236
+ ````
237
+ node build-embed-env.js
238
+ npm pack
package/index.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { Reporter } from '@playwright/test/reporter';
2
+
3
+ export interface TestLensReporterConfig {
4
+ /** TestLens API endpoint URL */
5
+ apiEndpoint?: string;
6
+ /** API key for authentication - required, must be provided in config */
7
+ apiKey: string;
8
+ /** Enable real-time streaming of test events */
9
+ enableRealTimeStream?: boolean;
10
+ /** Enable Git information collection */
11
+ enableGitInfo?: boolean;
12
+ /** Enable artifact processing */
13
+ enableArtifacts?: boolean;
14
+ /** Enable S3 upload for artifacts */
15
+ enableS3Upload?: boolean;
16
+ /** Batch size for API requests */
17
+ batchSize?: number;
18
+ /** Flush interval in milliseconds */
19
+ flushInterval?: number;
20
+ /** Number of retry attempts for failed API calls */
21
+ retryAttempts?: number;
22
+ /** Request timeout in milliseconds */
23
+ timeout?: number;
24
+ /** SSL certificate validation - set to false to disable SSL verification */
25
+ rejectUnauthorized?: boolean;
26
+ /** Alternative SSL option - set to true to ignore SSL certificate errors */
27
+ ignoreSslErrors?: boolean;
28
+ }
29
+
30
+ export interface TestLensReporterOptions {
31
+ /** TestLens API endpoint URL */
32
+ apiEndpoint?: string;
33
+ /** API key for authentication - required, must be provided in config */
34
+ apiKey: string;
35
+ /** Enable real-time streaming of test events */
36
+ enableRealTimeStream?: boolean;
37
+ /** Enable Git information collection */
38
+ enableGitInfo?: boolean;
39
+ /** Enable artifact processing */
40
+ enableArtifacts?: boolean;
41
+ /** Enable S3 upload for artifacts */
42
+ enableS3Upload?: boolean;
43
+ /** Batch size for API requests */
44
+ batchSize?: number;
45
+ /** Flush interval in milliseconds */
46
+ flushInterval?: number;
47
+ /** Number of retry attempts for failed API calls */
48
+ retryAttempts?: number;
49
+ /** Request timeout in milliseconds */
50
+ timeout?: number;
51
+ /** SSL certificate validation - set to false to disable SSL verification */
52
+ rejectUnauthorized?: boolean;
53
+ /** Alternative SSL option - set to true to ignore SSL certificate errors */
54
+ ignoreSslErrors?: boolean;
55
+ }
56
+
57
+ export interface GitInfo {
58
+ branch: string;
59
+ commit: string;
60
+ shortCommit: string;
61
+ author: string;
62
+ commitMessage: string;
63
+ commitTimestamp: string;
64
+ isDirty: boolean;
65
+ remoteName: string;
66
+ remoteUrl: string;
67
+ }
68
+
69
+ export default class TestLensReporter implements Reporter {
70
+ constructor(options: TestLensReporterOptions);
71
+
72
+ onBegin?(config: import('@playwright/test/reporter').FullConfig, suite: import('@playwright/test/reporter').Suite): void;
73
+ onTestBegin?(test: import('@playwright/test/reporter').TestCase, result: import('@playwright/test/reporter').TestResult): void;
74
+ onTestEnd?(test: import('@playwright/test/reporter').TestCase, result: import('@playwright/test/reporter').TestResult): void;
75
+ onEnd?(result: import('@playwright/test/reporter').FullResult): Promise<void>;
76
+ }