-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeno-land.test.ts
136 lines (128 loc) · 4.27 KB
/
deno-land.test.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { expect, expectTypeOf, describe, it } from "vitest";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import RE2 from "re2";
const repositoryRoot = dirname(dirname(__dirname));
const file = readFileSync(
join(repositoryRoot, "deno", "deno-land.json"),
).toString();
const config: string[][] = JSON.parse(file)?.customManagers?.map(
(manager: { matchStrings?: string[] }) => manager.matchStrings,
);
const regexps: RE2[][] = config.map((matchStrings: string[]) =>
matchStrings.map((re) => new RE2(re)),
);
describe("check configuration existing", () => {
it("should be array", () => {
expect(Array.isArray(config));
});
it("should be array of regexp", () => {
expectTypeOf(regexps).toEqualTypeOf<RE2[][]>();
});
});
describe("deno.land for import map", () => {
const testCases = [
{
title: "should be accept deno.land/std",
input: `{
"import_map": {
"std": "https://deno.land/[email protected]",
}
}`,
currentValue: "0.204.0",
depName: "https://deno.land/std",
},
{
title: "should be accept if include 'v' in version",
input: `{
"import_map": {
"path": "https://deno.land/[email protected]/path/mod.ts",
}
}`,
currentValue: "v0.204.0",
depName: "https://deno.land/std",
},
{
title: "should be accept deno.land/x",
input: `{
"import_map": {
"some": "https://deno.land/x/[email protected]",
}
}`,
currentValue: "v0.1.0",
depName: "https://deno.land/x/some_module",
},
] as const;
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[0].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});
describe("deno.land for import map", () => {
const testCases = [
{
title: "should accept deno.land/std",
currentValue: "0.204.0",
depName: "https://deno.land/std",
},
{
title: "should accept export specifier",
currentValue: "0.204.0",
depName: "https://deno.land/std",
},
{
title: "should accept if 'v' in version",
currentValue: "v1.0.0",
depName: "https://deno.land/std",
},
{
title: "should accept deno.land/x",
currentValue: "0.1.0",
depName: "https://deno.land/x/some_module",
},
{
title: "should accept deno.land/std in //@deno-types",
currentValue: "0.204.0",
depName: "https://deno.land/std",
},
{
title: "should accept if 'v' in version in //@deno-types",
currentValue: "v1.0.0",
depName: "https://deno.land/std",
},
{
title: "should accept deno.land/x in //@deno-types",
currentValue: "0.1.0",
depName: "https://deno.land/x/some_module",
},
{
title: "should accept deno.land/x in //@ts-types",
currentValue: "1.0.0",
depName: "https://deno.land/x/some_module",
},
] as const;
it.each(testCases)("$title", ({ input, currentValue, depName }) => {
const re = regexps[1].map((r) => new RegExp(r, "gm"));
const matches = re
.map((r) => Array.from(input.matchAll(r)).map((e) => e.groups))
.filter((match) => match.length !== 0)
.flat();
expect(matches.length).toBe(1);
expect(matches[0]?.currentValue).toBe(currentValue);
expect(matches[0]?.depName).toBe(depName);
});
});