From: Chris Duncan Date: Sat, 19 Jul 2025 21:56:21 +0000 (-0700) Subject: Move test runner check into its own file so it only runs once in node. X-Git-Tag: v0.10.5~55^2~58 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=f41ce50fb67167fbdb9ef4e36e803abbfa7ac605;p=libnemo.git Move test runner check into its own file so it only runs once in node. --- diff --git a/test/GLOBALS.mjs b/test/GLOBALS.mjs index 3823222..ea87e35 100644 --- a/test/GLOBALS.mjs +++ b/test/GLOBALS.mjs @@ -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') diff --git a/test/test.main.mjs b/test/test.main.mjs index e954753..103a42c 100644 --- a/test/test.main.mjs +++ b/test/test.main.mjs @@ -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 index 0000000..2295d30 --- /dev/null +++ b/test/test.runner-check.mjs @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// 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')