index.js 971 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const { readdirSync } = require('fs');
  3. const { spawnSync } = require('child_process');
  4. const path = require('path');
  5. let benchmarks = [];
  6. if (!!process.env.npm_config_benchmarks) {
  7. benchmarks = process.env.npm_config_benchmarks
  8. .split(';')
  9. .map((item) => (item + '.js'));
  10. }
  11. // Run each file in this directory or the list given on the command line except
  12. // index.js as a Node.js process.
  13. (benchmarks.length > 0 ? benchmarks : readdirSync(__dirname))
  14. .filter((item) => (item !== 'index.js' && item.match(/\.js$/)))
  15. .map((item) => path.join(__dirname, item))
  16. .forEach((item) => {
  17. const child = spawnSync(process.execPath, [
  18. '--expose-gc',
  19. item
  20. ], { stdio: 'inherit' });
  21. if (child.signal) {
  22. console.error(`Tests aborted with ${child.signal}`);
  23. process.exitCode = 1;
  24. } else {
  25. process.exitCode = child.status;
  26. }
  27. if (child.status !== 0) {
  28. process.exit(process.exitCode);
  29. }
  30. });