-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod_test.ts
39 lines (36 loc) · 949 Bytes
/
mod_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
import { assert } from "@std/assert";
import { assertSpyCalls, stub } from "@std/testing/mock";
import { forceInstantiateWasm, MediaType, transpile } from "./mod.ts";
Deno.test({
name: "forceInstantiateWasm",
async fn() {
await forceInstantiateWasm();
const start = Date.now();
await transpile(
"function foo(arg: string): string {return arg}",
new URL("file:///src.ts"),
MediaType.TypeScript,
);
const time = Date.now() - start;
assert(time < 100, `transpile() took ${time} ms`);
},
});
Deno.test({
name: "forceInstantiateWasm - failed to load wasm",
async fn() {
// Don't throw an error when transpile() throws
const fetchStub = stub(
URL.prototype,
"toString",
() => {
throw new Error("load fail!!");
},
);
try {
await forceInstantiateWasm();
assertSpyCalls(fetchStub, 1);
} finally {
fetchStub.restore();
}
},
});