-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugins.test.ts
More file actions
160 lines (151 loc) · 5.42 KB
/
plugins.test.ts
File metadata and controls
160 lines (151 loc) · 5.42 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
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
import { assertEquals } from "./deps.test.ts";
import { pluginResolvers, tryResolvePluginUrl, tryResolveSchemaUrl } from "./plugins.ts";
Deno.test("should get correct info for typescript resolver", () => {
const resolver = getResolverByName("typescript");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.1.0/typescript-0.1.0.wasm",
);
assertEquals(
resolver.getRedirectUrl("0.44.0"),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.44.0/typescript-0.44.0.wasm",
);
// file name changed here
assertEquals(
resolver.getRedirectUrl("0.44.1"),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.44.1/typescript.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/typescript-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("should get correct info for json resolver", () => {
const resolver = getResolverByName("json");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-json/releases/download/0.1.0/json-0.1.0.wasm",
);
assertEquals(
resolver.getRedirectUrl("0.10.1"),
"https://github.com/dprint/dprint-plugin-json/releases/download/0.10.1/json-0.10.1.wasm",
);
// file name changed here
assertEquals(
resolver.getRedirectUrl("0.10.2"),
"https://github.com/dprint/dprint-plugin-json/releases/download/0.10.2/json.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-json/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/json-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("should get correct info for markdown resolver", () => {
const resolver = getResolverByName("markdown");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.1.0/markdown-0.1.0.wasm",
);
assertEquals(
resolver.getRedirectUrl("0.7.0"),
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.7.0/markdown-0.7.0.wasm",
);
// file name changed here
assertEquals(
resolver.getRedirectUrl("0.7.1"),
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.7.1/markdown.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/markdown-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("should get correct info for toml resolver", () => {
const resolver = getResolverByName("toml");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-toml/releases/download/0.1.0/toml.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-toml/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/toml-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("should get correct info for dockerfile resolver", () => {
const resolver = getResolverByName("dockerfile");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-dockerfile/releases/download/0.1.0/dockerfile.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-dockerfile/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/dockerfile-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("should get correct info for sql resolver", () => {
const resolver = getResolverByName("sql");
assertEquals(
resolver.getRedirectUrl("0.1.0"),
"https://github.com/dprint/dprint-plugin-sql/releases/download/0.1.0/sql.wasm",
);
assertEquals(
resolver.getSchemaUrl!("0.1.0"),
"https://github.com/dprint/dprint-plugin-sql/releases/download/0.1.0/schema.json",
);
assertEquals(
resolver.schemaVersionUrlPattern!
.exec(new URL("https://plugins.dprint.dev/schemas/sql-0.5.0.json"))
?.pathname.groups[0],
"0.5.0",
);
});
Deno.test("tryResolvePluginUrl", () => {
assertEquals(
tryResolvePluginUrl(new URL("https://plugins.dprint.dev/typescript-1.2.3.wasm")),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/1.2.3/typescript.wasm",
);
});
Deno.test("tryResolveSchemaUrl", () => {
assertEquals(
tryResolveSchemaUrl(new URL("https://plugins.dprint.dev/schemas/typescript-1.2.3.json")),
"https://github.com/dprint/dprint-plugin-typescript/releases/download/1.2.3/schema.json",
);
});
function getResolverByName(name: string) {
const url = new URL(`https://plugins.dprint.dev/${name}-0.5.0.wasm`);
const resolver = pluginResolvers.find(r => r.versionPattern.exec(url)?.pathname.groups[0] != null);
if (!resolver) {
throw new Error("Not found.");
}
return resolver;
}