| 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 | // assert.deepEqual(result, undefined);
|
|---|
| 27 | expect(result).toBeUndefined();
|
|---|
| 28 | });
|
|---|
| 29 | it("should return no paths if no pattern match the requested module", function () {
|
|---|
| 30 | var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], [
|
|---|
| 31 | {
|
|---|
| 32 | pattern: "longest/pre/fix/*",
|
|---|
| 33 | paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
|
|---|
| 34 | },
|
|---|
| 35 | {
|
|---|
| 36 | pattern: "pre/fix/*",
|
|---|
| 37 | paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
|
|---|
| 38 | },
|
|---|
| 39 | ], "requested-module");
|
|---|
| 40 | expect(result).toBeUndefined();
|
|---|
| 41 | });
|
|---|
| 42 | it("should get all paths that matches requested module", function () {
|
|---|
| 43 | var result = (0, try_path_1.getPathsToTry)([".ts", ".tsx"], abosolutePathMappings, "longest/pre/fix/requested-module");
|
|---|
| 44 | // assert.deepEqual(result, [
|
|---|
| 45 | // // "longest/pre/fix/*"
|
|---|
| 46 | // { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
|
|---|
| 47 | // {
|
|---|
| 48 | // type: "extension",
|
|---|
| 49 | // path: join("/absolute", "base", "url", "foo2", "bar.ts"),
|
|---|
| 50 | // },
|
|---|
| 51 | // {
|
|---|
| 52 | // type: "extension",
|
|---|
| 53 | // path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
|
|---|
| 54 | // },
|
|---|
| 55 | // {
|
|---|
| 56 | // type: "package",
|
|---|
| 57 | // path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
|
|---|
| 58 | // },
|
|---|
| 59 | // {
|
|---|
| 60 | // type: "index",
|
|---|
| 61 | // path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
|
|---|
| 62 | // },
|
|---|
| 63 | // {
|
|---|
| 64 | // type: "index",
|
|---|
| 65 | // path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
|
|---|
| 66 | // },
|
|---|
| 67 | // // "*"
|
|---|
| 68 | // { type: "file", path: join("/absolute", "base", "url", "foo1") },
|
|---|
| 69 | // { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
|
|---|
| 70 | // { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
|
|---|
| 71 | // {
|
|---|
| 72 | // type: "package",
|
|---|
| 73 | // path: join("/absolute", "base", "url", "foo1", "package.json"),
|
|---|
| 74 | // },
|
|---|
| 75 | // {
|
|---|
| 76 | // type: "index",
|
|---|
| 77 | // path: join("/absolute", "base", "url", "foo1", "index.ts"),
|
|---|
| 78 | // },
|
|---|
| 79 | // {
|
|---|
| 80 | // type: "index",
|
|---|
| 81 | // path: join("/absolute", "base", "url", "foo1", "index.tsx"),
|
|---|
| 82 | // },
|
|---|
| 83 | // ]);
|
|---|
| 84 | expect(result).toEqual([
|
|---|
| 85 | // "longest/pre/fix/*"
|
|---|
| 86 | { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar") },
|
|---|
| 87 | {
|
|---|
| 88 | type: "extension",
|
|---|
| 89 | path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.ts"),
|
|---|
| 90 | },
|
|---|
| 91 | {
|
|---|
| 92 | type: "extension",
|
|---|
| 93 | path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.tsx"),
|
|---|
| 94 | },
|
|---|
| 95 | {
|
|---|
| 96 | type: "package",
|
|---|
| 97 | path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "package.json"),
|
|---|
| 98 | },
|
|---|
| 99 | {
|
|---|
| 100 | type: "index",
|
|---|
| 101 | path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.ts"),
|
|---|
| 102 | },
|
|---|
| 103 | {
|
|---|
| 104 | type: "index",
|
|---|
| 105 | path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
|
|---|
| 106 | },
|
|---|
| 107 | // "*"
|
|---|
| 108 | { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo1") },
|
|---|
| 109 | { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.ts") },
|
|---|
| 110 | { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.tsx") },
|
|---|
| 111 | {
|
|---|
| 112 | type: "package",
|
|---|
| 113 | path: (0, path_1.join)("/absolute", "base", "url", "foo1", "package.json"),
|
|---|
| 114 | },
|
|---|
| 115 | {
|
|---|
| 116 | type: "index",
|
|---|
| 117 | path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.ts"),
|
|---|
| 118 | },
|
|---|
| 119 | {
|
|---|
| 120 | type: "index",
|
|---|
| 121 | path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.tsx"),
|
|---|
| 122 | },
|
|---|
| 123 | ]);
|
|---|
| 124 | });
|
|---|
| 125 | it("should resolve paths starting with a slash", function () {
|
|---|
| 126 | var result = (0, try_path_1.getPathsToTry)([".ts"], abosolutePathMappingsStarstWithSlash, "/opt/utils");
|
|---|
| 127 | expect(result).toEqual([
|
|---|
| 128 | // "opt/*"
|
|---|
| 129 | {
|
|---|
| 130 | path: (0, path_1.join)("/absolute", "src", "aws-layer"),
|
|---|
| 131 | type: "file",
|
|---|
| 132 | },
|
|---|
| 133 | {
|
|---|
| 134 | path: (0, path_1.join)("/absolute", "src", "aws-layer.ts"),
|
|---|
| 135 | type: "extension",
|
|---|
| 136 | },
|
|---|
| 137 | {
|
|---|
| 138 | path: (0, path_1.join)("/absolute", "src", "aws-layer", "package.json"),
|
|---|
| 139 | type: "package",
|
|---|
| 140 | },
|
|---|
| 141 | {
|
|---|
| 142 | path: (0, path_1.join)("/absolute", "src", "aws-layer", "index.ts"),
|
|---|
| 143 | type: "index",
|
|---|
| 144 | },
|
|---|
| 145 | // "*"
|
|---|
| 146 | {
|
|---|
| 147 | path: (0, path_1.join)("/absolute", "src"),
|
|---|
| 148 | type: "file",
|
|---|
| 149 | },
|
|---|
| 150 | {
|
|---|
| 151 | path: (0, path_1.join)("/absolute", "src.ts"),
|
|---|
| 152 | type: "extension",
|
|---|
| 153 | },
|
|---|
| 154 | {
|
|---|
| 155 | path: (0, path_1.join)("/absolute", "src", "package.json"),
|
|---|
| 156 | type: "package",
|
|---|
| 157 | },
|
|---|
| 158 | {
|
|---|
| 159 | path: (0, path_1.join)("/absolute", "src", "index.ts"),
|
|---|
| 160 | type: "index",
|
|---|
| 161 | },
|
|---|
| 162 | ]);
|
|---|
| 163 | });
|
|---|
| 164 | });
|
|---|
| 165 | // describe("match-star", () => {
|
|---|
| 166 | // it("should match star in last position", () => {
|
|---|
| 167 | // const result = matchStar("lib/*", "lib/mylib");
|
|---|
| 168 | // assert.equal(result, "mylib");
|
|---|
| 169 | // });
|
|---|
| 170 | // it("should match star in first position", () => {
|
|---|
| 171 | // const result = matchStar("*/lib", "mylib/lib");
|
|---|
| 172 | // assert.equal(result, "mylib");
|
|---|
| 173 | // });
|
|---|
| 174 | // });
|
|---|
| 175 | //# sourceMappingURL=try-path.test.js.map |
|---|