You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

11 months ago
  1. 'use strict';
  2. // Do this as the first thing so that any code reading it knows the right env.
  3. process.env.BABEL_ENV = 'test';
  4. process.env.NODE_ENV = 'test';
  5. process.env.PUBLIC_URL = '';
  6. // Makes the script crash on unhandled rejections instead of silently
  7. // ignoring them. In the future, promise rejections that are not handled will
  8. // terminate the Node.js process with a non-zero exit code.
  9. process.on('unhandledRejection', err => {
  10. throw err;
  11. });
  12. // Ensure environment variables are read.
  13. require('../config/env');
  14. const jest = require('jest');
  15. const execSync = require('child_process').execSync;
  16. let argv = process.argv.slice(2);
  17. function isInGitRepository() {
  18. try {
  19. execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
  20. return true;
  21. } catch (e) {
  22. return false;
  23. }
  24. }
  25. function isInMercurialRepository() {
  26. try {
  27. execSync('hg --cwd . root', { stdio: 'ignore' });
  28. return true;
  29. } catch (e) {
  30. return false;
  31. }
  32. }
  33. // Watch unless on CI or explicitly running all tests
  34. if (
  35. !process.env.CI &&
  36. argv.indexOf('--watchAll') === -1 &&
  37. argv.indexOf('--watchAll=false') === -1
  38. ) {
  39. // https://github.com/facebook/create-react-app/issues/5210
  40. const hasSourceControl = isInGitRepository() || isInMercurialRepository();
  41. argv.push(hasSourceControl ? '--watch' : '--watchAll');
  42. }
  43. jest.run(argv);