Playwright JSON Report Not Generating Fix
In this tutorial, you'll learn about Playwright JSON Report Not Generating Fix. We cover key concepts, practical examples, and best practices.
Your CI pipeline expects JSON test results but Playwright doesn't generate them — or the output file is empty.
The Problem
# WRONG — JSON reporter configured without output file
npx playwright test --reporter=json
# The JSON is printed to stdout, not saved to a file
The JSON reporter outputs to stdout by default. CI tools often expect a file.
Step-by-Step Fix
1. Configure JSON reporter with output file
// RIGHT — playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['json', { outputFile: 'test-results.json' }],
],
});
2. Combine with HTML reporter
// RIGHT — multiple reporters
export default defineConfig({
reporter: [
['html', { open: 'never' }],
['json', { outputFile: 'test-results/results.json' }],
['junit', { outputFile: 'test-results/junit.xml' }],
],
});
3. Use JSON for CI integration
# RIGHT — CI script
npx playwright test --reporter=json > test-results.json
# Or with config
npx playwright test
4. Parse JSON results programmatically
// RIGHT — read and process JSON results
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('test-results.json', 'utf8'));
console.log(`Total: ${results.stats.expected + results.stats.unexpected}`);
console.log(`Passed: ${results.stats.expected}`);
console.log(`Failed: ${results.stats.unexpected}`);
Expected output:
{
"config": { ... },
"suites": [
{
"title": "login flow",
"specs": [
{
"title": "should login successfully",
"ok": true,
"tests": [
{
"status": "expected",
"duration": 1234
}
]
}
]
}
],
"stats": {
"expected": 12,
"unexpected": 0,
"flaky": 0,
"skipped": 0
}
}
Prevention Tips
- Set
outputFilefor the JSON reporter - Use absolute or config-relative paths
- Combine JSON with other reporters for different needs
- Parse JSON results in CI for custom reporting
- Use JUnit reporter for legacy CI integration
Common Mistakes with report json
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world PLAYWRIGHT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro