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.

35 lines
943 B

  1. const Tom = require('test-runner').Tom
  2. const fetch = require('node-fetch')
  3. const LocalWebServer = require('../')
  4. const WsCli = require('../lib/cli-app')
  5. const a = require('assert')
  6. const tom = module.exports = new Tom('sequential', { concurrency: 1 })
  7. let origCwd = ''
  8. tom.test('before', async function () {
  9. origCwd = process.cwd()
  10. process.chdir('test/fixture/middleware')
  11. })
  12. tom.test('cli: middleware named "index.js"', async function () {
  13. let logMsg = ''
  14. const cli = new WsCli({ log: function (msg) { logMsg = msg } })
  15. const lws = cli.start([ '--stack', 'index.js', '--config' ])
  16. a.ok(/TestMiddleware/.test(logMsg))
  17. })
  18. tom.test('basic', async function () {
  19. const port = 9100 + this.index
  20. const ws = LocalWebServer.create({
  21. port: port,
  22. stack: 'index.js'
  23. })
  24. ws.server.close()
  25. a.strictEqual(ws.stack[0].constructor.name, 'TestMiddleware')
  26. })
  27. tom.test('after', async function () {
  28. process.chdir(origCwd)
  29. })