Skip to content

Commit

Permalink
v0.0.42 bump
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Nov 13, 2024
1 parent 7748961 commit 6eb9652
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codi-test-framework",
"version": "v0.0.41",
"version": "v0.0.42",
"description": "A simple test framework for JavaScript",
"main": "src/testRunner.js",
"type": "module",
Expand Down
23 changes: 2 additions & 21 deletions src/runners/nodeRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,13 @@ export async function runTests(testDirectory, returnResults = false, codiConfig
* @param {Function} testFn - Test function to run
* @returns {Promise<object>} Test results
*/
export async function runTestFunction(testFn, options, description) {
const suite = {
description: description ? description : `Function: ${testFn.name}`,
tests: [],
startTime: performance.now()
};

state.pushSuite(suite);

if (options) {
state.setOptions(options);
}
export async function runTestFunction(testFn) {

try {
await Promise.resolve(testFn(suite.description));
await Promise.resolve(testFn());
} catch (error) {
console.error(`Error in test ${testFn.name}:`, error);
state.failedTests++;
} finally {
suite.duration = performance.now() - suite.startTime;
state.testResults.push(suite);
state.popSuite();
}

if (options.showSummary) {
state.printSummary();
}

return {
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const assertFalse = assertions.assertFalse;
export const assertThrows = assertions.assertThrows;
export const assertNoDuplicates = assertions.assertNoDuplicates;

export const version = 'v0.0.41';
export const version = 'v0.0.42';

/**
* CLI entry point for running tests
Expand Down
58 changes: 38 additions & 20 deletions tests/example.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,50 @@ await describe('I am an Example Test Suite', () => {
});


await describe('I am the first describe', async () => {
await runTestFunction(testFunction, { showSummary: false }, 'I am the first function');
await runTestFunction(testFunction, { showSummary: false }, 'I am the second function');
await runTestFunction(testFunction);

await describe('I am the second describe', async () => {

it('should pass equality assertion', () => {
assertEqual(1, 2, 'Expected 1 to equal 1');
function testFunction() {
describe('First Layer', () => {
it('First', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});

it('should pass equality assertion', () => {
assertEqual(1, 2, 'Expected 1 to equal 1');
it('First', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
it('First', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});

await runTestFunction(testFunction, { showSummary: false }, 'I am the third function');

await describe('I am the third describe', async () => {

await runTestFunction(testFunction, { showSummary: false }, 'I am the fouth function');
})
})
});
secondFunction();
});
}

function secondFunction() {
describe('Second Layer', () => {
it('Second', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
it('Second', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
it('Second', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
thirdFunction();
});
}

function testFunction() {
it('First', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
function thirdFunction() {
describe('Third Layer', () => {
it('Third', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
it('Third', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
it('Third', () => {
assertEqual(1, 1, 'Expected 1 to equal 1');
});
});
}

0 comments on commit 6eb9652

Please sign in to comment.