Skip to content

Commit

Permalink
fix: don't attempt to run validate scripts if there are none to be run
Browse files Browse the repository at this point in the history
  • Loading branch information
jrolfs committed Mar 28, 2020
1 parent 09cc0e4 commit 80c1545
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/scripts/__tests__/__snapshots__/validate.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ exports[`validate does not include "lint" if it doesn't have that script 1`] = `
exports[`validate does not include "test" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run build" "yarn run lint" "yarn run flow"`;

exports[`validate doesn't use test or lint if it's in pre-commit 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "yarn run build" "yarn run flow"`;

exports[`validate exits if there are no scripts to be run 1`] = ``;
8 changes: 5 additions & 3 deletions src/scripts/__tests__/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ cases(
try {
// tests
require('../validate')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const [firstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = firstCall
const [crossSpawnFirstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = crossSpawnFirstCall || ['', []]
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
} catch (error) {
throw error
Expand Down Expand Up @@ -58,6 +57,9 @@ cases(
}
}),
},
'exits if there are no scripts to be run': {
setup: withDefaultSetup(setupWithScripts([])),
},
},
)

Expand Down
18 changes: 12 additions & 6 deletions src/scripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ const scripts = useDefaultScripts
return scriptsToRun
}, {})

const result = spawn.sync(
resolveBin('concurrently'),
getConcurrentlyArgs(scripts),
{stdio: 'inherit'},
)
const scriptCount = Object.values(scripts).filter(Boolean).length

process.exit(result.status)
if (scriptCount > 0) {
const result = spawn.sync(
resolveBin('concurrently'),
getConcurrentlyArgs(scripts),
{stdio: 'inherit'},
)

process.exit(result.status)
} else {
process.exit(0)
}

0 comments on commit 80c1545

Please sign in to comment.