-
Notifications
You must be signed in to change notification settings - Fork 12
/
wasm.ts
55 lines (50 loc) · 1.68 KB
/
wasm.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
import {
withGreeter,
withGreeterScope,
Greeter,
persistGreeterValue,
LanguageCode,
deleteGreeterValue,
} from "../source";
test("Calling wasm methods", async () => {
await withGreeter((greeterModule) => {
const greeter = new greeterModule.Greeter("Wasm");
expect(greeter.greet(greeterModule.LanguageCode.EN)).toBe("Hello, Wasm!");
});
});
// non-public helper functions for testing
import {
__getCurrentWasmScope,
__getCurrentWasmScopeStackSize,
} from "../source/wasmWrapper";
test("Scoping", async () => {
expect(__getCurrentWasmScopeStackSize()).toBe(0);
await withGreeter((greeterModule) => {
expect(__getCurrentWasmScopeStackSize()).toBe(1);
expect(__getCurrentWasmScope().length).toBe(0);
new greeterModule.Greeter("Outer");
expect(__getCurrentWasmScope().length).toBe(1);
withGreeterScope(() => {
expect(__getCurrentWasmScopeStackSize()).toBe(2);
expect(__getCurrentWasmScope().length).toBe(0);
new greeterModule.Greeter("Inner 1");
expect(__getCurrentWasmScope().length).toBe(1);
new greeterModule.Greeter("Inner 2");
expect(__getCurrentWasmScope().length).toBe(2);
});
expect(__getCurrentWasmScopeStackSize()).toBe(1);
});
expect(__getCurrentWasmScopeStackSize()).toBe(0);
});
test("Persisting values", async () => {
let greeter: Greeter;
let language: LanguageCode;
await withGreeter((greeterModule) => {
greeter = persistGreeterValue(new greeterModule.Greeter("Global"));
language = greeterModule.LanguageCode.EN;
expect(__getCurrentWasmScope().length).toBe(0);
}).then(() => {
expect(greeter.greet(language)).toBe("Hello, Global!");
deleteGreeterValue(greeter);
});
});