try-path.test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var try_path_1 = require("../try-path");
  4. var path_1 = require("path");
  5. describe("mapping-entry", function () {
  6. var abosolutePathMappings = [
  7. {
  8. pattern: "longest/pre/fix/*",
  9. paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
  10. },
  11. { pattern: "pre/fix/*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")] },
  12. { pattern: "*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo1")] },
  13. ];
  14. var abosolutePathMappingsStarstWithSlash = [
  15. {
  16. pattern: "/opt/*",
  17. paths: [(0, path_1.join)("/absolute", "src", "aws-layer")],
  18. },
  19. {
  20. pattern: "*",
  21. paths: [(0, path_1.join)("/absolute", "src")],
  22. },
  23. ];
  24. it("should return no paths for relative requested module", function () {
  25. var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], abosolutePathMappings, "./requested-module");
  26. expect(result).toBeUndefined();
  27. });
  28. it("should return no paths if no pattern match the requested module", function () {
  29. var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], [
  30. {
  31. pattern: "longest/pre/fix/*",
  32. paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
  33. },
  34. {
  35. pattern: "pre/fix/*",
  36. paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
  37. },
  38. ], "requested-module");
  39. expect(result).toBeUndefined();
  40. });
  41. it("should get all paths that matches requested module", function () {
  42. var result = (0, try_path_1.getPathsToTry)([".ts", ".tsx"], abosolutePathMappings, "longest/pre/fix/requested-module");
  43. expect(result).toEqual([
  44. // "longest/pre/fix/*"
  45. { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar") },
  46. {
  47. type: "extension",
  48. path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.ts"),
  49. },
  50. {
  51. type: "extension",
  52. path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.tsx"),
  53. },
  54. {
  55. type: "package",
  56. path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "package.json"),
  57. },
  58. {
  59. type: "index",
  60. path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.ts"),
  61. },
  62. {
  63. type: "index",
  64. path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
  65. },
  66. // "*"
  67. { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo1") },
  68. { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.ts") },
  69. { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.tsx") },
  70. {
  71. type: "package",
  72. path: (0, path_1.join)("/absolute", "base", "url", "foo1", "package.json"),
  73. },
  74. {
  75. type: "index",
  76. path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.ts"),
  77. },
  78. {
  79. type: "index",
  80. path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.tsx"),
  81. },
  82. ]);
  83. });
  84. it("should resolve paths starting with a slash", function () {
  85. var result = (0, try_path_1.getPathsToTry)([".ts"], abosolutePathMappingsStarstWithSlash, "/opt/utils");
  86. expect(result).toEqual([
  87. // "opt/*"
  88. {
  89. path: (0, path_1.join)("/absolute", "src", "aws-layer"),
  90. type: "file",
  91. },
  92. {
  93. path: (0, path_1.join)("/absolute", "src", "aws-layer.ts"),
  94. type: "extension",
  95. },
  96. {
  97. path: (0, path_1.join)("/absolute", "src", "aws-layer", "package.json"),
  98. type: "package",
  99. },
  100. {
  101. path: (0, path_1.join)("/absolute", "src", "aws-layer", "index.ts"),
  102. type: "index",
  103. },
  104. // "*"
  105. {
  106. path: (0, path_1.join)("/absolute", "src"),
  107. type: "file",
  108. },
  109. {
  110. path: (0, path_1.join)("/absolute", "src.ts"),
  111. type: "extension",
  112. },
  113. {
  114. path: (0, path_1.join)("/absolute", "src", "package.json"),
  115. type: "package",
  116. },
  117. {
  118. path: (0, path_1.join)("/absolute", "src", "index.ts"),
  119. type: "index",
  120. },
  121. ]);
  122. });
  123. });
  124. //# sourceMappingURL=try-path.test.js.map