123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var try_path_1 = require("../try-path");
- var path_1 = require("path");
- describe("mapping-entry", function () {
- var abosolutePathMappings = [
- {
- pattern: "longest/pre/fix/*",
- paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
- },
- { pattern: "pre/fix/*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")] },
- { pattern: "*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo1")] },
- ];
- var abosolutePathMappingsStarstWithSlash = [
- {
- pattern: "/opt/*",
- paths: [(0, path_1.join)("/absolute", "src", "aws-layer")],
- },
- {
- pattern: "*",
- paths: [(0, path_1.join)("/absolute", "src")],
- },
- ];
- it("should return no paths for relative requested module", function () {
- var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], abosolutePathMappings, "./requested-module");
- // assert.deepEqual(result, undefined);
- expect(result).toBeUndefined();
- });
- it("should return no paths if no pattern match the requested module", function () {
- var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], [
- {
- pattern: "longest/pre/fix/*",
- paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
- },
- {
- pattern: "pre/fix/*",
- paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
- },
- ], "requested-module");
- expect(result).toBeUndefined();
- });
- it("should get all paths that matches requested module", function () {
- var result = (0, try_path_1.getPathsToTry)([".ts", ".tsx"], abosolutePathMappings, "longest/pre/fix/requested-module");
- // assert.deepEqual(result, [
- // // "longest/pre/fix/*"
- // { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
- // {
- // type: "extension",
- // path: join("/absolute", "base", "url", "foo2", "bar.ts"),
- // },
- // {
- // type: "extension",
- // path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
- // },
- // {
- // type: "package",
- // path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
- // },
- // {
- // type: "index",
- // path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
- // },
- // {
- // type: "index",
- // path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
- // },
- // // "*"
- // { type: "file", path: join("/absolute", "base", "url", "foo1") },
- // { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
- // { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
- // {
- // type: "package",
- // path: join("/absolute", "base", "url", "foo1", "package.json"),
- // },
- // {
- // type: "index",
- // path: join("/absolute", "base", "url", "foo1", "index.ts"),
- // },
- // {
- // type: "index",
- // path: join("/absolute", "base", "url", "foo1", "index.tsx"),
- // },
- // ]);
- expect(result).toEqual([
- // "longest/pre/fix/*"
- { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar") },
- {
- type: "extension",
- path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.ts"),
- },
- {
- type: "extension",
- path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.tsx"),
- },
- {
- type: "package",
- path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "package.json"),
- },
- {
- type: "index",
- path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.ts"),
- },
- {
- type: "index",
- path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
- },
- // "*"
- { type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo1") },
- { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.ts") },
- { type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.tsx") },
- {
- type: "package",
- path: (0, path_1.join)("/absolute", "base", "url", "foo1", "package.json"),
- },
- {
- type: "index",
- path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.ts"),
- },
- {
- type: "index",
- path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.tsx"),
- },
- ]);
- });
- it("should resolve paths starting with a slash", function () {
- var result = (0, try_path_1.getPathsToTry)([".ts"], abosolutePathMappingsStarstWithSlash, "/opt/utils");
- expect(result).toEqual([
- // "opt/*"
- {
- path: (0, path_1.join)("/absolute", "src", "aws-layer"),
- type: "file",
- },
- {
- path: (0, path_1.join)("/absolute", "src", "aws-layer.ts"),
- type: "extension",
- },
- {
- path: (0, path_1.join)("/absolute", "src", "aws-layer", "package.json"),
- type: "package",
- },
- {
- path: (0, path_1.join)("/absolute", "src", "aws-layer", "index.ts"),
- type: "index",
- },
- // "*"
- {
- path: (0, path_1.join)("/absolute", "src"),
- type: "file",
- },
- {
- path: (0, path_1.join)("/absolute", "src.ts"),
- type: "extension",
- },
- {
- path: (0, path_1.join)("/absolute", "src", "package.json"),
- type: "package",
- },
- {
- path: (0, path_1.join)("/absolute", "src", "index.ts"),
- type: "index",
- },
- ]);
- });
- });
- // describe("match-star", () => {
- // it("should match star in last position", () => {
- // const result = matchStar("lib/*", "lib/mylib");
- // assert.equal(result, "mylib");
- // });
- // it("should match star in first position", () => {
- // const result = matchStar("*/lib", "mylib/lib");
- // assert.equal(result, "mylib");
- // });
- // });
- //# sourceMappingURL=try-path.test.js.map
|