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.

48 lines
1.4 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 runner = new TestRunner()
  6. runner.test('cli.run', async function () {
  7. const port = 7500 + this.index
  8. const origArgv = process.argv.slice()
  9. process.argv = [ 'node', 'something', '--port', `${port}` ]
  10. const server = CliApp.run()
  11. process.argv = origArgv
  12. const response = await request(`http://127.0.0.1:${port}/`)
  13. server.close()
  14. a.strictEqual(response.res.statusCode, 200)
  15. })
  16. runner.test('cli.run: bad option', async function () {
  17. const origArgv = process.argv.slice()
  18. process.argv = [ 'node', 'something', '--should-fail' ]
  19. const exitCode = process.exitCode
  20. const server = CliApp.run()
  21. if (!exitCode) process.exitCode = 0
  22. process.argv = origArgv
  23. a.strictEqual(server, undefined)
  24. })
  25. runner.test('cli.run: --help', async function () {
  26. const origArgv = process.argv.slice()
  27. process.argv = [ 'node', 'something', '--help' ]
  28. CliApp.run()
  29. process.argv = origArgv
  30. })
  31. runner.test('cli.run: --version', async function () {
  32. const origArgv = process.argv.slice()
  33. process.argv = [ 'node', 'something', '--version' ]
  34. CliApp.run()
  35. process.argv = origArgv
  36. })
  37. runner.test('cli.run: middleware-list', async function () {
  38. const origArgv = process.argv.slice()
  39. process.argv = [ 'node', 'something', 'middleware-list' ]
  40. CliApp.run()
  41. process.argv = origArgv
  42. })