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.

43 lines
1.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. const Tom = require('test-runner').Tom
  2. const a = require('assert').strict
  3. const WsCli = require('../lib/cli-app')
  4. const fetch = require('node-fetch')
  5. const tom = module.exports = new Tom({ maxConcurrency: 1 })
  6. tom.test('simple', async function () {
  7. const port = 7500 + this.index
  8. const cli = new WsCli({ logError: function () {} })
  9. const server = cli.start([ '--port', `${port}` ])
  10. const response = await fetch(`http://127.0.0.1:${port}/package.json`)
  11. server.close()
  12. a.equal(response.status, 200)
  13. })
  14. tom.test('bad option', async function () {
  15. const exitCode = process.exitCode
  16. const cli = new WsCli({ logError: function () {} })
  17. const server = cli.start([ '--should-fail' ])
  18. if (!exitCode) process.exitCode = 0
  19. a.equal(server, undefined)
  20. })
  21. tom.test('--help', async function () {
  22. const cli = new WsCli({ log: function () {} })
  23. cli.start([ '--help' ])
  24. })
  25. tom.test('--version', async function () {
  26. let logMsg = ''
  27. const cli = new WsCli({ log: function (msg) { logMsg = msg } })
  28. cli.start([ '--version' ])
  29. const pkg = require('../package.json')
  30. a.equal(logMsg.trim(), pkg.version)
  31. })
  32. tom.test('default-stack', async function () {
  33. let logMsg = ''
  34. const cli = new WsCli({ log: function (msg) { logMsg = msg } })
  35. cli.start([ '--default-stack' ])
  36. a.ok(/lws-static/.test(logMsg))
  37. })