index.js 561 B

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