Skip to content

Commit 4cd0cf5

Browse files
authored
Merge pull request webpack#7379 from xtuc/refactor-use-wast-in-tests
switch to tests to wast
2 parents c513cac + 00eafa6 commit 4cd0cf5

32 files changed

+115
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"url-loader": "^0.6.2",
7373
"val-loader": "^1.0.2",
7474
"vm-browserify": "~0.0.0",
75+
"wast-loader": "^1.5.5",
7576
"webpack-dev-middleware": "^1.9.0",
7677
"worker-loader": "^1.1.1",
7778
"xxhashjs": "^0.2.1"

test/TestCases.template.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ const describeCases = config => {
143143
{
144144
test: /\.pug/,
145145
loader: "pug-loader"
146+
},
147+
{
148+
test: /\.wat$/i,
149+
loader: "wast-loader",
150+
type: "webassembly/experimental"
146151
}
147152
]
148153
},

test/cases/wasm/import-wasm-wasm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it("should allow to run a WebAssembly module with imports", function() {
2-
return import("./wasm.wasm").then(function(wasm) {
2+
return import("./wasm.wat").then(function(wasm) {
33
const result = wasm.addNumber(20);
44
expect(result).toEqual(42);
55
});
-78 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./wasm2.wat" "getNumber" (func $./wasm2.wasm.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./wasm2.wasm.getNumber))))
9+
-42 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(func $getNumber (export "getNumber") (type $t0) (result i32)
4+
(i32.const 22)))
5+

test/cases/wasm/imports-circular/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addNumber } from "./wasm.wasm";
1+
import { addNumber } from "./wasm.wat";
22

33
export var result = addNumber(22);
44

-74 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./module.getNumber))))
9+

test/cases/wasm/imports/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it("should allow to run a WebAssembly module with imports", function() {
2-
return import("./wasm.wasm?1").then(function(wasm) {
2+
return import("./wasm.wat?1").then(function(wasm) {
33
const result = wasm.addNumber(3);
44
expect(result).toEqual(11);
55
});

test/cases/wasm/imports/wasm.wasm

-74 Bytes
Binary file not shown.

test/cases/wasm/imports/wasm.wat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./module.getNumber))))
9+
-117 Bytes
Binary file not shown.

test/cases/wasm/memory/mem-access.wat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32)))
4+
(import "./memory.wat" "memory" (memory $./memory.wasm.memory 1))
5+
(func $get (export "get") (type $t0) (result i32)
6+
(i32.load
7+
(i32.const 0)))
8+
(func $set (export "set") (type $t1) (param $p i32)
9+
(i32.store
10+
(i32.const 0)
11+
(get_local $p))))

test/cases/wasm/memory/memory.wasm

-47 Bytes
Binary file not shown.

test/cases/wasm/memory/memory.wat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(module
2+
(memory $memory (export "memory") 1)
3+
(data (i32.const 12) "\00\00\00\00"))
4+

test/cases/wasm/memory/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as a1 from "./mem-access.wasm?1";
2-
import * as a2 from "./mem-access.wasm?2";
1+
import * as a1 from "./mem-access.wat?1";
2+
import * as a2 from "./mem-access.wat?2";
33

44
a1.set(42);
55
export const x1 = a1.get();

test/cases/wasm/order/a.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { trackA, results } from "./tracker";
22
import "./b.js";
3-
import "./wasm.wasm";
3+
import "./wasm.wat";
44

55
trackA();
66

test/cases/wasm/order/wasm.wasm

-82 Bytes
Binary file not shown.

test/cases/wasm/simple/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ it("should allow to run a WebAssembly module (indirect)", function() {
66
});
77

88
it("should allow to run a WebAssembly module (direct)", function() {
9-
return import("./wasm.wasm?2").then(function(wasm) {
9+
return import("./wasm.wat?2").then(function(wasm) {
1010
const result = wasm.add(wasm.getNumber(), 2);
1111
expect(result).toEqual(42);
1212
});

test/cases/wasm/simple/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { add, getNumber } from "./wasm.wasm?1";
1+
import { add, getNumber } from "./wasm.wat?1";
22

33
export function run() {
44
return add(getNumber(), 2);

test/cases/wasm/simple/wasm.wasm

-63 Bytes
Binary file not shown.

test/cases/wasm/simple/wasm.wat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(module
2+
(type $t0 (func (param i32 i32) (result i32)))
3+
(type $t1 (func (result i32)))
4+
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
5+
(i32.add
6+
(get_local $p0)
7+
(get_local $p1)))
8+
(func $getNumber (export "getNumber") (type $t1) (result i32)
9+
(i32.const 40)))
10+

test/cases/wasm/table/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
const UNKNOWN_FUNCTION_TABLE = /invalid index into function table|invalid function/;
33

44
it("should support tables", function() {
5-
return import("./wasm-table.wasm").then(function(wasm) {
5+
return import("./wasm-table.wat").then(function(wasm) {
66
expect(wasm.callByIndex(0)).toEqual(42);
77
expect(wasm.callByIndex(1)).toEqual(13);
88
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
99
});
1010
});
1111

1212
it("should support exported tables", function() {
13-
return import("./wasm-table-export.wasm").then(function(wasm) {
13+
return import("./wasm-table-export.wat").then(function(wasm) {
1414
expect(wasm.table).toBeInstanceOf(WebAssembly.Table);
1515
expect(wasm.table.length).toBe(2);
1616
const e0 = wasm.table.get(0);
@@ -23,7 +23,7 @@ it("should support exported tables", function() {
2323
});
2424

2525
it("should support imported tables", function() {
26-
return import("./wasm-table-imported.wasm").then(function(wasm) {
26+
return import("./wasm-table-imported.wat").then(function(wasm) {
2727
expect(wasm.callByIndex(0)).toEqual(42);
2828
expect(wasm.callByIndex(1)).toEqual(13);
2929
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
-85 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(func $f1 (type $t0) (result i32)
4+
(i32.const 42))
5+
(func $f2 (type $t0) (result i32)
6+
(i32.const 13))
7+
(table $table (export "table") 2 anyfunc)
8+
(elem (i32.const 0) $f1 $f2))
9+
-105 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./wasm-table-export.wat" "table" (table $./wasm-table-export.wasm.table 2 anyfunc))
5+
(func $callByIndex (export "callByIndex") (type $t1) (param $i i32) (result i32)
6+
(call_indirect (type $t0)
7+
(get_local $i))))
8+

test/cases/wasm/table/wasm-table.wasm

-84 Bytes
Binary file not shown.

test/cases/wasm/table/wasm-table.wat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (result i32)))
4+
(type $t2 (func (param i32) (result i32)))
5+
(func $f0 (type $t0) (result i32)
6+
(i32.const 42))
7+
(func $f1 (type $t0) (result i32)
8+
(i32.const 13))
9+
(func $callByIndex (export "callByIndex") (type $t2) (param $p0 i32) (result i32)
10+
(call_indirect (type $t1)
11+
(get_local $p0)))
12+
(table $T0 2 anyfunc)
13+
(elem (i32.const 0) $f0 $f1))
14+

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,12 +6174,22 @@ w3c-hr-time@^1.0.1:
61746174
dependencies:
61756175
browser-process-hrtime "^0.1.2"
61766176

6177+
wabt@^1.0.0:
6178+
version "1.0.0"
6179+
resolved "https://registry.yarnpkg.com/wabt/-/wabt-1.0.0.tgz#f33a5c4a6405370ec80ba97e782d092f1d599ff4"
6180+
61776181
walker@~1.0.5:
61786182
version "1.0.7"
61796183
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
61806184
dependencies:
61816185
makeerror "1.0.x"
61826186

6187+
wast-loader@^1.5.5:
6188+
version "1.5.5"
6189+
resolved "https://registry.yarnpkg.com/wast-loader/-/wast-loader-1.5.5.tgz#a1d6cdc468b6963a6e479de683dc74755f09b81a"
6190+
dependencies:
6191+
wabt "^1.0.0"
6192+
61836193
watch@~0.18.0:
61846194
version "0.18.0"
61856195
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"

0 commit comments

Comments
 (0)