showdir-with-spaces.js 864 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const test = require('tap').test;
  3. const ecstatic = require('../lib/ecstatic');
  4. const http = require('http');
  5. const request = require('request');
  6. const path = require('path');
  7. const root = `${__dirname}/public`;
  8. const baseDir = 'base';
  9. test('directory listing when directory name contains spaces', (t) => {
  10. const port = Math.floor((Math.random() * ((1 << 16) - 1e4)) + 1e4);
  11. const uri = `http://localhost:${port}${path.join('/', baseDir, 'subdir_with%20space')}`;
  12. const server = http.createServer(
  13. ecstatic({
  14. root,
  15. baseDir,
  16. showDir: true,
  17. autoIndex: false,
  18. })
  19. );
  20. server.listen(port, () => {
  21. request.get({
  22. uri,
  23. }, (err, res, body) => {
  24. t.ok(/href="\/base\/subdir_with%20space\/index.html"/.test(body), 'We found the right href');
  25. server.close();
  26. t.end();
  27. });
  28. });
  29. });