run.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. const childProcess = require('child_process');
  3. const path = require('path');
  4. const fs = require('fs');
  5. const Promise = require('bluebird');
  6. const arrify = require('arrify');
  7. const makeDir = require('make-dir');
  8. const branch = require('git-branch').sync(path.join(__dirname, '..'));
  9. const cliPath = require.resolve('../cli');
  10. function runTests(_args) {
  11. return new Promise(resolve => {
  12. const args = [cliPath].concat(arrify(_args));
  13. const start = Date.now();
  14. childProcess.execFile(process.execPath, args, {
  15. cwd: __dirname,
  16. maxBuffer: 100000 * 200
  17. }, (err, stdout, stderr) => {
  18. const end = Date.now();
  19. resolve({
  20. args: arrify(_args),
  21. time: end - start,
  22. err,
  23. stdout,
  24. stderr
  25. });
  26. });
  27. });
  28. }
  29. let list;
  30. if (process.argv.length === 2) {
  31. list = [
  32. {
  33. args: 'other/failures.js',
  34. shouldFail: true
  35. },
  36. 'serial/alternating-sync-async.js',
  37. 'serial/async-immediate.js',
  38. 'serial/async-timeout.js',
  39. 'serial/sync.js',
  40. 'concurrent/alternating-sync-async.js',
  41. 'concurrent/async-immediate.js',
  42. 'concurrent/async-timeout.js',
  43. 'concurrent/sync.js',
  44. ['concurrent/*.js', 'serial/*.js']
  45. ].map(definition => {
  46. if (Array.isArray(definition) || typeof definition === 'string') {
  47. definition = {
  48. shouldFail: false,
  49. args: definition
  50. };
  51. }
  52. return definition;
  53. });
  54. } else {
  55. list = [];
  56. let currentArgs = [];
  57. let shouldFail = false;
  58. for (const arg of process.argv.slice(2)) {
  59. if (arg === '--') {
  60. list.push({
  61. args: currentArgs,
  62. shouldFail
  63. });
  64. currentArgs = [];
  65. shouldFail = false;
  66. continue;
  67. }
  68. if (arg === '--should-fail') {
  69. shouldFail = true;
  70. continue;
  71. }
  72. currentArgs.push(arg);
  73. }
  74. if (currentArgs.length > 0) {
  75. list.push({
  76. args: currentArgs,
  77. shouldFail
  78. });
  79. }
  80. }
  81. for (const definition of list) {
  82. definition.args = ['--verbose'].concat(definition.args);
  83. }
  84. let combined = [];
  85. for (let i = 0; i < 11; i++) {
  86. combined = combined.concat(list);
  87. }
  88. const results = {};
  89. Promise.each(combined, definition => {
  90. const args = definition.args;
  91. return runTests(args).then(result => {
  92. const key = result.args.join(' ');
  93. const passedOrFaild = result.err ? 'failed' : 'passed';
  94. const seconds = result.time / 1000;
  95. console.log('%s %s in %d seconds', key, passedOrFaild, seconds);
  96. if (result.err && !definition.shouldFail) {
  97. console.log(result.stdout);
  98. console.log(result.stderr);
  99. throw result.err;
  100. }
  101. results[key] = results[key] || [];
  102. results[key].push({
  103. passed: !results.err,
  104. shouldFail: definition.shouldFail,
  105. time: seconds
  106. });
  107. });
  108. }).then(() => {
  109. makeDir.sync(path.join(__dirname, '.results'));
  110. results['.time'] = Date.now();
  111. fs.writeFileSync(
  112. path.join(__dirname, '.results', `${branch}.json`),
  113. JSON.stringify(results, null, 4)
  114. );
  115. });