-
Notifications
You must be signed in to change notification settings - Fork 22
/
versions.test.ts
69 lines (64 loc) · 1.72 KB
/
versions.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
import { assertThrows } from "https://deno.land/std@0.198.0/assert/assert_throws.ts";
import { verifyVersions } from "./versions.ts";
const correctMap: { [name: string]: string } = {
"wasm-bindgen": "0.2.87",
"wasm-bindgen-futures": "0.4.37",
"js-sys": "0.3.64",
"web-sys": "0.3.64",
};
Deno.test("should verify when all correct", () => {
const crate = {
name: "test-crate",
getDependencyVersion(depName: string) {
return correctMap[depName];
},
};
verifyVersions(crate);
});
Deno.test("should verify when only wasm-bindgen version", () => {
const crate = {
name: "test-crate",
getDependencyVersion(depName: string) {
return {
"wasm-bindgen": correctMap["wasm-bindgen"],
}[depName];
},
};
verifyVersions(crate);
});
Deno.test("should error when no wasm-bindgen", () => {
const crate = {
name: "test-crate",
getDependencyVersion(_depName: string) {
return undefined;
},
};
assertThrows(
() => verifyVersions(crate),
Error,
`The crate 'test-crate' must have a dependency on wasm-bindgen ${
correctMap["wasm-bindgen"]
} (found <NOT FOUND>).`,
);
});
Deno.test("should error when has incorrect dependency", () => {
const crateNames = Object.keys(correctMap);
for (const crateName of crateNames) {
const crate = {
name: "test-crate",
getDependencyVersion(depName: string) {
return {
"wasm-bindgen": correctMap["wasm-bindgen"],
[crateName]: "0.0.1",
}[depName];
},
};
assertThrows(
() => verifyVersions(crate),
Error,
`The crate 'test-crate' must have a dependency on ${crateName} ${
correctMap[crateName]
} (found 0.0.1).`,
);
}
});