]> git.codecow.com Git - nano-pow.git/commitdiff
Append test output as new nodes instead of extra text. Replace inner HTML modificatio...
authorChris Duncan <chris@codecow.com>
Sun, 26 Jul 2026 09:12:24 +0000 (02:12 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 26 Jul 2026 09:12:24 +0000 (02:12 -0700)
index.html

index 19f5076f828ecb82939649a8ff6db5b0feb7a5c9..468c7ac5796afbb1bd7b9cf0f97268294c80b653 100644 (file)
@@ -28,7 +28,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
 
                if (NanoPow && Logger) {
                        document.getElementById('btnStartTest').disabled = false
-                       document.getElementById('status').innerHTML = `READY`
+                       document.getElementById('status').textContent = `READY`
                }
 
                const logger = new Logger()
@@ -80,7 +80,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        duration = end - start
 
                        const valid = (result.hash === hash && check.hash === hash && check.valid === '1')
-                       document.getElementById('output').textContent += `${valid ? 'VALID' : 'INVALID'} (${duration} ms)\n${JSON.stringify(result, ' ', 2)}\n`
                        if (!valid) {
                                logger.log(hash, result, check)
                                throw new Error(`invalid result\nblock hash: ${hash}\nwork: ${work}`)
@@ -106,7 +105,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
                 * @param {string} api
                 */
                async function selfCheck (api) {
-                       document.getElementById('status').innerHTML = `RUNNING SELF-CHECK`
+                       document.getElementById('status').textContent = `RUNNING SELF-CHECK`
                        logger.log(`%cNanoPow`, 'color:green', 'Checking validation against known values')
                        const options = { api, debug: true }
                        // Generate once on load to compile shaders and initialize buffers
@@ -186,7 +185,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                        result = await NanoPow.work_generate(hash, options)
                                        logger.log(result)
                                } catch (err) {
-                                       document.getElementById('output').innerHTML += `Error: ${err.message}<br/>${err.cause}<br/>${err.stack}`
                                        console.error(err)
                                        return
                                }
@@ -198,8 +196,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        }
 
                        if (!expect.every(result => result)) {
-                               document.getElementById('status').innerHTML = `FAILED TO VALIDATE KNOWN VALUES`
-                               document.getElementById('output').innerHTML += `Error: Failed to validate known values<br/>`
+                               document.getElementById('status').textContent = `FAILED TO VALIDATE KNOWN VALUES, CHECK CONSOLE`
                                throw new Error(`Validation is not working`)
                        }
                }
@@ -218,17 +215,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        await selfCheck(api)
                        Cache.clear()
                        logger.log(`%cNanoPow ${type}`, 'color:green', `Calculate truncated harmonic mean of the truncated arithmetic rate of generating proof-of-work for ${size} samples over ${runs} test runs.`)
+                       const output = document.getElementById('output').appendChild(document.createElement('pre'))
                        const rates = []
                        for (let i = 0; i < runs; i++) {
-                               await new Promise(r => setTimeout(r))
                                const times = []
                                for (let j = 0; j < size; j++) {
-                                       document.getElementById('status').innerHTML = `TESTING IN PROGRESS. THIS MAY TAKE A LONG TIME. ${j}/${size} ${i}/${runs}<br/>`
+                                       document.getElementById('status').textContent = `TESTING IN PROGRESS. THIS MAY TAKE A LONG TIME. ${j}/${size} ${i}/${runs}`
                                        try {
                                                const duration = await sequenceGenerateValidate(api, difficulty, effort)
                                                times.push(duration)
                                        } catch (err) {
-                                               document.getElementById('output').innerHTML += `Error: ${err.message}<br/>`
+                                               output.textContent += `Error: ${err.message}\n`
                                                console.error(err)
                                                return
                                        }
@@ -237,16 +234,16 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                const result = Object.values(avg)[0]
                                const { truncatedRate } = result
                                rates.push(truncatedRate)
-                               document.getElementById('summary').innerHTML += `Test run ${i + 1} score: ${truncatedRate} wps<br/>`
-                               document.getElementById('output').innerHTML += `${JSON.stringify(avg, null, '\t')}<br/>`
+                               document.getElementById('summary').textContent += `Test run ${i + 1} score: ${truncatedRate} wps\n`
+                               output.textContent += `${JSON.stringify(avg, null, '\t')}\n`
                        }
                        const results = stats(rates)
                        const { truncatedHarmonic } = results
                        logger.log(rates)
                        logger.log(results)
-                       document.getElementById('output').innerHTML += `<hr/>`
-                       document.getElementById('summary').innerHTML += `Final work-per-second: ${truncatedHarmonic}<br/>`
-                       document.getElementById('status').innerHTML = `TESTING COMPLETE<br/>`
+                       output.after(document.createElement('hr'))
+                       document.getElementById('summary').textContent += `Final work-per-second: ${truncatedHarmonic}\n`
+                       document.getElementById('status').textContent = `TESTING COMPLETE`
                        logger.log('%TESTING COMPLETE', 'color:orange;font-weight:bold')
                }
 
@@ -392,7 +389,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <pre id="summary"></pre>
        <hr />
        <h4>Output</h4>
-       <pre id="output"></pre>
+       <div id="output"></div>
 </body>
 
 </html>