From 7a3139cec477e87435de166cb011687dabaacfe8 Mon Sep 17 00:00:00 2001 From: toyobayashi Date: Thu, 25 Apr 2024 00:30:22 +0800 Subject: [PATCH] test: handle emscripten 3.1.58 bug --- packages/test/util.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/test/util.js b/packages/test/util.js index b7903e80..5b6a6591 100644 --- a/packages/test/util.js +++ b/packages/test/util.js @@ -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' @@ -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 @@ -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)