index.spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var path = require('./index');
  2. const s = path.sep;
  3. describe("canonical-path", function() {
  4. describe("normalize", function() {
  5. it("should return a normalized path only using forward slashes", function() {
  6. expect(path.normalize('a/c/../b')).toEqual('a/b');
  7. expect(path.normalize(`a${s}c${s}..${s}b`)).toEqual('a/b');
  8. });
  9. });
  10. describe("join", function() {
  11. it("should join paths only using forward slashes", function() {
  12. expect(path.join('a/b', 'c/d')).toEqual('a/b/c/d');
  13. expect(path.join(`a${s}b`, `c${s}d`)).toEqual('a/b/c/d');
  14. });
  15. });
  16. describe("resolve", function() {
  17. it("should return a resolved path only using forward slashes", function() {
  18. expect(path.resolve('/a/b', 'x/../c')).toEqual(path.resolve('/') + 'a/b/c');
  19. expect(path.resolve(`a${s}c${s}..${s}b`)).toEqual(path.resolve('') + '/a/b');
  20. });
  21. });
  22. describe("relative", function() {
  23. it("should return a relative path only using forward slashes", function() {
  24. expect(path.relative('a/b', 'a/d/e/f')).toEqual('../d/e/f');
  25. expect(path.relative(`a${s}b`, `a${s}d${s}e${s}f`)).toEqual('../d/e/f');
  26. });
  27. });
  28. describe("dirname", function() {
  29. it("should return the dirname of a path only using forward slashes", function() {
  30. expect(path.dirname('a/b/c')).toEqual('a/b');
  31. expect(path.dirname(`a${s}b${s}c`)).toEqual('a/b');
  32. });
  33. });
  34. describe("format", function() {
  35. it("should return a formatted path only using forward slashes", function() {
  36. expect(path.format({dir: 'a/b', base: 'c'})).toEqual('a/b/c');
  37. expect(path.format({dir: `a${s}b`, base: 'c'})).toEqual('a/b/c');
  38. });
  39. });
  40. describe("canonical", function() {
  41. it("should return a path with forward slashes", function() {
  42. expect(path.canonical('a'+path.sep+'b'+path.sep+'c')).toEqual('a/b/c');
  43. });
  44. });
  45. });