@alternative-path/testlens-playwright-reporter 0.3.7
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 +21 -0
- package/README.md +163 -0
- package/cross-env.js +24 -0
- package/index.d.ts +192 -0
- package/index.js +1126 -0
- package/index.ts +1407 -0
- package/package.json +82 -0
- package/postinstall.js +39 -0
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,163 @@
|
|
|
1
|
+
# TestLens Playwright Reporter
|
|
2
|
+
|
|
3
|
+
A Playwright reporter for [TestLens](https://testlens.qa-path.com) - real-time test monitoring dashboard.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Real-time streaming** - Watch test results as they happen in the dashboard
|
|
8
|
+
- 📸 **Artifact support** - Shows screenshots, videos, and traces
|
|
9
|
+
- 🔄 **Retry tracking** - Monitor test retries and identify flaky tests
|
|
10
|
+
- âš¡ **Cross-platform** - Works on Windows, macOS, and Linux
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install testlens-playwright-reporter
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
### Quick Start (Recommended)
|
|
21
|
+
|
|
22
|
+
The simplest config - API key and metadata are passed via environment variables:
|
|
23
|
+
|
|
24
|
+
**TypeScript (`playwright.config.ts`)**
|
|
25
|
+
```typescript
|
|
26
|
+
import { defineConfig } from '@playwright/test';
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
use: {
|
|
30
|
+
screenshot: 'on',
|
|
31
|
+
video: 'on',
|
|
32
|
+
trace: 'on',
|
|
33
|
+
},
|
|
34
|
+
reporter: [
|
|
35
|
+
['testlens-playwright-reporter']
|
|
36
|
+
// API key is auto-detected from TESTLENS_API_KEY env var
|
|
37
|
+
// Build metadata is auto-detected from testlensBuildName/testlensBuildTag env vars
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**JavaScript (`playwright.config.js`)**
|
|
43
|
+
```javascript
|
|
44
|
+
const { defineConfig } = require('@playwright/test');
|
|
45
|
+
|
|
46
|
+
module.exports = defineConfig({
|
|
47
|
+
use: {
|
|
48
|
+
screenshot: 'on',
|
|
49
|
+
video: 'on',
|
|
50
|
+
trace: 'on',
|
|
51
|
+
},
|
|
52
|
+
reporter: [
|
|
53
|
+
['testlens-playwright-reporter']
|
|
54
|
+
// API key is auto-detected from TESTLENS_API_KEY env var
|
|
55
|
+
// Build metadata is auto-detected from testlensBuildName/testlensBuildTag env vars
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Advanced Configuration (Optional)
|
|
61
|
+
|
|
62
|
+
If you prefer to set API key or metadata explicitly in config:
|
|
63
|
+
|
|
64
|
+
**TypeScript (`playwright.config.ts`)**
|
|
65
|
+
```typescript
|
|
66
|
+
import { defineConfig } from '@playwright/test';
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
use: {
|
|
70
|
+
screenshot: 'on',
|
|
71
|
+
video: 'on',
|
|
72
|
+
trace: 'on',
|
|
73
|
+
},
|
|
74
|
+
reporter: [
|
|
75
|
+
['testlens-playwright-reporter', {
|
|
76
|
+
apiKey: process.env.TESTLENS_API_KEY || 'your-api-key-here',
|
|
77
|
+
|
|
78
|
+
// Optional: explicitly forward build metadata from env vars
|
|
79
|
+
customMetadata: {
|
|
80
|
+
testlensBuildName: process.env.testlensBuildName,
|
|
81
|
+
testlensBuildTag: process.env.testlensBuildTag,
|
|
82
|
+
},
|
|
83
|
+
}]
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**JavaScript (`playwright.config.js`)**
|
|
89
|
+
```javascript
|
|
90
|
+
const { defineConfig } = require('@playwright/test');
|
|
91
|
+
|
|
92
|
+
module.exports = defineConfig({
|
|
93
|
+
use: {
|
|
94
|
+
screenshot: 'on',
|
|
95
|
+
video: 'on',
|
|
96
|
+
trace: 'on',
|
|
97
|
+
},
|
|
98
|
+
reporter: [
|
|
99
|
+
['testlens-playwright-reporter', {
|
|
100
|
+
apiKey: process.env.TESTLENS_API_KEY || 'your-api-key-here',
|
|
101
|
+
|
|
102
|
+
// Optional: explicitly forward build metadata from env vars
|
|
103
|
+
customMetadata: {
|
|
104
|
+
testlensBuildName: process.env.testlensBuildName,
|
|
105
|
+
testlensBuildTag: process.env.testlensBuildTag,
|
|
106
|
+
},
|
|
107
|
+
}]
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Run With Build Name & Tag (UI Mode)
|
|
113
|
+
|
|
114
|
+
Use `testlens-cross-env` (bundled with this package) to set API key and metadata cross-platform, including Windows.
|
|
115
|
+
|
|
116
|
+
### Command
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx testlens-cross-env TESTLENS_API_KEY="<your-api-key>" testlensBuildName="Testing Build Local Environment" testlensBuildTag="smoke" playwright test --ui
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### What Gets Auto-Detected
|
|
123
|
+
|
|
124
|
+
The reporter automatically reads these environment variables (no config changes needed):
|
|
125
|
+
|
|
126
|
+
- **API Key**: `TESTLENS_API_KEY` (also checks: `testlens_api_key`, `TESTLENS_KEY`, `testlensApiKey`, `PLAYWRIGHT_API_KEY`, `PW_API_KEY`)
|
|
127
|
+
- **Build Name**: `testlensBuildName` (also checks: `TESTLENS_BUILD_NAME`, `BUILDNAME`, `BUILD_NAME`)
|
|
128
|
+
- **Build Tag**: `testlensBuildTag` (also checks: `TESTLENS_BUILD_TAG`, `BUILDTAG`, `BUILD_TAG`)
|
|
129
|
+
|
|
130
|
+
### Notes
|
|
131
|
+
|
|
132
|
+
- No config changes required - just pass env vars in the command
|
|
133
|
+
- `testlensBuildName` and `testlensBuildTag` are sent to TestLens as run `custom_metadata`
|
|
134
|
+
- Multiple tags: use comma-separated list `testlensBuildTag="smoke,regression"`
|
|
135
|
+
|
|
136
|
+
> 💡 **Tip:** Keep `screenshot`, `video`, and `trace` set to `'on'` for better debugging experience. TestLens automatically uploads these artifacts for failed tests, making it easier to identify issues.
|
|
137
|
+
|
|
138
|
+
### Configuration Options
|
|
139
|
+
|
|
140
|
+
| Option | Type | Default | Description |
|
|
141
|
+
|--------|------|---------|-------------|
|
|
142
|
+
| `apiKey` | `string` | **Required** | Your TestLens API key |
|
|
143
|
+
|
|
144
|
+
## Artifacts
|
|
145
|
+
|
|
146
|
+
TestLens automatically captures and uploads:
|
|
147
|
+
|
|
148
|
+
| Artifact | Description |
|
|
149
|
+
|----------|-------------|
|
|
150
|
+
| **Screenshots** | Visual snapshots of test failures |
|
|
151
|
+
| **Videos** | Full video recording of test execution |
|
|
152
|
+
| **Traces** | Playwright trace files for step-by-step debugging |
|
|
153
|
+
|
|
154
|
+
These artifacts are viewable directly in the TestLens dashboard for easy debugging.
|
|
155
|
+
|
|
156
|
+
## Requirements
|
|
157
|
+
|
|
158
|
+
- Node.js >= 16.0.0
|
|
159
|
+
- Playwright >= 1.40.0
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT License
|
package/cross-env.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Cross-platform wrapper for cross-env
|
|
4
|
+
*
|
|
5
|
+
* This wrapper allows users to set environment variables in a cross-platform way
|
|
6
|
+
* without needing to install cross-env separately.
|
|
7
|
+
*
|
|
8
|
+
* Platform Support:
|
|
9
|
+
* - Windows (PowerShell, CMD)
|
|
10
|
+
* - macOS (bash, zsh, etc.)
|
|
11
|
+
* - Linux (bash, sh, etc.)
|
|
12
|
+
* - Any platform that runs Node.js
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* npx testlens-cross-env VAR1=value1 VAR2=value2 command args...
|
|
16
|
+
*
|
|
17
|
+
* Example:
|
|
18
|
+
* npx testlens-cross-env testlensApiKey="abc123" playwright test
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const crossEnv = require('cross-env');
|
|
22
|
+
|
|
23
|
+
// Pass all command-line arguments to cross-env
|
|
24
|
+
crossEnv(process.argv.slice(2));
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Reporter, TestCase, TestResult, FullConfig, Suite } from '@playwright/test/reporter';
|
|
2
|
+
export interface TestLensReporterConfig {
|
|
3
|
+
/** TestLens API endpoint URL */
|
|
4
|
+
apiEndpoint?: string;
|
|
5
|
+
/** API key for authentication - can be provided in config or via TESTLENS_API_KEY environment variable */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/** Enable real-time streaming of test events */
|
|
8
|
+
enableRealTimeStream?: boolean;
|
|
9
|
+
/** Enable Git information collection */
|
|
10
|
+
enableGitInfo?: boolean;
|
|
11
|
+
/** Enable artifact processing */
|
|
12
|
+
enableArtifacts?: boolean;
|
|
13
|
+
/** Enable video capture - defaults to true */
|
|
14
|
+
enableVideo?: boolean;
|
|
15
|
+
/** Enable screenshot capture - defaults to true */
|
|
16
|
+
enableScreenshot?: boolean;
|
|
17
|
+
/** Batch size for API requests */
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
/** Flush interval in milliseconds */
|
|
20
|
+
flushInterval?: number;
|
|
21
|
+
/** Number of retry attempts for failed API calls */
|
|
22
|
+
retryAttempts?: number;
|
|
23
|
+
/** Request timeout in milliseconds */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/** SSL certificate validation - set to false to disable SSL verification */
|
|
26
|
+
rejectUnauthorized?: boolean;
|
|
27
|
+
/** Alternative SSL option - set to true to ignore SSL certificate errors */
|
|
28
|
+
ignoreSslErrors?: boolean;
|
|
29
|
+
/** Custom metadata from CLI arguments (automatically parsed from --key=value arguments) */
|
|
30
|
+
customMetadata?: Record<string, string | string[]>;
|
|
31
|
+
}
|
|
32
|
+
export interface TestLensReporterOptions {
|
|
33
|
+
/** TestLens API endpoint URL */
|
|
34
|
+
apiEndpoint?: string;
|
|
35
|
+
/** API key for authentication - can be provided in config or via TESTLENS_API_KEY environment variable */
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
/** Enable real-time streaming of test events */
|
|
38
|
+
enableRealTimeStream?: boolean;
|
|
39
|
+
/** Enable Git information collection */
|
|
40
|
+
enableGitInfo?: boolean;
|
|
41
|
+
/** Enable artifact processing */
|
|
42
|
+
enableArtifacts?: boolean;
|
|
43
|
+
/** Enable video capture - defaults to true */
|
|
44
|
+
enableVideo?: boolean;
|
|
45
|
+
/** Enable screenshot capture - defaults to true */
|
|
46
|
+
enableScreenshot?: boolean;
|
|
47
|
+
/** Batch size for API requests */
|
|
48
|
+
batchSize?: number;
|
|
49
|
+
/** Flush interval in milliseconds */
|
|
50
|
+
flushInterval?: number;
|
|
51
|
+
/** Number of retry attempts for failed API calls */
|
|
52
|
+
retryAttempts?: number;
|
|
53
|
+
/** Request timeout in milliseconds */
|
|
54
|
+
timeout?: number;
|
|
55
|
+
/** SSL certificate validation - set to false to disable SSL verification */
|
|
56
|
+
rejectUnauthorized?: boolean;
|
|
57
|
+
/** Alternative SSL option - set to true to ignore SSL certificate errors */
|
|
58
|
+
ignoreSslErrors?: boolean;
|
|
59
|
+
/** Custom metadata from CLI arguments (automatically parsed from --key=value arguments) */
|
|
60
|
+
customMetadata?: Record<string, string | string[]>;
|
|
61
|
+
}
|
|
62
|
+
export interface GitInfo {
|
|
63
|
+
branch: string;
|
|
64
|
+
commit: string;
|
|
65
|
+
shortCommit: string;
|
|
66
|
+
author: string;
|
|
67
|
+
message: string;
|
|
68
|
+
timestamp: string;
|
|
69
|
+
isDirty: boolean;
|
|
70
|
+
remoteName: string;
|
|
71
|
+
remoteUrl: string;
|
|
72
|
+
}
|
|
73
|
+
export interface CodeBlock {
|
|
74
|
+
type: 'test' | 'describe';
|
|
75
|
+
name: string;
|
|
76
|
+
content: string;
|
|
77
|
+
summary?: string;
|
|
78
|
+
describe?: string;
|
|
79
|
+
startLine?: number;
|
|
80
|
+
endLine?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface RunMetadata {
|
|
83
|
+
id: string;
|
|
84
|
+
startTime: string;
|
|
85
|
+
endTime?: string;
|
|
86
|
+
duration?: number;
|
|
87
|
+
environment: string;
|
|
88
|
+
browser: string;
|
|
89
|
+
os: string;
|
|
90
|
+
playwrightVersion: string;
|
|
91
|
+
nodeVersion: string;
|
|
92
|
+
gitInfo?: GitInfo | null;
|
|
93
|
+
shardInfo?: {
|
|
94
|
+
current: number;
|
|
95
|
+
total: number;
|
|
96
|
+
};
|
|
97
|
+
totalTests?: number;
|
|
98
|
+
passedTests?: number;
|
|
99
|
+
failedTests?: number;
|
|
100
|
+
skippedTests?: number;
|
|
101
|
+
status?: string;
|
|
102
|
+
testlensBuildName?: string;
|
|
103
|
+
customMetadata?: Record<string, string | string[]>;
|
|
104
|
+
}
|
|
105
|
+
export interface TestError {
|
|
106
|
+
message: string;
|
|
107
|
+
stack?: string;
|
|
108
|
+
location?: {
|
|
109
|
+
file: string;
|
|
110
|
+
line: number;
|
|
111
|
+
column: number;
|
|
112
|
+
};
|
|
113
|
+
snippet?: string;
|
|
114
|
+
expected?: string;
|
|
115
|
+
actual?: string;
|
|
116
|
+
diff?: string;
|
|
117
|
+
matcherName?: string;
|
|
118
|
+
timeout?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface TestData {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
status: string;
|
|
124
|
+
originalStatus?: string;
|
|
125
|
+
duration: number;
|
|
126
|
+
startTime: string;
|
|
127
|
+
endTime: string;
|
|
128
|
+
errorMessages: string[];
|
|
129
|
+
errors?: TestError[];
|
|
130
|
+
retryAttempts: number;
|
|
131
|
+
currentRetry: number;
|
|
132
|
+
annotations: Array<{
|
|
133
|
+
type: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
}>;
|
|
136
|
+
projectName: string;
|
|
137
|
+
workerIndex?: number;
|
|
138
|
+
parallelIndex?: number;
|
|
139
|
+
location?: {
|
|
140
|
+
file: string;
|
|
141
|
+
line: number;
|
|
142
|
+
column: number;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export interface SpecData {
|
|
146
|
+
filePath: string;
|
|
147
|
+
testSuiteName: string;
|
|
148
|
+
tags?: string[];
|
|
149
|
+
startTime: string;
|
|
150
|
+
endTime?: string;
|
|
151
|
+
status: string;
|
|
152
|
+
}
|
|
153
|
+
export declare class TestLensReporter implements Reporter {
|
|
154
|
+
private config;
|
|
155
|
+
private axiosInstance;
|
|
156
|
+
private runId;
|
|
157
|
+
private runMetadata;
|
|
158
|
+
private specMap;
|
|
159
|
+
private testMap;
|
|
160
|
+
private runCreationFailed;
|
|
161
|
+
private cliArgs;
|
|
162
|
+
/**
|
|
163
|
+
* Parse custom metadata from environment variables
|
|
164
|
+
* Checks for common metadata environment variables
|
|
165
|
+
*/
|
|
166
|
+
private static parseCustomArgs;
|
|
167
|
+
constructor(options: TestLensReporterOptions);
|
|
168
|
+
private initializeRunMetadata;
|
|
169
|
+
private getPlaywrightVersion;
|
|
170
|
+
private normalizeTestStatus;
|
|
171
|
+
private normalizeRunStatus;
|
|
172
|
+
onBegin(config: FullConfig, suite: Suite): Promise<void>;
|
|
173
|
+
onTestBegin(test: TestCase, result: TestResult): Promise<void>;
|
|
174
|
+
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
175
|
+
onEnd(result: {
|
|
176
|
+
status: string;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
private sendToApi;
|
|
179
|
+
private processArtifacts;
|
|
180
|
+
private sendSpecCodeBlocks;
|
|
181
|
+
private extractTestBlocks;
|
|
182
|
+
private collectGitInfo;
|
|
183
|
+
private getArtifactType;
|
|
184
|
+
private extractTags;
|
|
185
|
+
private getTestId;
|
|
186
|
+
private uploadArtifactToS3;
|
|
187
|
+
private getContentType;
|
|
188
|
+
private generateS3Key;
|
|
189
|
+
private sanitizeForS3;
|
|
190
|
+
private getFileSize;
|
|
191
|
+
}
|
|
192
|
+
export default TestLensReporter;
|