]> git.codecow.com Git - libnemo.git/commitdiff
Spruce up test output.
authorChris Duncan <chris@zoso.dev>
Fri, 18 Jul 2025 16:06:30 +0000 (09:06 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 18 Jul 2025 16:06:30 +0000 (09:06 -0700)
index.html
test/GLOBALS.mjs
test/test.main.mjs

index f193df59ced011b332ad0eecc1dc13c61338fa2f..c9627e61ae20bd90a9160c8e171d06ef14a89fd7 100644 (file)
@@ -33,8 +33,36 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                return hex.slice(0, size)
                        }
                        const output = document.getElementById('output')
+
+                       const consoleError = console.error
+                       const consoleLog = console.log
+
+                       function consoleOverride () {
+                               console.error = (...args) => {
+                                       let a = args.join()
+                                       a = a.replace('%cFAIL ,color:red,', '<span style="color:red">FAIL </span>')
+                                       output.innerHTML += `<pre>${a}</pre>`
+                                       consoleError(...args)
+                                       window?.scrollTo(0, document.body.scrollHeight)
+                               }
+                               console.log = (...args) => {
+                                       let a = args.join()
+                                       a = a.replace('%cTEST RUNNER CHECK DONE,font-weight:bold', '<span style="font-weight:bold">TEST RUNNER CHECK DONE </span>')
+                                       a = a.replace('%cPASS ,color:green,', '<span style="color:green">PASS </span>')
+                                       a = a.replace('%cSKIP ,color:CornflowerBlue,', '<span style="color:CornflowerBlue">SKIP </span>')
+                                       a = a.replace('%cTESTING COMPLETE,color:orange;font-weight:bold', '<span style="color:orange;font-weight:bold">TESTING COMPLETE</span>')
+                                       a = a.replace('%cPASS: ,color:green;font-weight:bold,', '<span style="color:green;font-weight:bold">PASS </span>')
+                                       a = a.replace('%cFAIL: ,color:red;font-weight:bold,', '<span style="color:red;font-weight:bold">FAIL </span>')
+                                       output.innerHTML += `<pre>${a}</pre>`
+                                       consoleLog(...args)
+                                       window?.scrollTo(0, document.body.scrollHeight)
+                               }
+                       }
+                       consoleOverride()
+
                        const consoleGroup = console.group
                        console.group = (...args) => {
+                               consoleOverride()
                                let a = args.join()
                                a = a.replace('%cSKIP ,color:CornflowerBlue,', '<span style="color:CornflowerBlue;font-weight:bold">SKIP </span>')
                                a = a.replace(',font-weight:bold', '</span>')
@@ -43,23 +71,22 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                consoleGroup(...args)
                                window?.scrollTo(0, document.body.scrollHeight)
                        }
-                       const consoleError = console.error
-                       console.error = (...args) => {
+                       const consoleGroupCollapsed = console.groupCollapsed
+                       console.groupCollapsed = (...args) => {
+                               console.error = (...args) => consoleError(...args)
+                               console.log = (...args) => consoleLog(...args)
                                let a = args.join()
-                               a = a.replace('%cFAIL ,color:red,', '<span style="color:red">FAIL </span>')
+                               a = a.replace('%cSKIP ,color:CornflowerBlue,', '<span style="color:CornflowerBlue;font-weight:bold">SKIP </span>')
+                               a = a.replace(',font-weight:bold', '</span>')
+                               a = a.replace('%c', '<span style="font-weight:bold">')
                                output.innerHTML += `<pre>${a}</pre>`
-                               consoleError(...args)
+                               consoleGroupCollapsed(...args)
                                window?.scrollTo(0, document.body.scrollHeight)
                        }
-                       const consoleLog = console.log
-                       console.log = (...args) => {
-                               let a = args.join()
-                               a = a.replace('%cTEST RUNNER CHECK DONE,font-weight:bold', '<span style="font-weight:bold">TEST RUNNER CHECK DONE </span>')
-                               a = a.replace('%cPASS ,color:green,', '<span style="color:green">PASS </span>')
-                               a = a.replace('%cSKIP ,color:CornflowerBlue,', '<span style="color:CornflowerBlue">SKIP </span>')
-                               a = a.replace('%cTESTING COMPLETE,color:orange;font-weight:bold', '<span style="color:orange;font-weight:bold">TESTING COMPLETE</span>')
-                               output.innerHTML += `<pre>${a}</pre>`
-                               consoleLog(...args)
+                       const consoleGroupEnd = console.groupEnd
+                       console.groupEnd = () => {
+                               consoleGroupEnd()
+                               consoleOverride()
                                window?.scrollTo(0, document.body.scrollHeight)
                        }
                })()
index 3973857e9b6cc9575587a88bce634862ccc906f3..5435b172a926677a1366e7181d3879a0c5cb2d1c 100644 (file)
@@ -103,8 +103,8 @@ export function stats (times) {
        }
 }
 
-const failures = []
-const passes = []
+export const failures = []
+export const passes = []
 function fail (err) {
        failures.push(err.message)
        console.error(`%cFAIL `, 'color:red', err.message, err.cause)
@@ -114,7 +114,7 @@ function pass (name) {
        console.log(`%cPASS `, 'color:green', name)
 }
 
-await suite('TEST RUNNER CHECK', async () => {
+await suite('TEST RUNNER CHECK', { collapse: true }, async () => {
        await new Promise(r => setTimeout(r, 0))
 
        console.assert(failures.length === 0)
@@ -144,8 +144,10 @@ await suite('TEST RUNNER CHECK', async () => {
        console.assert(failures.some(call => /.*function should fail.*/.test(call)) === true, 'bad function not errored')
        console.assert(passes.some(call => /.*function should fail.*/.test(call)) === false, 'bad function logged')
 
-       console.log(`%cTEST RUNNER CHECK DONE`, 'font-weight:bold')
+       failures.splice(0)
+       passes.splice(0)
 })
+console.log(`%cTEST RUNNER CHECK DONE`, 'font-weight:bold')
 
 export function suite (name, opts, fn) {
        if (fn === undefined) fn = opts
@@ -157,7 +159,9 @@ export function suite (name, opts, fn) {
                }
                if (fn?.constructor?.name === 'AsyncFunction') fn = fn()
                if (typeof fn === 'function') fn = new Promise(resolve => resolve(fn()))
-               console.group(`%c${name}`, 'font-weight:bold')
+               opts?.collapse
+                       ? console.groupCollapsed(`%c${name}`, 'font-weight:bold')
+                       : console.group(`%c${name}`, 'font-weight:bold')
                await fn
                console.groupEnd()
        })
index ff503202de899736914565d6c56b3bd015398803..e954753e45f5aa9c513bfc89d8df6babac587070 100644 (file)
@@ -1,6 +1,8 @@
 // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
 // SPDX-License-Identifier: GPL-3.0-or-later
 
+import { failures, passes } from './GLOBALS.mjs'
+
 import './test.blake2b.mjs'
 import './test.blocks.mjs'
 import './test.calculate-pow.mjs'
@@ -14,3 +16,5 @@ import './test.refresh-accounts.mjs'
 import './test.tools.mjs'
 
 console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
+console.log('%cPASS: ', 'color:green;font-weight:bold', passes.length)
+console.log('%cFAIL: ', 'color:red;font-weight:bold', failures.length)