Skip to content

Commit 18d1df9

Browse files
authored
Merge pull request webpack#7324 from webpack/wasm/more-tests
add all examples from the WebAssembly explorer as tests
2 parents f59526b + cbbe6f8 commit 18d1df9

File tree

19 files changed

+140
-0
lines changed

19 files changed

+140
-0
lines changed
156 Bytes
Binary file not shown.
531 Bytes
Binary file not shown.
154 Bytes
Binary file not shown.
290 Bytes
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
it("Q_rsqrt should work", function() {
2+
return import("./Q_rsqrt.wasm").then(function(wasm) {
3+
const result = wasm._Z7Q_rsqrtf(1/1764);
4+
expect(result).toBeGreaterThan(41.9);
5+
expect(result).toBeLessThan(42.1);
6+
});
7+
});
8+
9+
it("testFunction should work", function() {
10+
return import("./testFunction.wasm").then(function(wasm) {
11+
const view = new Int32Array(wasm.memory.buffer);
12+
view[0] = 123;
13+
view[1] = 1;
14+
view[2] = 2;
15+
view[3] = 3;
16+
const result = wasm._Z12testFunctionPii(4, 3);
17+
expect(result).toEqual(6);
18+
});
19+
});
20+
21+
it("fact should work", function() {
22+
return import("./fact.wasm").then(function(wasm) {
23+
const result = wasm._Z4facti(11);
24+
expect(result).toEqual(39916800);
25+
});
26+
});
27+
28+
it("popcnt should work", function() {
29+
return import("./popcnt.wasm").then(function(wasm) {
30+
expect(wasm.main(0xF0F)).toEqual(16);
31+
expect(wasm._Z5countj(0xF0F)).toEqual(8);
32+
});
33+
});
34+
35+
it("fast-math should work", function() {
36+
return import("./fast-math.wasm").then(function(wasm) {
37+
expect(wasm._Z3food(42)).toEqual(14);
38+
expect(wasm._Z9maybe_mindd(42, 24)).toEqual(24);
39+
expect(wasm._Z8call_powd(42)).toEqual(9682651996416);
40+
expect(wasm._Z6do_powd(42)).toEqual(9682651996416);
41+
expect(wasm._Z6factorddd(42, 42, 42)).toEqual(3528);
42+
});
43+
});
44+
45+
it("duff should work", function() {
46+
return import("./duff.wasm").then(function(wasm) {
47+
const view = new Uint8Array(wasm.memory.buffer);
48+
view[0] = 123;
49+
for(let i = 1; i < 100; i++)
50+
view[i] = i;
51+
const result = wasm._Z4sendPcS_m(200, 1, 100);
52+
for(let i = 1; i < 100; i++)
53+
expect(view[199 + i]).toEqual(i);
54+
});
55+
});

test/cases/wasm/wasm-explorer-examples-async/node_modules/env.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
120 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
2+
3+
module.exports = function(config) {
4+
return supportsWebAssembly();
5+
};
154 Bytes
Binary file not shown.
156 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)