Skip to content

Commit

Permalink
fix: scriptName early error (#147)
Browse files Browse the repository at this point in the history
* Fail gracefully on non-existent scripts

* Add test case to handle missing scripts
  • Loading branch information
imbhargav5 authored and Kent C. Dodds committed Jun 15, 2017
1 parent 70568c0 commit 1bad1f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -42,7 +42,7 @@ function runPackageScripts({scriptConfig, scripts, options = {}}) {
function runPackageScript({scriptConfig, options, input}) {
const [scriptPrefix, ...args] = input.split(' ')
const scripts = getScriptsFromConfig(scriptConfig, scriptPrefix)
const {scriptName, script} = getScriptToRun(scripts, scriptPrefix)
const {scriptName, script} = getScriptToRun(scripts, scriptPrefix) || {}
if (!isString(script)) {
return Promise.reject({
message: chalk.red(
Expand Down
17 changes: 17 additions & 0 deletions src/index.test.js
Expand Up @@ -151,6 +151,23 @@ test('runs the default script if no scripts provided', () => {
})
})

test('returns a log object when a script does not exist', () => {
const {runPackageScript} = setup()
const scriptConfig = {lint: {script: 42}}
return runPackageScript({scriptConfig, scripts: ['dev']}).catch(error => {
expect(error).toEqual({
message: chalk.red(
oneLine`
Scripts must resolve to strings.
There is no script that can be
resolved from "dev"
`,
),
ref: 'missing-script',
})
})
})

test('an error from the child process logs an error', () => {
const ERROR = {message: 'there was an error', code: 2}
const badCommand = 'bad'
Expand Down

0 comments on commit 1bad1f9

Please sign in to comment.