mocha 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. var spawn = require('child_process').spawn;
  8. var path = require('path');
  9. var getOptions = require('./options');
  10. var 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(function (arg) {
  15. var 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. args.unshift(arg);
  26. args.push('--no-timeouts');
  27. break;
  28. case '-gc':
  29. case '--expose-gc':
  30. args.unshift('--expose-gc');
  31. break;
  32. case '--gc-global':
  33. case '--es_staging':
  34. case '--no-deprecation':
  35. case '--prof':
  36. case '--log-timer-events':
  37. case '--throw-deprecation':
  38. case '--trace-deprecation':
  39. case '--use_strict':
  40. case '--allow-natives-syntax':
  41. case '--perf-basic-prof':
  42. args.unshift(arg);
  43. break;
  44. default:
  45. if (arg.indexOf('--harmony') === 0) {
  46. args.unshift(arg);
  47. } else if (arg.indexOf('--trace') === 0) {
  48. args.unshift(arg);
  49. } else if (arg.indexOf('--icu-data-dir') === 0) {
  50. args.unshift(arg);
  51. } else if (arg.indexOf('--max-old-space-size') === 0) {
  52. args.unshift(arg);
  53. } else if (arg.indexOf('--preserve-symlinks') === 0) {
  54. args.unshift(arg);
  55. } else {
  56. args.push(arg);
  57. }
  58. break;
  59. }
  60. });
  61. var proc = spawn(process.execPath, args, { stdio: 'inherit' });
  62. proc.on('exit', function (code, signal) {
  63. process.on('exit', function () {
  64. if (signal) {
  65. process.kill(process.pid, signal);
  66. } else {
  67. process.exit(code);
  68. }
  69. });
  70. });
  71. // terminate children.
  72. process.on('SIGINT', function () {
  73. proc.kill('SIGINT'); // calls runner.abort()
  74. proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
  75. });