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

44 lines
1.3 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 WsCli = 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
const tom = module.exports = new Tom('cli', { concurrency: 1 })
2017-07-07 23:52:48 +01:00
tom.test('simple', async function () {
2017-07-07 23:52:48 +01:00
const port = 7500 + this.index
const cli = new WsCli({ logError: function () {} })
const server = cli.start([ '--port', `${port}` ])
2019-06-02 23:15:15 +01:00
const response = await fetch(`http://127.0.0.1:${port}/package.json`)
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
})
tom.test('bad option', async function () {
2018-01-17 22:42:46 +00:00
const exitCode = process.exitCode
const cli = new WsCli({ logError: function () {} })
const server = cli.start([ '--should-fail' ])
2018-01-17 22:42:46 +00:00
if (!exitCode) process.exitCode = 0
2017-07-07 23:52:48 +01:00
a.strictEqual(server, undefined)
})
tom.test('--help', async function () {
const cli = new WsCli({ log: function () {} })
cli.start([ '--help' ])
2017-07-07 23:52:48 +01:00
})
tom.test('--version', async function () {
let logMsg = ''
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
cli.start([ '--version' ])
const pkg = require('../package.json')
a.strictEqual(logMsg.trim(), pkg.version)
2017-07-07 23:52:48 +01:00
})
tom.test('default-stack', async function () {
let logMsg = ''
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
cli.start([ '--default-stack' ])
2019-06-02 23:15:15 +01:00
a.ok(/lws-static/.test(logMsg))
2017-07-07 23:52:48 +01:00
})