Skip to content

Commit

Permalink
fix: fixed exit
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 6, 2018
1 parent 6577f58 commit 97986a4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"fancy-test": "^1.0.3"
},
"devDependencies": {
"@oclif/command": "^1.4.6",
"@oclif/command": "^1.4.7",
"@oclif/config": "^1.3.62",
"@oclif/errors": "^1.0.3",
"@oclif/tslint": "^1.0.2",
Expand Down
7 changes: 5 additions & 2 deletions src/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {expect} from 'chai'
export default (code = 0) => ({
run() {
expect(process.exitCode).to.equal(code)
throw new Error(`Expected hook to exit with code ${code} but it ran without exiting`)
}
throw new Error(`Expected to exit with code ${code} but it ran without exiting`)
},
catch(ctx: {error: Error}) {
expect(ctx.error.message).to.equal(`EEXIT: ${code}`)
},
})
15 changes: 15 additions & 0 deletions test/exit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as path from 'path'

import {expect, test} from '../src'

const root = path.join(__dirname, 'fixtures/multi')

describe('exit', () => {
test
.loadConfig({root})
.stdout()
.command(['exit', '--code=101'])
.exit(101)
.do(output => expect(output.stdout).to.equal('exiting with code 101\n'))
.it()
})
16 changes: 16 additions & 0 deletions test/fixtures/multi/src/commands/exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const {Command, flags} = require('@oclif/command')

class CLI extends Command {
async run() {
const {flags} = this.parse(CLI)
const code = parseInt(flags.code || '1')
this.log(`exiting with code ${code}`)
this.exit(code)
}
}

CLI.flags = {
code: flags.string(),
}

module.exports = CLI
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
version "1.0.0"
resolved "https://registry.yarnpkg.com/@heroku/linewrap/-/linewrap-1.0.0.tgz#a9d4e99f0a3e423a899b775f5f3d6747a1ff15c6"

"@oclif/command@^1.4.6":
version "1.4.6"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.4.6.tgz#6de7789cfc6ae6cdf177566fbfbb742d5cb8f320"
"@oclif/command@^1.4.7":
version "1.4.7"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.4.7.tgz#32423fcb3317c1e9fd5b864c728ddd5e4f8fd361"
dependencies:
"@oclif/errors" "^1.0.3"
"@oclif/parser" "^3.2.9"
Expand Down

0 comments on commit 97986a4

Please sign in to comment.