Skip to content

Commit 662183a

Browse files
test: update convert mocks in line with latest mock response repo
1 parent fd3cdf9 commit 662183a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/ai/__tests__/test-utils/convert-mocks.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const fs = require('fs');
2020
// eslint-disable-next-line @typescript-eslint/no-require-imports
2121
const { join } = require('path');
2222

23-
function findMockResponseDir(): string {
23+
function findMockResponseDir(backend: string): string {
2424
const directories = fs
2525
.readdirSync(__dirname, { withFileTypes: true })
2626
.filter(
@@ -36,18 +36,22 @@ function findMockResponseDir(): string {
3636
throw new Error('Multiple directories starting with "vertexai-sdk-test-data*" found');
3737
}
3838

39-
return join(__dirname, directories[0], 'mock-responses', 'vertexai');
39+
return join(__dirname, directories[0], 'mock-responses', backend);
4040
}
4141

4242
async function main(): Promise<void> {
43-
const mockResponseDir = findMockResponseDir();
44-
const list = fs.readdirSync(mockResponseDir);
45-
const lookup: Record<string, string> = {};
46-
// eslint-disable-next-line guard-for-in
47-
for (const fileName of list) {
48-
console.log(`attempting to read ${mockResponseDir}/${fileName}`)
49-
const fullText = fs.readFileSync(join(mockResponseDir, fileName), 'utf-8');
50-
lookup[fileName] = fullText;
43+
const backendNames = ['googleai', 'vertexai'];
44+
const lookup: Record<string, Record<string, string>> = {};
45+
46+
for (const backend of backendNames) {
47+
const mockResponseDir = findMockResponseDir(backend);
48+
const list = fs.readdirSync(mockResponseDir);
49+
lookup[backend] = {};
50+
const backendLookup = lookup[backend];
51+
for (const fileName of list) {
52+
const fullText = fs.readFileSync(join(mockResponseDir, fileName), 'utf-8');
53+
backendLookup[fileName] = fullText;
54+
}
5155
}
5256
let fileText = `// Generated from mocks text files.`;
5357

0 commit comments

Comments
 (0)