mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Refactor hello-web example for possible future automated testing
For now there's a Node.js test that works, but we're not actually running it in CI, and Node is not a dependency of the project.
This commit is contained in:
parent
c20a2e5740
commit
11f8652ff6
3 changed files with 48 additions and 12 deletions
25
examples/hello-web/test-node.js
Normal file
25
examples/hello-web/test-node.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Node.js test file for hello-web example
|
||||
* We are not running this in CI currently, and Node.js is not a Roc dependency.
|
||||
* But if you happen to have it, you can run this.
|
||||
*/
|
||||
|
||||
// Node doesn't have the fetch API
|
||||
const fs = require("fs/promises");
|
||||
global.fetch = (filename) =>
|
||||
fs.readFile(filename).then((buffer) => ({
|
||||
arrayBuffer() {
|
||||
return buffer;
|
||||
},
|
||||
}));
|
||||
|
||||
const { roc_web_platform_run } = require("./platform/host");
|
||||
|
||||
roc_web_platform_run("./hello-world.wasm", (string_from_roc) => {
|
||||
const expected = "Hello, World!";
|
||||
if (string_from_roc !== expected) {
|
||||
console.error(`Expected "${expected}", but got "${string_from_roc}"`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("OK");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue