on 0cb7c34 help sign in
bridge/scripts/test.js
52 lines 1.3 kB history raw
1'use strict';
3// Do this as the first thing so that any code reading it knows the right env.
4process.env.BABEL_ENV = 'test';
5process.env.NODE_ENV = 'test';
6process.env.PUBLIC_URL = '';
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.
11process.on('unhandledRejection', err => {
12 throw err;
13});
15// Ensure environment variables are read.
16require('../config/env');
19const jest = require('jest');
20const execSync = require('child_process').execSync;
21let argv = process.argv.slice(2);
23function isInGitRepository() {
24 try {
25 execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
26 return true;
27 } catch (e) {
28 return false;
29 }
32function isInMercurialRepository() {
33 try {
34 execSync('hg --cwd . root', { stdio: 'ignore' });
35 return true;
36 } catch (e) {
37 return false;
38 }
41// Watch unless on CI or explicitly running all tests
42if (
43 !process.env.CI &&
44 argv.indexOf('--watchAll') === -1
45) {
46 // https://github.com/facebook/create-react-app/issues/5210
47 const hasSourceControl = isInGitRepository() || isInMercurialRepository();
48 argv.push(hasSourceControl ? '--watch' : '--watchAll');
52jest.run(argv);