-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-tag.test.ts
175 lines (167 loc) · 5.72 KB
/
github-tag.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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", "github-tag.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("github tag for import_map", () => {
const testCases = [
{
title: "should accept raw.githubusercontent.com",
input: `{
"imports": {
"sample": "https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts",
}
}`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept pax.deno.dev",
input: `{
"imports": {
"sample": "https://pax.deno.dev/user/[email protected]/mod.ts",
}
}`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept omit 'mod.ts' when specify pax.deno.dev",
input: `{
"imports": {
"sample": "https://pax.deno.dev/user/[email protected]",
}
}`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept complex semver version",
input: `{
"imports": {
"sample": "https://raw.githubusercontent.com/user/repo/1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay/mod.ts"
}
}`,
currentValue: "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
depName: "user/repo",
},
{
title: "should accept un-semver version",
input: `{
"imports": {
"sample": "https://raw.githubusercontent.com/user/repo/sampleversion/mod.ts"
}
}`,
currentValue: "sampleversion",
depName: "user/repo",
},
];
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("github tag for js file", () => {
const testCases = [
{
title: "should accept raw.githubusercontent.com",
input: `import { sample } from "https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept pax.deno.dev",
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept omit 'mod.ts' when specify pax.deno.dev",
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept complex semver version",
input: `import { sample } from "https://raw.githubusercontent.com/user/repo/1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay/mod.ts"`,
currentValue: "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
depName: "user/repo",
},
{
title: "should accept un-semver version",
input: `import { sample } from "https://raw.githubusercontent.com/user/repo/sampleversion/mod.ts"`,
currentValue: "sampleversion",
depName: "user/repo",
},
{
title: "should accept raw.githubusercontent.com in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/1.0.0/mod.ts"`,
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept pax.deno.dev in //@deno-types",
currentValue: "1.0.0",
depName: "user/repo",
},
{
title:
"should accept omit 'mod.ts' when specify pax.deno.dev in //@deno-types",
currentValue: "1.0.0",
depName: "user/repo",
},
{
title: "should accept complex semver version in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay/mod.ts"`,
currentValue: "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay",
depName: "user/repo",
},
{
title: "should accept un-semver version in //@deno-types",
input: `// @deno-types="https://raw.githubusercontent.com/user/repo/sampleversion/mod.ts"`,
currentValue: "sampleversion",
depName: "user/repo",
},
{
title: "should accept un-semver version in //@ts-types",
input: `// @ts-types="https://raw.githubusercontent.com/user/repo/sampleversion/mod.ts"`,
currentValue: "sampleversion",
depName: "user/repo",
},
];
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);
});
});