diff --git a/CMakeLists.txt b/CMakeLists.txt index 116efa6b..b385b614 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ include(FetchContent) # -------------------------------------------------- FetchContent_Declare(AndroidExtensions GIT_REPOSITORY https://github.com/BabylonJS/AndroidExtensions.git - GIT_TAG 2d5af72259cc73e5f249d3c99bee2010be9cb042 + GIT_TAG 2e85a8d43b89246c460112c9e5546ad54b6e87b4 EXCLUDE_FROM_ALL) FetchContent_Declare(arcana.cpp GIT_REPOSITORY https://github.com/microsoft/arcana.cpp.git @@ -37,7 +37,7 @@ FetchContent_Declare(llhttp EXCLUDE_FROM_ALL) FetchContent_Declare(UrlLib GIT_REPOSITORY https://github.com/BabylonJS/UrlLib.git - GIT_TAG d53beb958b1cccafd5411260ace6d32b68b56a83 + GIT_TAG 880c2575e57ca0b59068ecc4860f185b9970e0ce EXCLUDE_FROM_ALL) # -------------------------------------------------- diff --git a/Tests/UnitTests/Scripts/tests.ts b/Tests/UnitTests/Scripts/tests.ts index a79ebdf0..38990703 100644 --- a/Tests/UnitTests/Scripts/tests.ts +++ b/Tests/UnitTests/Scripts/tests.ts @@ -408,6 +408,8 @@ if (hostPlatform !== "Unix") { it("should connect correctly with one websocket connection", function (done) { const ws = new WebSocket("wss://ws.postman-echo.com/raw"); const testMessage = "testMessage"; + let error: Error | undefined; + ws.onopen = () => { try { expect(ws).to.have.property("readyState", 1); @@ -415,7 +417,7 @@ if (hostPlatform !== "Unix") { ws.send(testMessage); } catch (e) { - done(e); + error = e as Error; } }; @@ -425,11 +427,17 @@ if (hostPlatform !== "Unix") { ws.close(); } catch (e) { - done(e); + error = e as Error; } }; + // onclose is always the terminal event. + // Collect errors from earlier phases and report them here. ws.onclose = () => { + if (error) { + done(error); + return; + } try { expect(ws).to.have.property("readyState", 3); done(); @@ -439,14 +447,15 @@ if (hostPlatform !== "Unix") { } }; - ws.onerror = (ev) => { - done(new Error("WebSocket failed")); + ws.onerror = () => { + error = new Error("WebSocket failed"); }; }); it("should connect correctly with multiple websocket connections", function (done) { const testMessage1 = "testMessage1"; const testMessage2 = "testMessage2"; + let error: Error | undefined; const ws1 = new WebSocket("wss://ws.postman-echo.com/raw"); ws1.onopen = () => { @@ -458,7 +467,7 @@ if (hostPlatform !== "Unix") { ws2.send(testMessage2); } catch (e) { - done(e); + error = e as Error; } }; @@ -468,7 +477,7 @@ if (hostPlatform !== "Unix") { ws2.close(); } catch (e) { - done(e); + error = e as Error; } }; @@ -478,12 +487,12 @@ if (hostPlatform !== "Unix") { ws1.send(testMessage1); } catch (e) { - done(e); + error = e as Error; } }; - ws2.onerror = (ev) => { - done(new Error("Websocket failed")); + ws2.onerror = () => { + error = new Error("WebSocket failed"); }; } @@ -493,11 +502,15 @@ if (hostPlatform !== "Unix") { ws1.close(); } catch (e) { - done(e); + error = e as Error; } } ws1.onclose = () => { + if (error) { + done(error); + return; + } try { expect(ws1).to.have.property("readyState", 3); done(); @@ -507,8 +520,8 @@ if (hostPlatform !== "Unix") { } } - ws1.onerror = (ev) => { - done(new Error("Websocket failed")); + ws1.onerror = () => { + error = new Error("WebSocket failed"); }; }); @@ -523,8 +536,18 @@ if (hostPlatform !== "Unix") { it("should trigger error callback with invalid domain", function (done) { this.timeout(10000); const ws = new WebSocket("wss://example"); + let errorFired = false; ws.onerror = () => { - done(); + errorFired = true; + }; + ws.onclose = () => { + try { + expect(errorFired).to.be.true; + done(); + } + catch (e) { + done(e); + } }; }); })