parse-results.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const fs = require('fs');
  2. const r = JSON.parse(fs.readFileSync('./test-results/results.json', 'utf8'));
  3. const stats = { passed: 0, failed: 0, skipped: 0, timedOut: 0, interrupted: 0, total: 0, other: 0 };
  4. const failedTests = [];
  5. const allTests = [];
  6. function walk(suite, parentFile) {
  7. const file = suite.file || parentFile;
  8. for (const sub of (suite.suites || [])) walk(sub, file);
  9. for (const spec of (suite.specs || [])) {
  10. for (const t of (spec.tests || [])) {
  11. stats.total++;
  12. const r0 = t.results && t.results[0];
  13. const realStatus = r0 ? r0.status : t.status;
  14. if (realStatus === 'passed') stats.passed++;
  15. else if (realStatus === 'skipped') stats.skipped++;
  16. else if (realStatus === 'timedOut') stats.timedOut++;
  17. else if (realStatus === 'failed') {
  18. stats.failed++;
  19. failedTests.push({
  20. file: file ? file.replace(/\\/g, '/').split('/tests/').pop() : '',
  21. title: spec.title,
  22. status: realStatus,
  23. error: r0 && r0.error ? (r0.error.message || '').split('\n')[0].slice(0, 200) : ''
  24. });
  25. } else if (realStatus === 'interrupted') stats.interrupted++;
  26. else stats.other++;
  27. allTests.push({
  28. file: file ? file.replace(/\\/g, '/').split('/tests/').pop() : '',
  29. title: spec.title,
  30. status: realStatus
  31. });
  32. }
  33. }
  34. }
  35. for (const s of (r.suites || [])) walk(s, '');
  36. console.log('SUMMARY:');
  37. console.log(JSON.stringify(stats, null, 2));
  38. console.log('\nFAILED TESTS:');
  39. console.log(JSON.stringify(failedTests, null, 2));
  40. console.log('\nALL TESTS BY STATUS:');
  41. const byStatus = {};
  42. for (const t of allTests) {
  43. byStatus[t.status] = (byStatus[t.status] || 0) + 1;
  44. }
  45. console.log(JSON.stringify(byStatus, null, 2));