mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-03 07:09:01 +03:00
move utils to seperate files and folder, update imports
This commit is contained in:
5
test/utils/getBaseURL.ts
Normal file
5
test/utils/getBaseURL.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { config } from "../../src/config";
|
||||
|
||||
export function getbaseURL(): string {
|
||||
return `http://localhost:${config.port}`;
|
||||
}
|
||||
24
test/utils/partialDeepEquals.ts
Normal file
24
test/utils/partialDeepEquals.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Logger } from "../../src/utils/logger";
|
||||
|
||||
function printActualExpected(actual: Record<string, any>, expected: Record<string, any>): void {
|
||||
Logger.error(`Actual: ${JSON.stringify(actual)}`);
|
||||
Logger.error(`Expected: ${JSON.stringify(expected)}`);
|
||||
}
|
||||
|
||||
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, false)) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (actual?.[key] !== value) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
11
test/utils/utils.ts
Normal file
11
test/utils/utils.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Duplicated from Mocha types. TypeScript doesn't infer that type by itself for some reason.
|
||||
*/
|
||||
export type Done = (err?: any) => void;
|
||||
|
||||
export const postJSON = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user