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.

50 lines
1.5 KiB

8 years ago
8 years ago
8 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 origArgv = process.argv.slice()
  20. process.argv = [ 'node', 'something', '--should-fail' ]
  21. const exitCode = process.exitCode
  22. const server = CliApp.run()
  23. if (!exitCode) process.exitCode = 0
  24. process.argv = origArgv
  25. a.strictEqual(server, undefined)
  26. })
  27. runner.test('cli.run: --help', async function () {
  28. const origArgv = process.argv.slice()
  29. process.argv = [ 'node', 'something', '--help' ]
  30. CliApp.run()
  31. process.argv = origArgv
  32. })
  33. runner.test('cli.run: --version', async function () {
  34. const origArgv = process.argv.slice()
  35. process.argv = [ 'node', 'something', '--version' ]
  36. CliApp.run()
  37. process.argv = origArgv
  38. })
  39. runner.test('cli.run: middleware-list', async function () {
  40. const origArgv = process.argv.slice()
  41. process.argv = [ 'node', 'something', 'middleware-list' ]
  42. CliApp.run()
  43. process.argv = origArgv
  44. })