]> zoso.dev Git - libnemo.git/commitdiff
Draft a test of our test runner.
authorChris Duncan <chris@zoso.dev>
Fri, 6 Dec 2024 12:42:56 +0000 (04:42 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 6 Dec 2024 12:42:56 +0000 (04:42 -0800)
test/main.mjs
test/test.test.mjs [new file with mode: 0644]

index 14f5bc456b65f6f2c6ae531a31add6168d55fe20..e41b08bbed5b5d87b48e5176ded0bca157247e52 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
 // 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 (file)
index 0000000..25bf413
--- /dev/null
@@ -0,0 +1,50 @@
+// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
+// 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
+       }
+}