Skip to content

Commit 2672921

Browse files
feat: initial commit
0 parents  commit 2672921

22 files changed

+3822
-0
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: ci
2+
on: push
3+
permissions:
4+
contents: write
5+
jobs:
6+
check-and-test:
7+
runs-on: ubuntu-24.04
8+
steps:
9+
- name: Checkout 🛎
10+
uses: actions/checkout@v4
11+
12+
- name: Install everything 📦
13+
run: npm ci
14+
15+
- name: Format and lint code ☑️
16+
run: npm run prepublishOnly
17+
18+
- name: Run Playwright tests 🧪
19+
run: npm run test
20+
21+
release:
22+
needs: [check-and-test]
23+
runs-on: ubuntu-24.04
24+
if: github.ref == 'refs/heads/main'
25+
steps:
26+
- name: Checkout 🛎
27+
uses: actions/checkout@v4
28+
29+
- name: Semantic Release 🚀
30+
uses: cycjimmy/semantic-release-action@v4
31+
with:
32+
branch: main
33+
tag_format: v${version}
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.env
3+
test-results
4+
.hooks

.npmignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
src
2+
tests
3+
.gitignore
4+
eslint.config.js
5+
.prettierignore
6+
.prettier.json
7+
tsconfig.json
8+
*.log
9+
test-results
10+
.hooks
11+
playwright.config.js

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
report
3+
allure-report
4+
allure-results
5+
postman_collections
6+
playwright-report
7+
package-lock.json
8+
Readme.md

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"useTabs": false,
5+
"tabWidth": 2,
6+
"bracketSpacing": true,
7+
"arrowParens": "avoid",
8+
"trailingComma": "none",
9+
"printWidth": 200,
10+
"endOfLine": "lf"
11+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Valentin Lutchanka
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.

Readme.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Playwright Performance Metrics
2+
3+
A comprehensive performance metrics collector for Playwright tests. Collect and analyze web vital metrics, network timing, and resource usage in your Playwright tests.
4+
5+
## Features
6+
7+
- Collect Web Vitals (LCP, FID, CLS)
8+
- Network timing metrics (TTFB, resource timing)
9+
- Network condition emulation (3G, 4G, WiFi)
10+
- Resource usage tracking
11+
- TypeScript support
12+
- Easy integration with Playwright tests
13+
14+
## Installation
15+
16+
```bash
17+
npm install -D playwright-performance-metrics
18+
```
19+
20+
## Usage
21+
22+
Basic usage:
23+
24+
```typescript
25+
import { test } from '@playwright/test';
26+
import { PerformanceMetricsCollector } from 'playwright-performance-metrics';
27+
28+
test('measure page performance', async ({ page }) => {
29+
const collector = new PerformanceMetricsCollector(page);
30+
31+
await page.goto('https://example.com');
32+
33+
const metrics = await collector.collectMetrics({
34+
timeout: 10000,
35+
initialDelay: 1000
36+
});
37+
38+
console.log('Performance metrics:', {
39+
'First Paint': metrics.paint?.firstPaint,
40+
'First Contentful Paint': metrics.paint?.firstContentfulPaint,
41+
'Largest Contentful Paint': metrics.largestContentfulPaint,
42+
'Cumulative Layout Shift': metrics.cumulativeLayoutShift
43+
});
44+
});
45+
```
46+
47+
With network emulation:
48+
49+
```typescript
50+
import { DefaultNetworkPresets } from 'playwright-performance-metrics';
51+
52+
test('measure performance with slow 3G', async ({ page }) => {
53+
const collector = new PerformanceMetricsCollector(page);
54+
55+
const metrics = await collector.collectMetrics({
56+
networkConditions: DefaultNetworkPresets.SLOW_3G,
57+
timeout: 30000
58+
});
59+
60+
console.log('Slow 3G metrics:', metrics);
61+
});
62+
```
63+
64+
## API Reference
65+
66+
### PerformanceMetricsCollector
67+
68+
Main class for collecting performance metrics.
69+
70+
#### Constructor
71+
72+
```typescript
73+
constructor(page: Page)
74+
```
75+
76+
#### Methods
77+
78+
##### collectMetrics(options?: PerformanceOptions): Promise<PerformanceMetrics>
79+
80+
Collects performance metrics from the page.
81+
82+
Options:
83+
- `startMark`: Performance mark to use as start time
84+
- `endMark`: Performance mark to use as end time
85+
- `timeout`: Collection timeout in milliseconds
86+
- `initialDelay`: Initial delay before starting collection
87+
- `retryTimeout`: Maximum time to retry collecting metrics
88+
- `networkConditions`: Network conditions to emulate
89+
90+
### Network Presets
91+
92+
Available network presets:
93+
- `REGULAR_4G`
94+
- `SLOW_3G`
95+
- `FAST_WIFI`
96+
97+
## Contributing
98+
99+
Contributions are welcome! Please feel free to submit a Pull Request.
100+
101+
## License
102+
103+
MIT License - see LICENSE file for details

dist/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { PerformanceMetricsCollector, DefaultNetworkPresets } from './performance-metrics'
2+
export * from './types'

dist/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
var __createBinding =
3+
(this && this.__createBinding) ||
4+
(Object.create
5+
? function (o, m, k, k2) {
6+
if (k2 === undefined) k2 = k
7+
var desc = Object.getOwnPropertyDescriptor(m, k)
8+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9+
desc = {
10+
enumerable: true,
11+
get: function () {
12+
return m[k]
13+
}
14+
}
15+
}
16+
Object.defineProperty(o, k2, desc)
17+
}
18+
: function (o, m, k, k2) {
19+
if (k2 === undefined) k2 = k
20+
o[k2] = m[k]
21+
})
22+
var __exportStar =
23+
(this && this.__exportStar) ||
24+
function (m, exports) {
25+
for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
26+
}
27+
Object.defineProperty(exports, '__esModule', { value: true })
28+
exports.DefaultNetworkPresets = exports.PerformanceMetricsCollector = void 0
29+
var performance_metrics_1 = require('./performance-metrics')
30+
Object.defineProperty(exports, 'PerformanceMetricsCollector', {
31+
enumerable: true,
32+
get: function () {
33+
return performance_metrics_1.PerformanceMetricsCollector
34+
}
35+
})
36+
Object.defineProperty(exports, 'DefaultNetworkPresets', {
37+
enumerable: true,
38+
get: function () {
39+
return performance_metrics_1.DefaultNetworkPresets
40+
}
41+
})
42+
__exportStar(require('./types'), exports)

dist/performance-metrics.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Page } from '@playwright/test'
2+
import { IPerformanceMetricsCollector, NetworkConditions, NetworkPresets, PerformanceMetrics, PerformanceOptions } from './types'
3+
/**
4+
* Default network condition presets for performance testing
5+
*/
6+
export declare const DefaultNetworkPresets: NetworkPresets
7+
/**
8+
* Collector for gathering web performance metrics using Playwright.
9+
*/
10+
export declare class PerformanceMetricsCollector implements IPerformanceMetricsCollector {
11+
private page
12+
private cdpSession
13+
/**
14+
* Create a new PerformanceMetricsCollector.
15+
* @param page - Playwright Page instance to collect metrics from.
16+
*/
17+
constructor(page: Page)
18+
/**
19+
* Initialize the collector with optional network conditions.
20+
* @param networkConditions - Network conditions to emulate.
21+
* @throws Error if CDP session creation fails.
22+
*/
23+
initialize(networkConditions?: NetworkConditions): Promise<void>
24+
/**
25+
* Clean up collector resources.
26+
*/
27+
cleanup(): Promise<void>
28+
/**
29+
* Collect performance metrics from the page.
30+
* @param options - Options for metric collection.
31+
* @returns Collected performance metrics.
32+
*/
33+
collectMetrics(options?: PerformanceOptions): Promise<PerformanceMetrics>
34+
/**
35+
* Validate collected metrics to ensure completeness.
36+
* @param results - Collected performance metrics.
37+
* @returns True if metrics are valid, otherwise false.
38+
*/
39+
private hasValidMetrics
40+
}

0 commit comments

Comments
 (0)