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