MCPcopy
hub / github.com/promptfoo/promptfoo / loadFromJavaScriptFile

Function loadFromJavaScriptFile

src/assertions/utils.ts:39–57  ·  view source on GitHub ↗
(
  filePath: string,
  functionName: string | undefined,
  args: unknown[],
  // biome-ignore lint/suspicious/noExplicitAny: I think this is hotloading JS
)

Source from the content-addressed store, hash-verified

37}
38
39export async function loadFromJavaScriptFile(
40 filePath: string,
41 functionName: string | undefined,
42 args: unknown[],
43 // biome-ignore lint/suspicious/noExplicitAny: I think this is hotloading JS
44): Promise<any> {
45 const requiredModule = await importModule(filePath, functionName);
46 if (functionName && typeof requiredModule[functionName] === 'function') {
47 return requiredModule[functionName](...args);
48 } else if (typeof requiredModule === 'function') {
49 return requiredModule(...args);
50 } else if (requiredModule.default && typeof requiredModule.default === 'function') {
51 return requiredModule.default(...args);
52 } else {
53 throw new Error(
54 `Assertion malformed: ${filePath} must export a function or have a default export as a function`,
55 );
56 }
57}
58
59export function processFileReference(fileRef: string): object | string {
60 const basePath = cliState.basePath || '';

Callers 4

utils.test.tsFile · 0.90
llm-rubric.test.tsFile · 0.90
runAssertionFunction · 0.90
loadRubricPromptFunction · 0.90

Calls 1

importModuleFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…