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.

58 lines
1.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. const Tom = require('test-runner').Tom
  2. const a = require('assert')
  3. const WsCli = require('../lib/cli-app')
  4. const fetch = require('node-fetch')
  5. const tom = module.exports = new Tom('cli')
  6. tom.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 cli = new WsCli({ logError: function () {} })
  11. const server = cli.start()
  12. process.argv = origArgv
  13. const response = await fetch(`http://127.0.0.1:${port}/package.json`)
  14. server.close()
  15. a.strictEqual(response.status, 200)
  16. })
  17. tom.test('cli.run: bad option', async function () {
  18. const origArgv = process.argv.slice()
  19. process.argv = [ 'node', 'something', '--should-fail' ]
  20. const exitCode = process.exitCode
  21. const cli = new WsCli({ logError: function () {} })
  22. const server = cli.start()
  23. if (!exitCode) process.exitCode = 0
  24. process.argv = origArgv
  25. a.strictEqual(server, undefined)
  26. })
  27. tom.test('cli.run: --help', async function () {
  28. const origArgv = process.argv.slice()
  29. process.argv = [ 'node', 'something', '--help' ]
  30. const cli = new WsCli({ log: function () {} })
  31. cli.start()
  32. process.argv = origArgv
  33. })
  34. tom.test('cli.run: --version', async function () {
  35. const origArgv = process.argv.slice()
  36. process.argv = [ 'node', 'something', '--version' ]
  37. let logMsg = ''
  38. const cli = new WsCli({ log: function (msg) { logMsg = msg } })
  39. cli.start()
  40. const pkg = require('../package.json')
  41. a.strictEqual(logMsg.trim(), pkg.version)
  42. process.argv = origArgv
  43. })
  44. tom.test('cli.run: default-stack', async function () {
  45. const origArgv = process.argv.slice()
  46. process.argv = [ 'node', 'something', '--default-stack' ]
  47. let logMsg = ''
  48. const cli = new WsCli({ log: function (msg) { logMsg = msg } })
  49. cli.start()
  50. a.ok(/lws-static/.test(logMsg))
  51. process.argv = origArgv
  52. })