index.js 836 B

12345678910111213141516171819202122232425262728293031323334
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0 */
  3. const fs = require('fs').promises;
  4. class TestBalancer {
  5. constructor(globalConfig, options) {
  6. this._globalConfig = globalConfig;
  7. this._options = options;
  8. this.results = new Map();
  9. }
  10. onTestFileResult(test) {
  11. const path = test.path.replace(this._globalConfig.rootDir, '');
  12. this.results.set(path, test.duration);
  13. }
  14. onRunComplete(_contexts, results) {
  15. // results.success always returns false for me?
  16. if (
  17. results.numTotalTests === 0 ||
  18. results.numFailedTests > 0 ||
  19. !this._options.enabled ||
  20. !this._options.resultsPath
  21. ) {
  22. return;
  23. }
  24. const data = JSON.stringify(Object.fromEntries(this.results), null, 2);
  25. fs.writeFile(this._options.resultsPath, data);
  26. }
  27. }
  28. module.exports = TestBalancer;