url.test.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. exports.__esModule = true;
  3. var url_js_1 = require("../url.js");
  4. describe('next-sitemap/url', function () {
  5. test('isURL : Valid', function () {
  6. expect((0, url_js_1.isURL)('https://example.com')).toBeTruthy();
  7. });
  8. test('isURL : Invalid', function () {
  9. expect((0, url_js_1.isURL)('/someone-relative/path/item.jpg')).toBeFalsy();
  10. });
  11. test('cleanPath : Relative Path', function () {
  12. expect((0, url_js_1.cleanPath)('./epic///awesome///path')).toBe('./epic/awesome/path');
  13. });
  14. test('cleanPath: Public Url', function () {
  15. expect((0, url_js_1.cleanPath)('https://www.example.com//epic///awesome///path')).toBe('https://www.example.com/epic/awesome/path');
  16. });
  17. test('generateUrl: with relative slug', function () {
  18. var url = (0, url_js_1.generateUrl)('https://base.example.com', '//awesome/path');
  19. expect(url).toBe('https://base.example.com/awesome/path');
  20. });
  21. test('generateUrl: with external slug', function () {
  22. var url = (0, url_js_1.generateUrl)('https://base.example.com', 'https://cdn.another.site/new//path');
  23. expect(url).toBe('https://cdn.another.site/new/path');
  24. });
  25. test('isNextInternalUrl', function () {
  26. expect((0, url_js_1.isNextInternalUrl)('/_app')).toBeTruthy();
  27. expect((0, url_js_1.isNextInternalUrl)('/404')).toBeTruthy();
  28. expect((0, url_js_1.isNextInternalUrl)('/500')).toBeTruthy();
  29. expect((0, url_js_1.isNextInternalUrl)('/_random')).toBeTruthy();
  30. expect((0, url_js_1.isNextInternalUrl)('/_middleware')).toBeTruthy();
  31. expect((0, url_js_1.isNextInternalUrl)('/about/_middleware')).toBeTruthy();
  32. expect((0, url_js_1.isNextInternalUrl)('/some_url/about/_middleware')).toBeTruthy();
  33. expect((0, url_js_1.isNextInternalUrl)('/projects/[id]/_middleware')).toBeTruthy();
  34. });
  35. test('isNextInternalUrl: url params', function () {
  36. expect((0, url_js_1.isNextInternalUrl)('/[id]')).toBeTruthy();
  37. expect((0, url_js_1.isNextInternalUrl)('/blog/[id]')).toBeTruthy();
  38. });
  39. test('isNextInternalUrl: allow urls with underscore`', function () {
  40. expect((0, url_js_1.isNextInternalUrl)('/_some_url')).toBeTruthy();
  41. expect((0, url_js_1.isNextInternalUrl)('/some_url/[param]')).toBeTruthy();
  42. expect((0, url_js_1.isNextInternalUrl)('/some_url')).toBeFalsy();
  43. expect((0, url_js_1.isNextInternalUrl)('/some-404')).toBeFalsy();
  44. expect((0, url_js_1.isNextInternalUrl)('/some-500')).toBeFalsy();
  45. });
  46. test('createDefaultLocaleReplace: replaces default locale within path`', function () {
  47. var replaceDefaultLocale = (0, url_js_1.createDefaultLocaleReplace)('en-US');
  48. expect(replaceDefaultLocale('/')).toBe('/');
  49. expect(replaceDefaultLocale('/en-US')).toBe('/');
  50. expect(replaceDefaultLocale('/en-US/')).toBe('/');
  51. expect(replaceDefaultLocale('/en-US/home')).toBe('/home');
  52. expect(replaceDefaultLocale('/en-US/home/')).toBe('/home/');
  53. expect(replaceDefaultLocale('/en-US-home')).toBe('/en-US-home');
  54. expect(replaceDefaultLocale('/en-USA/home')).toBe('/en-USA/home');
  55. expect(replaceDefaultLocale('/fr')).toBe('/fr');
  56. expect(replaceDefaultLocale('/fr/about')).toBe('/fr/about');
  57. });
  58. });