-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugins.test.ts
More file actions
102 lines (97 loc) · 3.69 KB
/
plugins.test.ts
File metadata and controls
102 lines (97 loc) · 3.69 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
import { assertEquals } from "https://deno.land/std@0.106.0/testing/asserts.ts";
import { pluginResolvers } 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.tryGetVersionFromSchemaUrl!(new URL("https://plugins.dprint.dev/schemas/typescript-0.5.0.json")),
"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.tryGetVersionFromSchemaUrl!(new URL("https://plugins.dprint.dev/schemas/json-0.5.0.json")),
"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.tryGetVersionFromSchemaUrl!(new URL("https://plugins.dprint.dev/schemas/markdown-0.5.0.json")),
"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.tryGetVersionFromSchemaUrl!(new URL("https://plugins.dprint.dev/schemas/toml-0.5.0.json")),
"0.5.0",
);
});
function getResolverByName(name: string) {
const url = new URL(`https://plugins.dprint.dev/${name}-0.5.0.wasm`);
const resolver = pluginResolvers.find(r => r.tryGetVersion(url) != null);
if (!resolver) {
throw new Error("Not found.");
}
return resolver;
}