diff --git a/src/testRunner.js b/src/testRunner.js index 76c5d46..4dc4790 100755 --- a/src/testRunner.js +++ b/src/testRunner.js @@ -137,6 +137,26 @@ export async function runWebTests(testFiles) { } } + +export async function runTestFunction(testFn) { + + try { + await testFn(); + } catch (error) { + console.error(`Error in test ${testFn.name}:`, error); + } + + console.log(chalk.bold.cyan('\nTest Summary:')); + console.log(chalk.green(` Passed: ${passedTests}`)); + console.log(chalk.red(` Failed: ${failedTests}`)); + + return { + passedTests, + failedTests, + testResults + } +} + // CLI function export async function runCLI() { const testDirectory = process.argv[2]; diff --git a/tests/example.test.mjs b/tests/example.test.mjs index d4fea05..c628a69 100644 --- a/tests/example.test.mjs +++ b/tests/example.test.mjs @@ -1,11 +1,11 @@ -import { describe, it, assertEqual, assertNotEqual, assertTrue, assertFalse, assertThrows, assertNoDuplicates } from '../src/testRunner.js'; +import { describe, it, assertEqual, assertNotEqual, assertTrue, assertFalse, assertThrows, assertNoDuplicates, runTestFunction } from '../src/testRunner.js'; import { helloworld } from '../example/example.mjs'; import pkg from '../example/common.cjs'; const { helloCommon } = pkg; -describe('I am an Example Test Suite', () => { +await describe('I am an Example Test Suite', () => { helloworld(); helloCommon(); @@ -43,4 +43,16 @@ describe('I am an Example Test Suite', () => { assertNoDuplicates(array, 'There should be no duplicates'); }); +}); + +await describe('Running testFunction', async () => { + + function testFunction() { + it('First', () => { + assertEqual(1, 1, 'Expected 1 to equal 1'); + }) + } + + await runTestFunction(testFunction); + }); \ No newline at end of file