]> git.codecow.com Git - libnemo.git/commitdiff
Move test runner check into its own file so it only runs once in node.
authorChris Duncan <chris@zoso.dev>
Sat, 19 Jul 2025 21:56:21 +0000 (14:56 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 19 Jul 2025 21:56:21 +0000 (14:56 -0700)
test/GLOBALS.mjs
test/test.main.mjs
test/test.runner-check.mjs [new file with mode: 0644]

index 3823222db5f58605a2ccf78a9f012f6b017cca61..ea87e35023532ad8d97dce66c3997536f7998d54 100644 (file)
@@ -234,41 +234,3 @@ export const assert = {
                }
        }
 }
-
-await suite('TEST RUNNER CHECK', async () => {
-       await new Promise(r => setTimeout(r, 0))
-
-       console.assert(failures.length === 0)
-       console.assert(passes.length === 0)
-
-       //@ts-expect-error
-       await test('promise should pass', new Promise(resolve => resolve(null)))
-       console.assert(failures.some(call => /.*promise should pass.*/.test(call[0])) === false, `good promise errored`)
-       console.assert(passes.some(call => /.*promise should pass.*/.test(call)) === true, `good promise not logged`)
-
-       //@ts-expect-error
-       await test('promise should fail', new Promise((resolve, reject) => reject('FAILURE EXPECTED HERE')))
-       console.assert(failures.some(call => /.*promise should fail.*/.test(call)) === true, `bad promise not errored`)
-       console.assert(passes.some(call => /.*promise should fail.*/.test(call)) === false, 'bad promise logged')
-
-       await test('async should pass', async () => {})
-       console.assert(failures.some(call => /.*async should pass.*/.test(call)) === false, 'good async errored')
-       console.assert(passes.some(call => /.*async should pass.*/.test(call)) === true, 'good async not logged')
-
-       await test('async should fail', async () => { throw new Error('FAILURE EXPECTED HERE') })
-       console.assert(failures.some(call => /.*async should fail.*/.test(call)) === true, 'bad async not errored')
-       console.assert(passes.some(call => /.*async should fail.*/.test(call)) === false, 'bad async logged')
-
-       await test('function should pass', () => {})
-       console.assert(failures.some(call => /.*function should pass.*/.test(call)) === false, 'good function errored')
-       console.assert(passes.some(call => /.*function should pass.*/.test(call)) === true, 'good function not logged')
-
-       //@ts-expect-error
-       await test('function should fail', 'FAILURE EXPECTED HERE')
-       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')
-
-       failures.splice(0)
-       passes.splice(0)
-})
-console.log(`%cTEST RUNNER CHECK DONE`, 'font-weight:bold')
index e954753e45f5aa9c513bfc89d8df6babac587070..103a42cc7481c0c4e987e016bde7737ef2806557 100644 (file)
@@ -2,6 +2,7 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
 import { failures, passes } from './GLOBALS.mjs'
+import './test.runner-check.mjs'
 
 import './test.blake2b.mjs'
 import './test.blocks.mjs'
diff --git a/test/test.runner-check.mjs b/test/test.runner-check.mjs
new file mode 100644 (file)
index 0000000..2295d30
--- /dev/null
@@ -0,0 +1,42 @@
+// SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+import { failures, passes, suite, test } from './GLOBALS.mjs'
+
+await suite('TEST RUNNER CHECK', async () => {
+       await new Promise(r => setTimeout(r, 0))
+
+       console.assert(failures.length === 0)
+       console.assert(passes.length === 0)
+
+       //@ts-expect-error
+       await test('promise should pass', new Promise(resolve => resolve(null)))
+       console.assert(failures.some(call => /.*promise should pass.*/.test(call[0])) === false, `good promise errored`)
+       console.assert(passes.some(call => /.*promise should pass.*/.test(call)) === true, `good promise not logged`)
+
+       //@ts-expect-error
+       await test('promise should fail', new Promise((resolve, reject) => reject('FAILURE EXPECTED HERE')))
+       console.assert(failures.some(call => /.*promise should fail.*/.test(call)) === true, `bad promise not errored`)
+       console.assert(passes.some(call => /.*promise should fail.*/.test(call)) === false, 'bad promise logged')
+
+       await test('async should pass', async () => {})
+       console.assert(failures.some(call => /.*async should pass.*/.test(call)) === false, 'good async errored')
+       console.assert(passes.some(call => /.*async should pass.*/.test(call)) === true, 'good async not logged')
+
+       await test('async should fail', async () => { throw new Error('FAILURE EXPECTED HERE') })
+       console.assert(failures.some(call => /.*async should fail.*/.test(call)) === true, 'bad async not errored')
+       console.assert(passes.some(call => /.*async should fail.*/.test(call)) === false, 'bad async logged')
+
+       await test('function should pass', () => {})
+       console.assert(failures.some(call => /.*function should pass.*/.test(call)) === false, 'good function errored')
+       console.assert(passes.some(call => /.*function should pass.*/.test(call)) === true, 'good function not logged')
+
+       //@ts-expect-error
+       await test('function should fail', 'FAILURE EXPECTED HERE')
+       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')
+
+       failures.splice(0)
+       passes.splice(0)
+})
+console.log(`%cTEST RUNNER CHECK DONE`, 'font-weight:bold')