Skip to content

Commit

Permalink
fix(hubot): hubot --help wasn't working (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Nov 9, 2023
1 parent 5738ea1 commit 5641d4c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/hubot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const options = {
}

const Parser = new OptParse(switches)
Parser.banner = 'Usage hubot [options]'
Parser.banner = 'Usage: hubot [options]'

Parser.on('adapter', (opt, value) => {
options.adapter = value
Expand Down
5 changes: 5 additions & 0 deletions src/OptParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class OptParse extends EventEmitter {
}
return options
}

toString () {
return `${this.banner}
${this.switches.map(([key, description]) => ` ${key}, ${description}`).join('\n')}`
}
}

module.exports = OptParse
30 changes: 29 additions & 1 deletion test/hubot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { TextMessage, User } = require('../index.js')
const path = require('node:path')

describe('Running bin/hubot.js', () => {
it('should load adapter from HUBOT_FILE environment variable', async function () {
it('should load adapter from HUBOT_FILE environment variable', async () => {
process.env.HUBOT_HTTPD = 'false'
process.env.HUBOT_FILE = path.resolve(root, 'test', 'fixtures', 'MockAdapter.mjs')
const hubot = require('../bin/hubot.js')
Expand All @@ -31,4 +31,32 @@ describe('Running bin/hubot.js', () => {
hubot.shutdown()
}
})
const { spawn } = require('child_process')

it('should output a help message when run with --help', (t, done) => {
const hubot = spawn('./bin/hubot', ['--help'])
const expected = `Usage: hubot [options]
-a, --adapter HUBOT_ADAPTER
-f, --file HUBOT_FILE
-c, --create HUBOT_CREATE
-d, --disable-httpd HUBOT_HTTPD
-h, --help
-l, --alias HUBOT_ALIAS
-n, --name HUBOT_NAME
-r, --require PATH
-t, --config-check
-v, --version
`
let actual = ''
hubot.stdout.on('data', (data) => {
actual += data.toString()
})
hubot.stderr.on('data', (data) => {
actual += data.toString()
})
hubot.on('close', (code) => {
assert.deepEqual(actual, expected)
done()
})
})
})

0 comments on commit 5641d4c

Please sign in to comment.