mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 14:04:41 -07:00
fix(tests): look for json in thrown error (#8601)
This commit is contained in:
@@ -55,9 +55,27 @@ describe('JSON output', () => {
|
|||||||
|
|
||||||
expect(thrown).toBeDefined();
|
expect(thrown).toBeDefined();
|
||||||
const message = (thrown as Error).message;
|
const message = (thrown as Error).message;
|
||||||
const jsonStart = message.indexOf('{');
|
|
||||||
expect(jsonStart).toBeGreaterThan(-1);
|
// Use a regex to find the first complete JSON object in the string
|
||||||
const payload = JSON.parse(message.slice(jsonStart));
|
const jsonMatch = message.match(/{[\s\S]*}/);
|
||||||
|
|
||||||
|
// Fail if no JSON-like text was found
|
||||||
|
expect(
|
||||||
|
jsonMatch,
|
||||||
|
'Expected to find a JSON object in the error output',
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
|
let payload;
|
||||||
|
try {
|
||||||
|
// Parse the matched JSON string
|
||||||
|
payload = JSON.parse(jsonMatch![0]);
|
||||||
|
} catch (parseError) {
|
||||||
|
console.error('Failed to parse the following JSON:', jsonMatch![0]);
|
||||||
|
throw new Error(
|
||||||
|
`Test failed: Could not parse JSON from error message. Details: ${parseError}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
expect(payload.error).toBeDefined();
|
expect(payload.error).toBeDefined();
|
||||||
expect(payload.error.type).toBe('Error');
|
expect(payload.error.type).toBe('Error');
|
||||||
expect(payload.error.code).toBe(1);
|
expect(payload.error.code).toBe(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user