Skip to content

Commit

Permalink
Addition of TestFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Nov 11, 2024
1 parent 199f773 commit 9873a67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 14 additions & 2 deletions tests/example.test.mjs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);

});

0 comments on commit 9873a67

Please sign in to comment.