@@ -16,6 +16,7 @@ This boilerplate includes modern web features:
16
16
- ♿ Accessibility features including prefers-reduced-motion support
17
17
- 🔍 SEO optimized
18
18
- 🧪 End-to-end testing with Playwright
19
+ - 📊 Performance testing and monitoring with baselines
19
20
20
21
## Getting Started
21
22
@@ -32,6 +33,7 @@ This boilerplate includes modern web features:
32
33
- ` npm run test ` - Run Playwright end-to-end tests
33
34
- ` npm run test:ui ` - Run Playwright tests with UI for debugging
34
35
- ` npm run test:update-snapshots ` - Update visual test baselines
36
+ - ` npm run test:update-performance ` - Update performance baselines
35
37
- ` npm run analyze ` - Analyze the site with Lighthouse
36
38
37
39
## Web Components
@@ -110,7 +112,7 @@ The site respects the user's motion preferences:
110
112
111
113
## Testing
112
114
113
- ## Testing Philosophy
115
+ ### Testing Philosophy
114
116
115
117
This boilerplate embraces a practical testing philosophy:
116
118
@@ -128,13 +130,15 @@ The boilerplate uses Playwright for comprehensive end-to-end testing which:
128
130
- Verifies behavior across ** different devices and viewports**
129
131
- Ensures ** accessibility standards** are met
130
132
- Provides ** visual regression testing** to catch unexpected UI changes
133
+ - Monitors ** performance metrics** against established baselines
131
134
132
135
#### Included Test Types
133
136
134
137
- ** Functional tests** : Verify features work as expected
135
138
- ** Visual regression tests** : Catch unintended visual changes
136
139
- ** Accessibility tests** : Ensure the site works for all users
137
140
- ** Mobile responsiveness** : Test behavior on different devices
141
+ - ** Performance tests** : Monitor core web vitals and prevent regressions
138
142
139
143
#### Running Tests
140
144
@@ -148,6 +152,9 @@ npm run test:staging
148
152
# Update visual snapshots after intentional changes
149
153
npm run test:update-snapshots
150
154
155
+ # Update performance baselines after optimizations
156
+ npm run test:update-performance
157
+
151
158
# Debug tests interactively with UI
152
159
npm run test:ui
153
160
@@ -170,14 +177,51 @@ When making design changes, update the visual reference snapshots:
170
177
npm run test:update-snapshots
171
178
```
172
179
173
- #### Writing Effective Tests
180
+ ### Performance Testing
181
+
182
+ This boilerplate includes a comprehensive performance testing system:
183
+
184
+ #### How it works
185
+
186
+ 1 . ** Performance baselines** : Each component and page has baseline metrics saved in the ` /performance ` directory
187
+ 2 . ** Automated testing** : Tests run on each build and compare current performance against baselines
188
+ 3 . ** Threshold alerts** : Tests fail if performance degrades beyond configurable thresholds
189
+ 4 . ** Lighthouse integration** : For index pages, full Lighthouse audits are run and results tracked
190
+
191
+ #### Performance metrics tracked
192
+
193
+ - ** Core Web Vitals** : First Contentful Paint (FCP), Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS)
194
+ - ** Interaction metrics** : Total Blocking Time (TBT), Time to Interactive (TTI)
195
+ - ** Navigation metrics** : Time to First Byte (TTFB), DOM Load, Full Page Load
196
+ - ** Component-level metrics** : Toggle operation time, memory usage, etc.
197
+
198
+ #### Managing performance baselines
199
+
200
+ After intentional performance changes or optimizations, update the baselines:
201
+
202
+ ``` bash
203
+ # Update performance baselines
204
+ npm run test:update-performance
205
+ ```
206
+
207
+ This will run all tests with the baseline update flag and save current metrics as the new baseline.
208
+
209
+ #### Performance test file organization
210
+
211
+ - Performance tests are integrated into component-specific test files
212
+ - Each test file measures specific metrics relevant to that component
213
+ - The utils/performance-utils.js module provides shared testing utilities
214
+ - Baseline metrics are stored in the /performance directory as JSON files
215
+
216
+ ### Writing Effective Tests
174
217
175
218
When adding new features, write Playwright tests that:
176
219
177
220
1 . Focus on ** user journeys** rather than implementation details
178
221
2 . Use ** accessibility-friendly selectors** like ` getByRole ` and ` getByLabel `
179
222
3 . Test across ** multiple browsers and devices**
180
- 4 . Include ** visual regression** tests for UI components
223
+ 4 . Include ** visual regression** and ** performance** tests
224
+ 5 . Verify ** accessibility** requirements are met
181
225
182
226
Example of a good test case:
183
227
@@ -202,6 +246,10 @@ test('user can toggle theme', async ({ page }) => {
202
246
document .documentElement .classList .contains (' dark-mode' ) ? ' dark' : ' light' ,
203
247
);
204
248
expect (newTheme).not .toBe (initialTheme);
249
+
250
+ // Check performance metrics for the operation
251
+ const metrics = await getBrowserPerformanceMetrics (page);
252
+ await assertPerformanceBaseline (' theme-toggle-operation' , metrics);
205
253
});
206
254
```
207
255
@@ -219,15 +267,15 @@ This project uses Playwright's visual comparison testing to ensure UI consistenc
219
267
220
268
### Managing snapshots
221
269
222
- - ** Update snapshots:** After intentional UI changes, run ` npm run test:update-visual `
270
+ - ** Update snapshots:** After intentional UI changes, run ` npm run test:update-snapshots `
223
271
- ** Clean temporary snapshots:** Remove diff and actual files with ` npm run test:clean-snapshots `
224
272
- ** View differences:** Check the Playwright report for side-by-side comparison of visual changes
225
273
226
274
### Snapshot organization
227
275
228
- - Baseline snapshots are stored in ` tests/snapshots/ `
229
- - Each test file has its own subfolder to organize screenshots
276
+ - Baseline snapshots are stored in ` /snapshots/ ` with the naming convention ` *-baseline.png `
230
277
- Only baseline snapshots are committed to git
278
+ - The snapshot directory uses a flat structure for simplicity
231
279
232
280
### Best practices
233
281
0 commit comments