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.

44 lines
1010 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. test('static', function (t) {
  7. t.plan(1)
  8. const app = localWebServer({
  9. static: {
  10. root: __dirname + '/static',
  11. options: {
  12. index: 'file.txt'
  13. }
  14. }
  15. })
  16. const server = http.createServer(app.callback())
  17. server.listen(8100)
  18. request('http://localhost:8100')
  19. .then(response => {
  20. t.strictEqual(response.data, 'test\n')
  21. })
  22. .then(() => server.close())
  23. })
  24. test('serve-index', function (t) {
  25. t.plan(2)
  26. const app = localWebServer({
  27. serveIndex: {
  28. path: __dirname + '/static',
  29. options: {
  30. icons: true
  31. }
  32. }
  33. })
  34. const server = http.createServer(app.callback())
  35. server.listen(8100)
  36. request('http://localhost:8100/')
  37. .then(response => {
  38. t.ok(/listing directory/.test(response.data))
  39. t.ok(/class="icon/.test(response.data))
  40. })
  41. .then(() => server.close())
  42. })