diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 7ab5e2553c4..1ea6c30a48c 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -115,6 +115,10 @@ #include #endif +#if defined(Q_OS_WASM) +#include +#endif + #include QT_BEGIN_NAMESPACE @@ -2274,6 +2278,14 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) qInit(testObject, argc, argv); int ret = qRun(); qCleanup(); + +#if defined(Q_OS_WASM) + EM_ASM({ + if (typeof Module != "undefined" && typeof Module.notifyTestFinished != "undefined") + Module.notifyTestFinished($0); + }, ret); +#endif // Q_OS_WASM + return ret; } diff --git a/tests/auto/corelib/serialization/CMakeLists.txt b/tests/auto/corelib/serialization/CMakeLists.txt index ef40e78d249..7fd9a336391 100644 --- a/tests/auto/corelib/serialization/CMakeLists.txt +++ b/tests/auto/corelib/serialization/CMakeLists.txt @@ -10,7 +10,7 @@ if(TARGET Qt::Gui) add_subdirectory(qdatastream) add_subdirectory(qdatastream_core_pixmap) endif() -if(TARGET Qt::Network) +if(TARGET Qt::Network AND NOT WASM) add_subdirectory(qtextstream) endif() if(TARGET Qt::Gui AND TARGET Qt::Network AND TARGET Qt::Xml AND NOT INTEGRITY AND NOT QNX AND NOT WASM) diff --git a/tests/auto/corelib/thread/CMakeLists.txt b/tests/auto/corelib/thread/CMakeLists.txt index 64c0f47ca5e..5889f4249f2 100644 --- a/tests/auto/corelib/thread/CMakeLists.txt +++ b/tests/auto/corelib/thread/CMakeLists.txt @@ -6,7 +6,6 @@ if(WASM) # not all tests currently work in WebAssembly add_subdirectory(qatomicinteger) add_subdirectory(qatomicpointer) add_subdirectory(qfuturesynchronizer) - add_subdirectory(qfuturewatcher) add_subdirectory(qmutexlocker) add_subdirectory(qreadlocker) add_subdirectory(qresultstore) diff --git a/util/wasm/batchedtestrunner/qwasmjsruntime.js b/util/wasm/batchedtestrunner/qwasmjsruntime.js index 716a461576f..99d9c41c710 100644 --- a/util/wasm/batchedtestrunner/qwasmjsruntime.js +++ b/util/wasm/batchedtestrunner/qwasmjsruntime.js @@ -129,16 +129,9 @@ export class CompiledModule { return await new Promise(async (resolve, reject) => { let instance = undefined; let result = undefined; - const continuation = () => { - if (!(instance && result)) - return; - resolve({ - stdout: result.stdout, - exitCode: result.exitCode, - instance, - }); - }; + let testFinished = false; + const testFinishedEvent = new CustomEvent('testFinished'); instance = await this.#createQtAppInstanceFn((() => { const params = this.#makeDefaultExecParams({ onInstantiationError: (error) => { reject(error); }, @@ -154,12 +147,26 @@ export class CompiledModule { params.quit = (code, exception) => { if (exception && exception.name !== 'ExitStatus') reject(exception); + }; + params.notifyTestFinished = (code) => { result = { stdout: data, exitCode: code }; - continuation(); + testFinished = true; + window.dispatchEvent(testFinishedEvent); }; return params; })()); - continuation(); + if (!testFinished) { + await new Promise((resolve) => { + window.addEventListener('testFinished', () => { + resolve(); + }); + }); + } + resolve({ + stdout: result.stdout, + exitCode: result.exitCode, + instance, + }); }); }