Files
hiring-test-one/test/cli.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-05-23 22:08:37 +01:00
const Tom = require('test-runner').Tom
2017-07-07 23:52:48 +01:00
const a = require('assert')
const CliApp = require('../lib/cli-app')
2019-05-23 22:08:37 +01:00
const fetch = require('node-fetch')
2017-07-07 23:52:48 +01:00
2019-05-23 22:08:37 +01:00
const tom = module.exports = new Tom('cli')
2017-07-07 23:52:48 +01:00
2019-05-23 22:08:37 +01:00
tom.test('cli.run', async function () {
2017-07-07 23:52:48 +01:00
const port = 7500 + this.index
const origArgv = process.argv.slice()
process.argv = [ 'node', 'something', '--port', `${port}` ]
const server = CliApp.run()
process.argv = origArgv
2019-05-23 22:08:37 +01:00
const response = await fetch(`http://127.0.0.1:${port}/`)
2017-07-07 23:52:48 +01:00
server.close()
2019-05-23 22:08:37 +01:00
a.strictEqual(response.status, 200)
2017-07-07 23:52:48 +01:00
})
2019-05-23 22:08:37 +01:00
tom.test('cli.run: bad option', async function () {
2017-07-07 23:52:48 +01:00
const origArgv = process.argv.slice()
process.argv = [ 'node', 'something', '--should-fail' ]
2018-01-17 22:42:46 +00:00
const exitCode = process.exitCode
2017-07-07 23:52:48 +01:00
const server = CliApp.run()
2018-01-17 22:42:46 +00:00
if (!exitCode) process.exitCode = 0
2017-07-07 23:52:48 +01:00
process.argv = origArgv
a.strictEqual(server, undefined)
})
2019-05-23 22:08:37 +01:00
tom.test('cli.run: --help', async function () {
2017-07-07 23:52:48 +01:00
const origArgv = process.argv.slice()
process.argv = [ 'node', 'something', '--help' ]
CliApp.run()
process.argv = origArgv
})
2019-05-23 22:08:37 +01:00
tom.test('cli.run: --version', async function () {
2017-07-07 23:52:48 +01:00
const origArgv = process.argv.slice()
process.argv = [ 'node', 'something', '--version' ]
CliApp.run()
process.argv = origArgv
})
2019-05-23 22:08:37 +01:00
tom.test('cli.run: middleware-list', async function () {
2017-07-07 23:52:48 +01:00
const origArgv = process.argv.slice()
process.argv = [ 'node', 'something', 'middleware-list' ]
CliApp.run()
process.argv = origArgv
})