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.

36 lines
909 B

8 years ago
  1. 'use strict'
  2. const test = require('tape')
  3. const request = require('req-then')
  4. const LocalWebServer = require('../')
  5. const c = require('./common')
  6. const path = require('path')
  7. test('stack', function (t) {
  8. t.plan(2)
  9. const ws = new LocalWebServer({
  10. stack: [ path.resolve(__dirname, 'test-middleware.js') ]
  11. })
  12. const server = ws.getServer()
  13. server.listen(8100, () => {
  14. request('http://localhost:8100/')
  15. .then(c.checkResponse(t, 200, /1234512345/))
  16. .then(server.close.bind(server))
  17. .catch(c.fail(t))
  18. })
  19. })
  20. test('https', function (t) {
  21. t.plan(2)
  22. const ws = new LocalWebServer({
  23. stack: [ path.resolve(__dirname, 'test-middleware.js') ],
  24. https: true,
  25. port: 8100
  26. })
  27. ws.listen()
  28. .then(() => {
  29. request('https://localhost:8100/')
  30. .then(c.checkResponse(t, 200, /1234512345/))
  31. .then(ws.close.bind(ws))
  32. .catch(c.fail(t))
  33. })
  34. })