try-path-tests.ts
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { assert } from "chai";
import { getPathsToTry } from "../src/try-path";
import { join } from "path";
describe("mapping-entry", () => {
const abosolutePathMappings = [
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")]
},
{ pattern: "pre/fix/*", paths: [join("/absolute", "base", "url", "foo3")] },
{ pattern: "*", paths: [join("/absolute", "base", "url", "foo1")] }
];
it("should return no paths for relative requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
abosolutePathMappings,
"./requested-module"
);
assert.deepEqual(result, undefined);
});
it("should return no paths if no pattern match the requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
[
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")]
},
{
pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")]
}
],
"requested-module"
);
assert.deepEqual(result, undefined);
});
it("should get all paths that matches requested module", () => {
const result = 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")
}
]);
});
});
// 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");
// });
// });