ee1296bf | // Do this as the first thing so that any code reading it knows the right env. |
84348047 | process.env.BABEL_ENV = "test"; process.env.NODE_ENV = "test"; process.env.PUBLIC_URL = ""; |
ee1296bf | // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. |
84348047 | process.on("unhandledRejection", err => { |
ee1296bf | throw err; }); // Ensure environment variables are read. |
84348047 | require("../config/env"); |
ee1296bf | |
84348047 | const jest = require("jest"); const execSync = require("child_process").execSync; |
ee1296bf | let argv = process.argv.slice(2); function isInGitRepository() { try { |
84348047 | execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" }); |
ee1296bf | return true; } catch (e) { return false; } } // Watch unless on CI, in coverage mode, explicitly adding `--no-watch`, // or explicitly running all tests if ( !process.env.CI && |
84348047 | argv.indexOf("--coverage") === -1 && argv.indexOf("--no-watch") === -1 && argv.indexOf("--watchAll") === -1 |
ee1296bf | ) { // https://github.com/facebook/create-react-app/issues/5210 |
2ecc370b | const hasSourceControl = isInGitRepository(); |
84348047 | argv.push(hasSourceControl ? "--watch" : "--watchAll"); |
ee1296bf | } // Jest doesn't have this option so we'll remove it |
84348047 | if (argv.indexOf("--no-watch") !== -1) { argv = argv.filter(arg => arg !== "--no-watch"); |
ee1296bf | } jest.run(argv); |