urlJoin.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import path from 'path';
  2. import { urlJoin } from '../src/utilities/urlJoin.js';
  3. describe( 'urlJoin', () => {
  4. it( 'should behave like path.join if no protocol is present', () => {
  5. expect(
  6. urlJoin( 'path', 'to', 'file.json' )
  7. ).toBe(
  8. path.normalize( 'path\\to\\file.json' )
  9. );
  10. expect(
  11. urlJoin( 'path//', 'to\\other\\', 'file.json' )
  12. ).toBe(
  13. path.normalize( 'path\\to\\other\\file.json' )
  14. );
  15. expect(
  16. urlJoin( '//path', 'to', 'file.json' )
  17. ).toBe(
  18. path.normalize( '\\\\path\\to\\file.json' )
  19. );
  20. } );
  21. it( 'should handle protocols correctly.', () => {
  22. expect(
  23. urlJoin( 'http://path', 'to', 'file.json' )
  24. ).toBe(
  25. path.normalize( 'http:\\\\path\\to\\file.json' )
  26. );
  27. expect(
  28. urlJoin( 'http://path', 'http://path2', 'to', 'file.json' )
  29. ).toBe(
  30. path.normalize( 'http:\\\\path2\\to\\file.json' )
  31. );
  32. expect(
  33. urlJoin( 'https://path', 'to', 'file.json' )
  34. ).toBe(
  35. path.normalize( 'https:\\\\path\\to\\file.json' )
  36. );
  37. expect(
  38. urlJoin( 'ftp://path', 'to', 'file.json' )
  39. ).toBe(
  40. path.normalize( 'ftp:\\\\path\\to\\file.json' )
  41. );
  42. expect(
  43. urlJoin( 'ftp://http://path', 'to', 'file.json' )
  44. ).toBe(
  45. path.normalize( 'ftp:\\\\http:\\path\\to\\file.json' )
  46. );
  47. } );
  48. } );