From: Chris Duncan Date: Fri, 6 Dec 2024 12:42:56 +0000 (-0800) Subject: Draft a test of our test runner. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=5e462695dae122f53f3a8b11a4ff9a70e6752db4;p=libnemo.git Draft a test of our test runner. --- diff --git a/test/main.mjs b/test/main.mjs index 14f5bc4..e41b08b 100644 --- a/test/main.mjs +++ b/test/main.mjs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later +import './test.test.mjs' import './create-wallet.test.mjs' import './derive-accounts.test.mjs' import './import-wallet.test.mjs' diff --git a/test/test.test.mjs b/test/test.test.mjs new file mode 100644 index 0000000..25bf413 --- /dev/null +++ b/test/test.test.mjs @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +'use strict' + +import { assert, skip, test } from '#GLOBALS.mjs' + +function testTheTests () { + // Replace console.log with stub implementation. + const console_log = console.log + const calls = [] + console.log = (...args) => { + calls.push(args) + console_log(...args) + } + + try { + console.assert(calls.length == 0) + + test('good promise', new Promise(resolve => resolve())) + console.assert(calls.length == 1) + console.assert(calls[0][0] === 'PASS: good promise') + + test('bad promise', new Promise((resolve, reject) => reject())) + console.assert(calls.length == 2) + console.assert(calls[1][0] === 'FAIL: bad promise') + + test('good async', async () => { }) + console.assert(calls.length == 3) + console.assert(calls[2][0] === 'PASS: good async') + + test('bad async', async () => { throw new Error('msg') }) + console.assert(calls.length == 4) + console.assert(calls[3][0] === 'PASS: bad async: msg') + + test('good function', () => { }) + console.assert(calls.length == 5) + console.assert(calls[4][0] === 'PASS: good function') + + test('bad function', null) + console.assert(calls.length == 6) + console.assert(calls[5][0] === 'FAIL: bad function') + + } catch (error) { + console.error(error) + } finally { + // Restore original implementation after testing. + console.log = console_log + } +}