codi-test-framework
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "codi-test-framework", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A simple test framework for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "src/testRunner.js", |
@@ -53,2 +53,3 @@ # Codi Test Framework ๐ถ | ||
- `assertEqual(actual, expected, message)`: Asserts that the actual value is equal to the expected value. โ๏ธ | ||
- `assertDeepEqual(actual, expected, message)`: Asserts that the actual object is equal to the expected object. โ๏ธ | ||
- `assertNotEqual(actual, expected, message)`: Asserts that the actual value is not equal to the expected value. ๐ โโ๏ธ | ||
@@ -55,0 +56,0 @@ - `assertTrue(actual, message)`: Asserts that the actual value is true. โ |
@@ -56,2 +56,34 @@ import fs from 'fs'; | ||
export function assertDeepEqual(actual, expected, message) { | ||
if (!isDeepEqual(actual, expected)) { | ||
throw new Error(message || `Expected ${chalk.bold.yellow(JSON.stringify(actual))} to deeply equal ${chalk.bold.yellow(JSON.stringify(expected))}`); | ||
} | ||
} | ||
// Helper function to compare objects deeply | ||
function isDeepEqual(obj1, obj2) { | ||
if (obj1 === obj2) { | ||
return true; | ||
} | ||
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) { | ||
return false; | ||
} | ||
const keys1 = Object.keys(obj1); | ||
const keys2 = Object.keys(obj2); | ||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} | ||
for (const key of keys1) { | ||
if (!keys2.includes(key) || !isDeepEqual(obj1[key], obj2[key])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
// Function to run a single test file | ||
@@ -58,0 +90,0 @@ async function runTestFile(testFile) { |
Sorry, the diff of this file is not supported yet
9569
144
81