diff --git a/CHANGELOG.md b/CHANGELOG.md index 58186f1..f333691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## 9.0.2 - Unreleased +## 9.0.2 - **Fix**: CLI will now exit with non-zero error code when an error is encountered (thanks to blagh) ## 9.0.1 -- **BREAKING**: Fixed major bug that required passing `--` inorder to pass flags to the command. +- **BREAKING**: Fixed major bug that required passing `--` in order to pass flags to the command. Normally I release major breaking changes as major versions, but this was a bug and no documentation anywhere states using `--` as intended or official behavior. - **Change**: Fixed some documentation issues diff --git a/package.json b/package.json index 53e7634..fef0377 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "env-cmd", - "version": "9.0.1", + "version": "9.0.2", "description": "Executes a command using the environment variables in an env file", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/test/env-cmd.spec.ts b/test/env-cmd.spec.ts index 221f706..fd6582e 100644 --- a/test/env-cmd.spec.ts +++ b/test/env-cmd.spec.ts @@ -8,20 +8,39 @@ import * as envCmdLib from '../src/env-cmd' describe('CLI', (): void => { let parseArgsStub: sinon.SinonStub let envCmdStub: sinon.SinonStub + let processExitStub: sinon.SinonStub + before((): void => { parseArgsStub = sinon.stub(parseArgsLib, 'parseArgs') envCmdStub = sinon.stub(envCmdLib, 'EnvCmd') + processExitStub = sinon.stub(process, 'exit') }) after((): void => { sinon.restore() }) + afterEach((): void => { + sinon.resetHistory() + sinon.resetBehavior() + }) + it('should parse the provided args and execute the EnvCmd', async (): Promise => { parseArgsStub.returns({}) await envCmdLib.CLI(['node', './env-cmd', '-v']) assert.equal(parseArgsStub.callCount, 1) assert.equal(envCmdStub.callCount, 1) + assert.equal(processExitStub.callCount, 0) + }) + + it('should catch exception if EnvCmd throws an exception', async (): Promise => { + parseArgsStub.returns({}) + envCmdStub.throwsException('Error') + await envCmdLib.CLI(['node', './env-cmd', '-v']) + assert.equal(parseArgsStub.callCount, 1) + assert.equal(envCmdStub.callCount, 1) + assert.equal(processExitStub.callCount, 1) + assert.equal(processExitStub.args[0][0], 1) }) })