index.js 531 B

1234567891011121314151617181920212223
  1. /* eslint-env node */
  2. const fs = require('node:fs');
  3. const path = require('node:path');
  4. module.exports = results => {
  5. if (!results.success) {
  6. throw new Error('Balance reporter requires all tests to succeed.');
  7. }
  8. const cwd = process.cwd();
  9. const testValues = {};
  10. for (const test of results.testResults) {
  11. testValues[test.testFilePath.replace(cwd, '')] = test.perfStats.runtime;
  12. }
  13. fs.writeFileSync(
  14. path.resolve(__dirname, 'jest-balance.json'),
  15. JSON.stringify(testValues)
  16. );
  17. return results;
  18. };