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.

46 lines
1.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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. port: 8100,
  12. testMode: true
  13. })
  14. const server = ws.getServer(() => {
  15. return request('http://localhost:8100/')
  16. .then(c.checkResponse(t, 200, /1234512345/))
  17. .then(server.close.bind(server))
  18. .catch(err => {
  19. t.fail(err.message)
  20. server.close()
  21. })
  22. })
  23. })
  24. test('https', function (t) {
  25. t.plan(2)
  26. const ws = new LocalWebServer({
  27. stack: [ path.resolve(__dirname, 'test-middleware.js') ],
  28. https: true,
  29. port: 8100,
  30. testMode: true
  31. })
  32. const url = require('url')
  33. const reqOptions = url.parse('https://localhost:8100/')
  34. reqOptions.rejectUnauthorized = false
  35. const server = ws.getServer(() => {
  36. return request(reqOptions)
  37. .then(c.checkResponse(t, 200, /1234512345/))
  38. .then(server.close.bind(server))
  39. .catch(err => {
  40. t.fail(err.message)
  41. server.close()
  42. })
  43. })
  44. })