You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

7 years ago
  1. const TestRunner = require('test-runner')
  2. const a = require('assert')
  3. const CliApp = require('../lib/cli-app')
  4. const request = require('req-then')
  5. const usage = require('lws/lib/usage')
  6. usage.disable()
  7. const runner = new TestRunner()
  8. runner.test('cli.run', async function () {
  9. const port = 7500 + this.index
  10. const origArgv = process.argv.slice()
  11. process.argv = [ 'node', 'something', '--port', `${port}` ]
  12. const server = CliApp.run()
  13. process.argv = origArgv
  14. const response = await request(`http://127.0.0.1:${port}/`)
  15. server.close()
  16. a.strictEqual(response.res.statusCode, 200)
  17. })
  18. runner.test('cli.run: bad option', async function () {
  19. const port = 7500 + this.index
  20. const origArgv = process.argv.slice()
  21. process.argv = [ 'node', 'something', '--should-fail' ]
  22. const server = CliApp.run()
  23. process.argv = origArgv
  24. a.strictEqual(server, undefined)
  25. })
  26. runner.test('cli.run: --help', async function () {
  27. const origArgv = process.argv.slice()
  28. process.argv = [ 'node', 'something', '--help' ]
  29. CliApp.run()
  30. process.argv = origArgv
  31. })
  32. runner.test('cli.run: --version', async function () {
  33. const origArgv = process.argv.slice()
  34. process.argv = [ 'node', 'something', '--version' ]
  35. CliApp.run()
  36. process.argv = origArgv
  37. })
  38. runner.test('cli.run: middleware-list', async function () {
  39. const origArgv = process.argv.slice()
  40. process.argv = [ 'node', 'something', 'middleware-list' ]
  41. CliApp.run()
  42. process.argv = origArgv
  43. })