emscripten-core / emscripten-core/emscripten
BindingError when running unittests twice
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I have setup some unit tests using karma and jasmine.
The file that loads the Wasm looks like this:
```
declare var window: any
declare var Module: any
window.Module = {}
window.PdfToolsPromise = new Promise((resolve, reject) => {
window.Module['onRuntimeInitialized'] = () =>{
console.log('resolved')
window.WebViewerLoaded = true
resolve()
}
})
let script = document.createElement('script');
script.src = 'PdfViewing_Main.js';
document.head.appendChild(script);
```
and my beforeAllTests callback looks like this:
```
export function beforeAllTests(): () => Promise {
return () => new Promise( (resolve, reject) => {
const checkApi = () => {
console.log('binaries ready', window.WebViewerLoaded)
if (window.WebViewerLoaded) {
resolve()
clearInterval(interval)
}
}
const interval = setInterval(checkApi, 100)
checkApi()
})
}
```
When starting the unit tests it's fine but refreshing the browser or changing some test files causing a reload results in a `BindingError`:
```
message: "Cannot register public name '' twice"
name: "BindingError"
throwBindingError http://localhost:9876/PdfViewing_Main.js:1
exposePublicSymbol http://localhost:9876/PdfViewing_Main.js:1
__embind_register_function http://localhost:9876/PdfViewing_Main.js:1
http://localhost:9876/PdfViewing_Main.wasm:1181499
http://localhost:9876/PdfViewing_Main.wasm:44712
___wasm_call_ctors http://localhost:9876/PdfViewing_Main.js:1
func http://localhost:9876/PdfViewing_Main.js:1
callRuntimeCallbacks http://localhost:9876/PdfViewing_Main.js:1
initRuntime http://localhost:9876/PdfViewing_Main.js:1
doRun http://localhost:9876/PdfViewing_Main.js:1
run http://localhost:9876/PdfViewing_Main.js:1
runCaller http://localhost:9876/PdfViewing_Main.js:1
removeRunDependency http://localhost:9876/PdfViewing_Main.js:1
processPackageData http://localhost:9876/PdfViewing_Main.js:1
onsuccess http://localhost:9876/PdfViewing_Main.js:1
(Async: EventHandlerNonNull)
fetchCachedPackage http://localhost:9876/PdfViewing_Main.js:1
runWithFS http://localhost:9876/PdfViewing_Main.js:1
onsuccess http://localhost:9876/PdfViewing_Main.js:1
(Async: EventHandlerNonNull)
checkCachedPackage http://localhost:9876/PdfViewing_Main.js:1
runWithFS http://localhost:9876/PdfViewing_Main.js:1
onsuccess http://localhost:9876/PdfViewing_Main.js:1
(Async: EventHandlerNonNull)
openDatabase http://localhost:9876/PdfViewing_Main.js:1
runWithFS http://localhost:9876/PdfViewing_Main.js:1
callRuntimeCallbacks http://localhost:9876/PdfViewing_Main.js:1
preRun http://localhost:9876/PdfViewing_Main.js:1
run http://localhost:9876/PdfViewing_Main.js:1
runCaller http://localhost:9876/PdfViewing_Main.js:1
removeRunDependency http://localhost:9876/PdfViewing_Main.js:1
receiveInstance http://localhost:9876/PdfViewing_Main.js:1
receiveInstantiatedSource http://localhost:9876/PdfViewing_Main.js:1
(Async: promise callback)
instantiateAsync http://localhost:9876/PdfViewing_Main.js:1
(Async: promise callback)
instantiateAsync http://localhost:9876/PdfViewing_Main.js:1
createWasm http://localhost:9876/PdfViewing_Main.js:1
http://localhost:9876/PdfViewing_Main.js:1
```
Is there a way to avoid this?
Contributor guide
Assessment
This issue has not been assessed yet.