Skip to content

Commit 113dd2b

Browse files
stevekinneyMylesBorins
authored andcommitted
test: add basic WebAssembly test
Tests a basic WebAssembly module that adds two numbers. wasm example from the WebAssembly/wabt repo licensed Apache 2.0. Refs: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/demo/wat2wasm/examples.js#L27-L32 PR-URL: #16760 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 6f805c6 commit 113dd2b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

test/.eslintrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ rules:
1515
inspector-check: error
1616
## common module is mandatory in tests
1717
required-modules: [error, common]
18+
19+
# Global scoped methods and vars
20+
globals:
21+
WebAssembly: false

test/fixtures/test.wasm

44 Bytes
Binary file not shown.

test/parallel/test-wasm-simple.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const fixtures = require('../common/fixtures');
7+
8+
const buffer = fixtures.readSync('test.wasm');
9+
10+
assert.ok(WebAssembly.validate(buffer), 'Buffer should be valid WebAssembly');
11+
12+
WebAssembly.instantiate(buffer, {}).then((results) => {
13+
assert.strictEqual(
14+
results.instance.exports.addTwo(10, 20),
15+
30,
16+
'Exported function should add two numbers.',
17+
);
18+
});

0 commit comments

Comments
 (0)