path.spec.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. expect
  5. } from 'chai';
  6. import {
  7. PathExt
  8. } from '../../../lib/coreutils';
  9. const TESTPATH = 'foo/test/simple/test-path.js';
  10. describe('@jupyterlab/coreutils', () => {
  11. describe('PathExt', () => {
  12. describe('.join()', () => {
  13. it('should join the arguments and normalize the path', () => {
  14. let path = PathExt.join('foo', '../../../bar');
  15. expect(path).to.equal('../../bar');
  16. });
  17. });
  18. describe('.basename()', () => {
  19. it('should return the last portion of a path', () => {
  20. expect(PathExt.basename(TESTPATH)).to.equal('test-path.js');
  21. });
  22. });
  23. describe('.dirname()', () => {
  24. it('should get the directory name of a path', () => {
  25. expect(PathExt.dirname(TESTPATH)).to.equal('foo/test/simple');
  26. });
  27. });
  28. describe('.extname()', () => {
  29. it('should get the file extension of the path', () => {
  30. expect(PathExt.extname(TESTPATH)).to.equal('.js');
  31. });
  32. it('should only take the last occurance of a dot', () => {
  33. expect(PathExt.extname('foo.tar.gz')).to.equal('.gz');
  34. });
  35. });
  36. describe('.normalize()', () => {
  37. it('should normalize a string path', () => {
  38. let path = PathExt.normalize('./fixtures///b/../b/c.js');
  39. expect(path).to.equal('fixtures/b/c.js');
  40. });
  41. });
  42. describe('.resolve()', () => {
  43. it('should resolve a sequence of paths to an absolute path on the server', () => {
  44. let path = PathExt.resolve('var/lib', '../', 'file/');
  45. expect(path).to.equal('var/file');
  46. });
  47. });
  48. describe('.relative()', () => {
  49. it('should solve the relative path', () => {
  50. let path = PathExt.relative('var/lib', 'var/apache');
  51. expect(path).to.equal('../apache');
  52. });
  53. });
  54. describe('.normalizeExtension()', () => {
  55. it('should normalize a file extension to be of type `.foo`', () => {
  56. expect(PathExt.normalizeExtension('foo')).to.equal('.foo');
  57. expect(PathExt.normalizeExtension('.bar')).to.equal('.bar');
  58. });
  59. });
  60. });
  61. });