From 71036dd75160892dc6b82c59b6c9a18626b0fbca Mon Sep 17 00:00:00 2001 From: Steve Kinney Date: Sat, 4 Nov 2017 16:08:37 -0600 Subject: [PATCH] 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/master/demo/wat2wasm/examples.js#L27-L32 --- test/.eslintrc.yaml | 4 ++++ test/fixtures/test.wasm | Bin 0 -> 44 bytes test/parallel/test-wasm-simple.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/fixtures/test.wasm create mode 100644 test/parallel/test-wasm-simple.js diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index 6be0ca4e3f83bc..aa320996aa4b16 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -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 diff --git a/test/fixtures/test.wasm b/test/fixtures/test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..8b19588df228b76c6747d04aee091cbe268592d0 GIT binary patch literal 44 zcmZQbEY4+QU|?WmXG~zKuV<`hW@2Pu=VD|_Oi2kT&u3uZ;$&oJP+(AC%;E+BoDK$l literal 0 HcmV?d00001 diff --git a/test/parallel/test-wasm-simple.js b/test/parallel/test-wasm-simple.js new file mode 100644 index 00000000000000..6227875fd8a9df --- /dev/null +++ b/test/parallel/test-wasm-simple.js @@ -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.', + ); +});