mocha 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env node
  2. 'use strict';
  3. /**
  4. * This tiny wrapper file checks for known node flags and appends them
  5. * when found, before invoking the "real" _mocha(1) executable.
  6. */
  7. const spawn = require('child_process').spawn;
  8. const path = require('path');
  9. const getOptions = require('./options');
  10. const args = [path.join(__dirname, '_mocha')];
  11. // Load mocha.opts into process.argv
  12. // Must be loaded here to handle node-specific options
  13. getOptions();
  14. process.argv.slice(2).forEach(arg => {
  15. const flag = arg.split('=')[0];
  16. switch (flag) {
  17. case '-d':
  18. args.unshift('--debug');
  19. args.push('--no-timeouts');
  20. break;
  21. case 'debug':
  22. case '--debug':
  23. case '--debug-brk':
  24. case '--inspect':
  25. case '--inspect-brk':
  26. args.unshift(arg);
  27. args.push('--no-timeouts');
  28. break;
  29. case '-gc':
  30. case '--expose-gc':
  31. args.unshift('--expose-gc');
  32. break;
  33. case '--gc-global':
  34. case '--es_staging':
  35. case '--no-deprecation':
  36. case '--no-warnings':
  37. case '--prof':
  38. case '--log-timer-events':
  39. case '--throw-deprecation':
  40. case '--trace-deprecation':
  41. case '--trace-warnings':
  42. case '--use_strict':
  43. case '--allow-natives-syntax':
  44. case '--perf-basic-prof':
  45. case '--napi-modules':
  46. args.unshift(arg);
  47. break;
  48. default:
  49. if (arg.indexOf('--harmony') === 0) {
  50. args.unshift(arg);
  51. } else if (arg.indexOf('--trace') === 0) {
  52. args.unshift(arg);
  53. } else if (arg.indexOf('--icu-data-dir') === 0) {
  54. args.unshift(arg);
  55. } else if (arg.indexOf('--max-old-space-size') === 0) {
  56. args.unshift(arg);
  57. } else if (arg.indexOf('--preserve-symlinks') === 0) {
  58. args.unshift(arg);
  59. } else {
  60. args.push(arg);
  61. }
  62. break;
  63. }
  64. });
  65. const proc = spawn(process.execPath, args, {
  66. stdio: 'inherit'
  67. });
  68. proc.on('exit', (code, signal) => {
  69. process.on('exit', () => {
  70. if (signal) {
  71. process.kill(process.pid, signal);
  72. } else {
  73. process.exit(code);
  74. }
  75. });
  76. });
  77. // terminate children.
  78. process.on('SIGINT', () => {
  79. proc.kill('SIGINT'); // calls runner.abort()
  80. proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
  81. });