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: nodejs#16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
  • Loading branch information
stevekinney authored and addaleax committed Nov 15, 2017
1 parent 7d8fe7d commit 74e7a4a
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 74e7a4a

Please sign in to comment.