diff options
Diffstat (limited to 'tests/manual/wasm/shared/testrunner.js')
| -rw-r--r-- | tests/manual/wasm/shared/testrunner.js | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/tests/manual/wasm/shared/testrunner.js b/tests/manual/wasm/shared/testrunner.js index da87026b03c..82259b0620b 100644 --- a/tests/manual/wasm/shared/testrunner.js +++ b/tests/manual/wasm/shared/testrunner.js @@ -1,6 +1,71 @@ // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +export class assert +{ + static isFalse(value) + { + if (value !== false) + throw new Error(`Assertion failed, expected to be false, was ${value}`); + } + + static isTrue(value) + { + if (value !== true) + throw new Error(`Assertion failed, expected to be true, was ${value}`); + } + + static isUndefined(value) + { + if (typeof value !== 'undefined') + throw new Error(`Assertion failed, expected to be undefined, was ${value}`); + } + + static isNotUndefined(value) + { + if (typeof value === 'undefined') + throw new Error(`Assertion failed, expected not to be undefined, was ${value}`); + } + + static equal(expected, actual) + { + if (expected !== actual) + throw new Error(`Assertion failed, expected to be ${expected}, was ${actual}`); + } + + static notEqual(expected, actual) + { + if (expected === actual) + throw new Error(`Assertion failed, expected not to be ${expected}`); + } +} + +export class Mock extends Function +{ + #calls = []; + + constructor() + { + super() + const proxy = new Proxy(this, { + apply: (target, _, args) => target.onCall(...args) + }); + proxy.thisMock = this; + + return proxy; + } + + get calls() + { + return this.thisMock.#calls; + } + + onCall(...args) + { + this.#calls.push(args); + } +} + function output(message) { const outputLine = document.createElement('div'); @@ -15,10 +80,12 @@ function output(message) export class TestRunner { #testClassInstance + #timeoutSeconds - constructor(testClassInstance) + constructor(testClassInstance, config) { this.#testClassInstance = testClassInstance; + this.#timeoutSeconds = config?.timeoutSeconds ?? 2; } async run(testCase) @@ -39,8 +106,8 @@ export class TestRunner const timeout = window.setTimeout(() => { rejected = true; - reject(new Error('Timeout after 2 seconds')); - }, 2000); + reject(new Error(`Timeout after ${this.#timeoutSeconds} seconds`)); + }, this.#timeoutSeconds * 1000); prototype[testCase].apply(this.#testClassInstance).then(() => { if (!rejected) { |
