53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// Fix type: "module" issue by using readFileSync if running as module or just basic node
|
|
// but easier to just use standard require if not module, or import fs if module.
|
|
// Package.json says type: module, so imports are fine.
|
|
|
|
try {
|
|
const errorData = JSON.parse(fs.readFileSync('storybook_errors.json', 'utf8'));
|
|
const totalFailed = Object.keys(errorData).length;
|
|
|
|
const stats = {
|
|
totalFailed,
|
|
byType: {},
|
|
commonMessages: {}
|
|
};
|
|
|
|
for (const [storyId, errors] of Object.entries(errorData)) {
|
|
for (const error of errors) {
|
|
let type = 'Unknown';
|
|
if (error.startsWith('Console:')) type = 'Console';
|
|
if (error.startsWith('PageError:')) type = 'PageError';
|
|
if (error.startsWith('NetworkFail:')) type = 'NetworkFail';
|
|
if (error.startsWith('Navigation:')) type = 'Navigation';
|
|
|
|
stats.byType[type] = (stats.byType[type] || 0) + 1;
|
|
|
|
// Extract core message for grouping
|
|
const message = error.substring(error.indexOf(':') + 1).trim();
|
|
// Truncate simple variable parts
|
|
const cleanMessage = message.split(' at ')[0].substring(0, 100);
|
|
stats.commonMessages[cleanMessage] = (stats.commonMessages[cleanMessage] || 0) + 1;
|
|
}
|
|
}
|
|
|
|
console.log('--- Error Summary ---');
|
|
console.log(`Total Stories with Errors: ${stats.totalFailed}`);
|
|
console.log('\nErrors by Type:');
|
|
console.table(stats.byType);
|
|
|
|
console.log('\nTop 10 Common Error Messages:');
|
|
const sortedMessages = Object.entries(stats.commonMessages)
|
|
.sort((a, b) => b[1] - a[1])
|
|
.slice(0, 10);
|
|
|
|
sortedMessages.forEach(([msg, count]) => {
|
|
console.log(`${count}x: ${msg}`);
|
|
});
|
|
|
|
} catch (e) {
|
|
console.error('Failed to parse errors:', e);
|
|
}
|