MCPcopy
hub / github.com/promptfoo/promptfoo / readTestFiles

Function readTestFiles

src/util/testCaseReader.ts:45–68  ·  view source on GitHub ↗
(
  pathOrGlobs: string | string[],
  basePath: string = '',
)

Source from the content-addressed store, hash-verified

43const SHA256_BLOB_SUFFIX = /\.[a-f0-9]{64}$/i;
44
45export async function readTestFiles(
46 pathOrGlobs: string | string[],
47 basePath: string = '',
48): Promise<Record<string, string | string[] | object>> {
49 if (typeof pathOrGlobs === 'string') {
50 pathOrGlobs = [pathOrGlobs];
51 }
52
53 const ret: Record<string, string | string[] | object> = {};
54 for (const pathOrGlob of pathOrGlobs) {
55 const resolvedPath = path.resolve(basePath, pathOrGlob);
56
57 const paths = globSync(resolvedPath, {
58 windowsPathsNoEscape: true,
59 });
60
61 for (const p of paths) {
62 const rawData = yaml.load(await fsPromises.readFile(p, 'utf-8'));
63 const yamlData = maybeLoadConfigFromExternalFile(rawData);
64 Object.assign(ret, yamlData);
65 }
66 }
67 return ret;
68}
69
70/**
71 * Reads test cases from a file in various formats (CSV, JSON, YAML, Python, JavaScript) and returns them as TestCase objects.

Callers 2

loadTestWithVarsFunction · 0.85

Calls 2

resolveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…