Skip to content

Commit

Permalink
test: add basic WebAssembly test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stevekinney authored and MylesBorins committed Dec 11, 2017
1 parent 6f805c6 commit 113dd2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ rules:
inspector-check: error
## common module is mandatory in tests
required-modules: [error, common]

# Global scoped methods and vars
globals:
WebAssembly: false
Binary file added test/fixtures/test.wasm
Binary file not shown.
18 changes: 18 additions & 0 deletions test/parallel/test-wasm-simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

require('../common');

const assert = require('assert');
const fixtures = require('../common/fixtures');

const buffer = fixtures.readSync('test.wasm');

assert.ok(WebAssembly.validate(buffer), 'Buffer should be valid WebAssembly');

WebAssembly.instantiate(buffer, {}).then((results) => {
assert.strictEqual(
results.instance.exports.addTwo(10, 20),
30,
'Exported function should add two numbers.',
);
});

0 comments on commit 113dd2b

Please sign in to comment.