-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathwasm.js
120 lines (110 loc) · 2.9 KB
/
wasm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import assert from 'assert';
import path from 'path';
import {assertBundleTree, bundle, deferred, run} from '@parcel/test-utils';
describe.skip('wasm', function () {
if (typeof WebAssembly === 'undefined') {
return;
}
for (const target of ['browser', 'node']) {
describe(`--target=${target}`, function () {
it('should preload a wasm file for a sync require', async function () {
let b = await bundle(
path.join(__dirname, '/integration/wasm-sync/index.js'),
{
target,
},
);
await assertBundleTree(b, {
name: 'index.js',
assets: [
'index.js',
'bundle-loader.js',
'bundle-url.js',
'wasm-loader.js',
],
childBundles: [
{
type: 'wasm',
assets: ['add.wasm'],
childBundles: [],
},
{
type: 'map',
},
],
});
let promise = deferred();
await run(b, {output: promise.resolve}, {require: false});
assert.equal(await promise, 5);
});
it('should load a wasm file asynchronously with dynamic import', async function () {
let b = await bundle(
path.join(__dirname, '/integration/wasm-async/index.js'),
{
target,
},
);
await assertBundleTree(b, {
name: 'index.js',
assets: [
'index.js',
'bundle-loader.js',
'bundle-url.js',
'wasm-loader.js',
],
childBundles: [
{
type: 'wasm',
assets: ['add.wasm'],
childBundles: [],
},
{
type: 'map',
},
],
});
var res = await run(b);
assert.equal(await res, 5);
});
it('should load a wasm file in parallel with a dynamic JS import', async function () {
let b = await bundle(
path.join(__dirname, '/integration/wasm-dynamic/index.js'),
{
target,
},
);
await assertBundleTree(b, {
name: 'index.js',
assets: [
'index.js',
'bundle-loader.js',
'bundle-url.js',
'js-loader.js',
'wasm-loader.js',
],
childBundles: [
{
type: 'js',
assets: ['dynamic.js'],
childBundles: [
{
type: 'wasm',
assets: ['add.wasm'],
childBundles: [],
},
{
type: 'map',
},
],
},
{
type: 'map',
},
],
});
var res = await run(b);
assert.equal(await res, 5);
});
});
}
});