first commit

This commit is contained in:
2026-06-19 23:55:45 -07:00
commit f2e4730549
297 changed files with 30726 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import path from "path"
import { readFileSync } from "fs"
import { APP_ROOT_PATH } from "@/config"
import arrayWrap from "@/utils/array-wrap"
/**
* Usage:
* - `testDataPath('path/to/my-file.json')`
* - `testDataPath('path', 'to', 'my-file.json')`
*/
export function testDataPath(pathOrPathSegment: string | string[]): string {
const pathSegments = arrayWrap(pathOrPathSegment)
return path.join(APP_ROOT_PATH, "tests", "data", ...pathSegments)
}
/**
* Usage:
* - `specData('path/to/my-file.json')`
* - `specData('path', 'to', 'my-file.json')`
*
* Returns:
* - JSON parsed object if file is a JSON file
* - Raw file content otherwise
*/
export function loadTestData(pathOrPathSegment: string | string[]): string | object {
const filePath = testDataPath(pathOrPathSegment)
const rawData = readFileSync(filePath)
const extension = path.extname(filePath)
switch (extension) {
case ".json":
return JSON.parse(rawData.toString())
default:
return rawData.toString()
}
}
export default loadTestData