diff options
| author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-11-02 15:48:44 +0100 |
|---|---|---|
| committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-11-24 18:47:49 +0100 |
| commit | b4ef0031c67a99ebd98fb324eff8ad2ce5af025d (patch) | |
| tree | e91ad569115f89ede6114e4a457de4e1262668a1 /tests/manual/wasm/shared/testrunner.js | |
| parent | 6c435e5dd41177308f22ba4b55931b2c463cb0d8 (diff) | |
Set up a manual test for qt loader
Skeleton tests included. Run the test with run.sh.
Fixes: QTBUG-107744
Change-Id: Ic2734e24025f8edc0f8e710d981367aa321f9066
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/manual/wasm/shared/testrunner.js')
| -rw-r--r-- | tests/manual/wasm/shared/testrunner.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/manual/wasm/shared/testrunner.js b/tests/manual/wasm/shared/testrunner.js new file mode 100644 index 00000000000..da87026b03c --- /dev/null +++ b/tests/manual/wasm/shared/testrunner.js @@ -0,0 +1,78 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +function output(message) +{ + const outputLine = document.createElement('div'); + outputLine.style.fontFamily = 'monospace'; + outputLine.innerText = message; + + document.body.appendChild(outputLine); + + console.log(message); +} + +export class TestRunner +{ + #testClassInstance + + constructor(testClassInstance) + { + this.#testClassInstance = testClassInstance; + } + + async run(testCase) + { + const prototype = Object.getPrototypeOf(this.#testClassInstance); + try { + output(`Running ${testCase}`); + if (!prototype.hasOwnProperty(testCase)) + throw new Error(`No such testcase ${testCase}`); + + if (prototype.beforeEach) { + await prototype.beforeEach.apply(this.#testClassInstance); + } + + await new Promise((resolve, reject) => + { + let rejected = false; + const timeout = window.setTimeout(() => + { + rejected = true; + reject(new Error('Timeout after 2 seconds')); + }, 2000); + prototype[testCase].apply(this.#testClassInstance).then(() => + { + if (!rejected) { + window.clearTimeout(timeout); + output(`✅ Test passed ${testCase}`); + resolve(); + } + }).catch(reject); + }); + } catch (e) { + output(`❌ Failed ${testCase}: exception ${e} ${e.stack}`); + } finally { + if (prototype.afterEach) { + await prototype.afterEach.apply(this.#testClassInstance); + } + } + } + + async runAll() + { + const SPECIAL_FUNCTIONS = + ['beforeEach', 'afterEach', 'beforeAll', 'afterAll', 'constructor']; + const prototype = Object.getPrototypeOf(this.#testClassInstance); + const testFunctions = + Object.getOwnPropertyNames(prototype).filter( + entry => SPECIAL_FUNCTIONS.indexOf(entry) === -1); + + if (prototype.beforeAll) + await prototype.beforeAll.apply(this.#testClassInstance); + for (const fn of testFunctions) + await this.run(fn); + if (prototype.afterAll) + await prototype.afterAll.apply(this.#testClassInstance); + } +} |
