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.

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