mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 21:47:02 +03:00
Print when partial deep equals fails
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {config} from "../src/config";
|
||||
import { Logger } from "../src/utils/logger";
|
||||
|
||||
export function getbaseURL(): string {
|
||||
return `http://localhost:${config.port}`;
|
||||
@@ -13,14 +14,27 @@ export type Done = (err?: any) => void;
|
||||
*
|
||||
* Check object contains expected properties
|
||||
*/
|
||||
export const partialDeepEquals = (actual: Record<string, any>, expected: Record<string, any>): boolean => {
|
||||
export const partialDeepEquals = (actual: Record<string, any>, expected: Record<string, any>, print = true): boolean => {
|
||||
// loop over key, value of expected
|
||||
for (const [ key, value ] of Object.entries(expected)) {
|
||||
// if value is object or array, recurse
|
||||
if (Array.isArray(value) || typeof value === "object") {
|
||||
if (!partialDeepEquals(actual?.[key], value)) return false;
|
||||
if (!partialDeepEquals(actual?.[key], value, false)) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (actual?.[key] !== value) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (actual?.[key] !== value) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
function printActualExpected(actual: Record<string, any>, expected: Record<string, any>): void {
|
||||
Logger.error(`Actual: ${JSON.stringify(actual)}`);
|
||||
Logger.error(`Expected: ${JSON.stringify(expected)}`);
|
||||
}
|
||||
Reference in New Issue
Block a user