Skip to content

Commit

Permalink
Don't crash npm test when hg/git are missing (#5212)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Oct 1, 2018
1 parent b539b64 commit b103376
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/react-scripts/scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,36 @@ if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
// @remove-on-eject-end

const jest = require('jest');
const execSync = require('child_process').execSync;
let argv = process.argv.slice(2);

function isInGitRepository() {
try {
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}

function isInMercurialRepository() {
try {
execSync('hg --cwd . root', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}

// Watch unless on CI, in coverage mode, or explicitly running all tests
if (
!process.env.CI &&
argv.indexOf('--coverage') === -1 &&
argv.indexOf('--watchAll') === -1
) {
argv.push('--watch');
// https://github.com/facebook/create-react-app/issues/5210
const hasSourceControl = isInGitRepository() || isInMercurialRepository();
argv.push(hasSourceControl ? '--watch' : '--watchAll');
}

// @remove-on-eject-begin
Expand Down

0 comments on commit b103376

Please sign in to comment.