Skip to content

Commit 4abbe95

Browse files
authored
Don't crash npm test when hg/git are missing (facebook#5212)
1 parent 66648f1 commit 4abbe95

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

scripts/test.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,36 @@ if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
3131
// @remove-on-eject-end
3232

3333
const jest = require('jest');
34+
const execSync = require('child_process').execSync;
3435
let argv = process.argv.slice(2);
3536

37+
function isInGitRepository() {
38+
try {
39+
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
40+
return true;
41+
} catch (e) {
42+
return false;
43+
}
44+
}
45+
46+
function isInMercurialRepository() {
47+
try {
48+
execSync('hg --cwd . root', { stdio: 'ignore' });
49+
return true;
50+
} catch (e) {
51+
return false;
52+
}
53+
}
54+
3655
// Watch unless on CI, in coverage mode, or explicitly running all tests
3756
if (
3857
!process.env.CI &&
3958
argv.indexOf('--coverage') === -1 &&
4059
argv.indexOf('--watchAll') === -1
4160
) {
42-
argv.push('--watch');
61+
// https://github.com/facebook/create-react-app/issues/5210
62+
const hasSourceControl = isInGitRepository() || isInMercurialRepository();
63+
argv.push(hasSourceControl ? '--watch' : '--watchAll');
4364
}
4465

4566
// @remove-on-eject-begin

0 commit comments

Comments
 (0)