-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugins.test.ts
87 lines (83 loc) · 2.96 KB
/
plugins.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
import { assertEquals } from "./deps.test.ts";
import { tryResolveLatestJson } from "./plugins.ts";
import { getLatestReleaseInfo } from "./utils/github.ts";
Deno.test("tryResolveUserLatestJson", async () => {
// non-matching
assertEquals(
await tryResolveLatestJson(
new URL("https://plugins.dprint.dev/dsherret/latest.json"),
),
undefined,
);
assertEquals(
await tryResolveLatestJson(
new URL("https://plugins.dprint.dev/dsherret/non-existent/latest.json"),
),
404,
);
// dprint repo
{
const result = await getValidResultForUrl("https://plugins.dprint.dev/dprint/typescript/latest.json");
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName,
checksum: undefined,
});
}
// dprint repo full name
{
const result = await getValidResultForUrl(
"https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json",
);
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript");
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName,
checksum: undefined,
});
}
// non-dprint repo
{
const result = await getValidResultForUrl("https://plugins.dprint.dev/malobre/vue/latest.json");
const releaseInfo = await getLatestReleaseInfo("malobre", "dprint-plugin-vue");
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName.replace(/^v/, ""),
checksum: undefined,
});
}
// non-dprint repo full name
{
const result = await getValidResultForUrl("https://plugins.dprint.dev/malobre/dprint-plugin-vue/latest.json");
const releaseInfo = await getLatestReleaseInfo("malobre", "dprint-plugin-vue");
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`,
version: releaseInfo!.tagName.replace(/^v/, ""),
checksum: undefined,
});
}
// process plugin repo
{
const result = await getValidResultForUrl("https://plugins.dprint.dev/dprint/prettier/latest.json");
const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-prettier");
assertEquals(releaseInfo?.checksum?.length, 64);
assertEquals(result, {
schemaVersion: 1,
url: `https://plugins.dprint.dev/prettier-${releaseInfo!.tagName}.json`,
version: releaseInfo!.tagName,
checksum: releaseInfo!.checksum,
});
}
async function getValidResultForUrl(url: string) {
const result = await tryResolveLatestJson(new URL(url))!;
if (result == null || result === 404) {
throw new Error("Expected result.");
}
return result;
}
});