serveSinglePageApp.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const ava_1 = require("ava");
  4. const mocks_1 = require("../mocks");
  5. (0, mocks_1.mockGlobalScope)();
  6. const index_1 = require("../index");
  7. function testRequest(path) {
  8. (0, mocks_1.mockRequestScope)();
  9. let url = new URL('https://example.com');
  10. url.pathname = path;
  11. let request = new Request(url.toString());
  12. return request;
  13. }
  14. (0, ava_1.default)('serveSinglePageApp returns root asset path when request path ends in .html', async (t) => {
  15. let path = '/foo/thing.html';
  16. let request = testRequest(path);
  17. let expected_request = testRequest('/index.html');
  18. let actual_request = (0, index_1.serveSinglePageApp)(request);
  19. t.deepEqual(expected_request, actual_request);
  20. });
  21. (0, ava_1.default)('serveSinglePageApp returns root asset path when request path does not have extension', async (t) => {
  22. let path = '/foo/thing';
  23. let request = testRequest(path);
  24. let expected_request = testRequest('/index.html');
  25. let actual_request = (0, index_1.serveSinglePageApp)(request);
  26. t.deepEqual(expected_request, actual_request);
  27. });
  28. (0, ava_1.default)('serveSinglePageApp returns requested asset when request path has non-html extension', async (t) => {
  29. let path = '/foo/thing.js';
  30. let request = testRequest(path);
  31. let expected_request = request;
  32. let actual_request = (0, index_1.serveSinglePageApp)(request);
  33. t.deepEqual(expected_request, actual_request);
  34. });