Skip to content

Commit

Permalink
test: handle emscripten 3.1.58 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Apr 25, 2024
1 parent c6a802c commit 7a3139c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = require('./common.js')
const emnapi = require('../runtime')
const context = emnapi.getDefaultContext()

function getEntry (targetName) {
function getDir () {
let buildDir
if ('EMNAPI_TEST_WASI_THREADS' in process.env) {
buildDir = process.env.MEMORY64 ? '.build/wasm64-wasi-threads' : '.build/wasm32-wasi-threads'
Expand All @@ -20,7 +20,11 @@ function getEntry (targetName) {
} else {
buildDir = process.env.MEMORY64 ? '.build/wasm64-unknown-emscripten' : '.build/wasm32-unknown-emscripten'
}
return join(__dirname, `./${buildDir}/${common.buildType}/${targetName}.${process.env.EMNAPI_TEST_NATIVE ? 'node' : (process.env.EMNAPI_TEST_WASI || process.env.EMNAPI_TEST_WASM32) ? 'wasm' : 'js'}`)
return join(__dirname, buildDir, common.buildType)
}

function getEntry (targetName) {
return join(getDir(), `${targetName}.${process.env.EMNAPI_TEST_NATIVE ? 'node' : (process.env.EMNAPI_TEST_WASI || process.env.EMNAPI_TEST_WASM32) ? 'wasm' : 'js'}`)
}

exports.getEntry = getEntry
Expand Down Expand Up @@ -153,7 +157,21 @@ function loadPath (request, options) {
return p
}
const p = new Promise((resolve, reject) => {
mod().then((Module) => {
mod({
locateFile (path, scriptDirectory) {
const defaultResult = scriptDirectory + path

/**
* emscripten 3.1.58 bug introduced by
* https://github.com/emscripten-core/emscripten/pull/21701
*/
if (!fs.existsSync(defaultResult)) {
return join(getDir(), path)
}

return defaultResult
}
}).then((Module) => {
p.Module = Module
resolveEmnapiExports(Module, resolve, reject)
}).catch(reject)
Expand Down

0 comments on commit 7a3139c

Please sign in to comment.