Parallel Letter Frequency
This commit is contained in:
parent
3ca9867a11
commit
af89290bbc
45 changed files with 2862 additions and 0 deletions
40
wasm/hello-world/hello-world.spec.js
Normal file
40
wasm/hello-world/hello-world.spec.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { compileWat, WasmRunner } from "@exercism/wasm-lib";
|
||||
|
||||
let wasmModule;
|
||||
let currentInstance;
|
||||
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
const watPath = new URL("./hello-world.wat", import.meta.url);
|
||||
const { buffer } = await compileWat(watPath);
|
||||
wasmModule = await WebAssembly.compile(buffer);
|
||||
} catch (err) {
|
||||
console.log(`Error compiling *.wat: \n${err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
describe("Hello World", () => {
|
||||
beforeEach(async () => {
|
||||
currentInstance = null;
|
||||
|
||||
if (!wasmModule) {
|
||||
return Promise.reject();
|
||||
}
|
||||
try {
|
||||
currentInstance = await new WasmRunner(wasmModule);
|
||||
return Promise.resolve();
|
||||
} catch (err) {
|
||||
console.log(`Error instantiating WebAssembly module: ${err}`);
|
||||
return Promise.reject();
|
||||
}
|
||||
});
|
||||
|
||||
test("Say Hi!", () => {
|
||||
expect(currentInstance).toBeTruthy();
|
||||
const [offset, length] = currentInstance.exports.hello();
|
||||
expect(length).toBe(13);
|
||||
const greeting = currentInstance.get_mem_as_utf8(offset, length);
|
||||
expect(greeting).toBe("Hello, World!");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue