Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: eager loading of wasm in jest environment #1246

Merged
merged 1 commit into from Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/client.js
Expand Up @@ -408,6 +408,8 @@ const constants = require('./llhttp/constants')
const EMPTY_BUF = Buffer.alloc(0)

async function lazyllhttp () {
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('./llhttp/llhttp.wasm.js') : undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I don't understand? What's the purpose? This isn't very eager.


let mod
try {
mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd.wasm.js'), 'base64'))
Expand All @@ -418,7 +420,7 @@ async function lazyllhttp () {
// being enabled, but the occurring of this other error
// * https://github.com/emscripten-core/emscripten/issues/11495
// got me to remove that check to avoid breaking Node 12.
mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp.wasm.js'), 'base64'))
mod = await WebAssembly.compile(Buffer.from(llhttpWasmData || require('./llhttp/llhttp.wasm.js'), 'base64'))
}

return await WebAssembly.instantiate(mod, {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -48,7 +48,7 @@
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:jest && tsd",
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
"test:fetch": "node scripts/verifyVersion.js 16 || tap test/fetch/*.js",
"test:jest": "jest test/jest/test",
"test:jest": "jest",
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
"test:typescript": "tsd",
Expand Down Expand Up @@ -114,5 +114,8 @@
"esnext"
]
}
},
"jest": {
"testMatch": ["<rootDir>/test/jest/**"]
}
}
6 changes: 3 additions & 3 deletions test/jest/test.js
Expand Up @@ -12,7 +12,7 @@ test('should work in jest', async () => {
res.setHeader('Content-Type', 'text/plain')
res.end('hello')
})
await new Promise((resolve, reject) => {
await expect(new Promise((resolve, reject) => {
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
client.request({
Expand All @@ -28,9 +28,9 @@ test('should work in jest', async () => {
if (err) {
reject(err)
} else {
resolve(result)
resolve(result.body.text())
}
})
})
})
})).resolves.toBe('hello')
})