path.spec.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 '@jupyterlab/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. it('should not return "." for an empty path', () => {
  18. let path = PathExt.join('', '');
  19. expect(path).to.equal('');
  20. });
  21. });
  22. describe('.basename()', () => {
  23. it('should return the last portion of a path', () => {
  24. expect(PathExt.basename(TESTPATH)).to.equal('test-path.js');
  25. });
  26. });
  27. describe('.dirname()', () => {
  28. it('should get the directory name of a path', () => {
  29. expect(PathExt.dirname(TESTPATH)).to.equal('foo/test/simple');
  30. });
  31. it('should not return "." for an empty path', () => {
  32. let path = PathExt.dirname('');
  33. expect(path).to.equal('');
  34. });
  35. it('should not return "." for a path in the root directory', () => {
  36. let path = PathExt.dirname('foo.txt');
  37. expect(path).to.equal('');
  38. });
  39. });
  40. describe('.extname()', () => {
  41. it('should get the file extension of the path', () => {
  42. expect(PathExt.extname(TESTPATH)).to.equal('.js');
  43. });
  44. it('should only take the last occurance of a dot', () => {
  45. expect(PathExt.extname('foo.tar.gz')).to.equal('.gz');
  46. });
  47. });
  48. describe('.normalize()', () => {
  49. it('should normalize a string path', () => {
  50. let path = PathExt.normalize('./fixtures///b/../b/c.js');
  51. expect(path).to.equal('fixtures/b/c.js');
  52. });
  53. it('should not return "." for an empty path', () => {
  54. let path = PathExt.normalize('');
  55. expect(path).to.equal('');
  56. });
  57. });
  58. describe('.resolve()', () => {
  59. it('should resolve a sequence of paths to an absolute path on the server', () => {
  60. let path = PathExt.resolve('var/lib', '../', 'file/');
  61. expect(path).to.equal('var/file');
  62. });
  63. });
  64. describe('.relative()', () => {
  65. it('should solve the relative path', () => {
  66. let path = PathExt.relative('var/lib', 'var/apache');
  67. expect(path).to.equal('../apache');
  68. });
  69. });
  70. describe('.normalizeExtension()', () => {
  71. it('should normalize a file extension to be of type `.foo`', () => {
  72. expect(PathExt.normalizeExtension('foo')).to.equal('.foo');
  73. expect(PathExt.normalizeExtension('.bar')).to.equal('.bar');
  74. });
  75. });
  76. });
  77. });