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.

33 lines
918 B

  1. 'use strict'
  2. const test = require('tape')
  3. const request = require('req-then')
  4. const localWebServer = require('../')
  5. const http = require('http')
  6. function launchServer (app, options) {
  7. options = options || {}
  8. const path = `http://localhost:8100${options.path || '/'}`
  9. const server = http.createServer(app.callback())
  10. return server.listen(options.port || 8100, () => {
  11. const req = request(path, options.reqOptions)
  12. if (options.onSuccess) req.then(options.onSuccess)
  13. if (!options.leaveOpen) req.then(() => server.close())
  14. req.catch(err => console.error('LAUNCH ERROR', err.stack))
  15. })
  16. }
  17. test('static', function (t) {
  18. t.plan(1)
  19. const app = localWebServer({
  20. log: { format: 'none' },
  21. static: {
  22. root: __dirname + '/fixture',
  23. options: {
  24. index: 'file.txt'
  25. }
  26. }
  27. })
  28. launchServer(app, { onSuccess: response => {
  29. t.ok(/test/.test(response.data))
  30. }})
  31. })