Commands run with netlify dev's `--command` flag always exit with code 1. Successful commands should exit with code 0.
Is your feature request related to a problem? Please describe.
I'm using the --command flag to run integration tests together with Netlify dev server. This way the Netlify dev server stops automatically when tests are done. The exit code is always 1 (unfortunately), even if all tests succeed.
Here is an example of the command I'm running: NODE_ENV=test netlify dev --command=ava.
Describe the solution you'd like
I'd like the netlify dev to return exit code 0 if the command that was executed by --command flag returns 0.
Describe alternatives you've considered
I've made slight modification using the patch package in my node_modules, inside of netlify-cli folder.
Additional context
This seems to be caused by this line of code.
Can you submit a pull request?
Yes, I have a change prepared in a forked repo. Some tests however keep failing:
➜ cli git:(feature/exit-code-zero-on-successful-command) ✗ ava tests/framework-detection.test.js --match "should pass framework-info env to framework sub process"
Starting dev server on port: 17478 in directory site-with-gatsby
should pass framework-info env to framework sub process
tests/framework-detection.test.js:301
300: const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
301: t.snapshot(normalize(error.stdout))
302: })
Rejected promise returned by test. Reason:
TypeError {
message: 'Cannot read properties of undefined (reading \'replace\')',
}
› tests/utils/snapshots.js:17:55
› Array.reduce (<anonymous>)
› normalize (tests/utils/snapshots.js:17:15)
› tests/framework-detection.test.js:301:16
› withSiteBuilder (tests/utils/site-builder.js:188:12)
› tests/framework-detection.test.js:288:3
─
1 test failed
Pull requests are welcome! If you would like to help us add this feature, please check our contributions guidelines.
@matobeno1 do you suggest reusing the status code of the command?
So I guess you mean updating: https://github.com/netlify/cli/blob/main/src/commands/dev/dev.js#L110
)
} else {
const errorMessage = result.failed
? `${NETLIFYDEVERR} ${result.shortMessage}`
: `${NETLIFYDEVWARN} "${command}" exited with code ${result.exitCode}`
log(`${errorMessage}. Shutting down Netlify Dev server`)
}
+ process.exit(result.exitCode)
- process.exit(1)
})
would this be enough for you?
Yes it would be great, thank you!
To add more context, the command netlify dev runs is expected to be a long running command that doesn't exit at all (e.g. a server), hence if it exists it consists as a failure.
This is useful if a user configures the wrong command to signal an error.
I wonder if using something like https://github.com/bahmutov/start-server-and-test will be more straightforward for this specific use case.