From 956a66adac45b5f95d17565b32aed42796917d0e Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 13 Feb 2025 14:25:31 +0100 Subject: [PATCH] migrate second --- tests/playwright-test/ui-mode-llm.spec.ts | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/playwright-test/ui-mode-llm.spec.ts b/tests/playwright-test/ui-mode-llm.spec.ts index 69e318dd69..9d850d56ca 100644 --- a/tests/playwright-test/ui-mode-llm.spec.ts +++ b/tests/playwright-test/ui-mode-llm.spec.ts @@ -61,7 +61,23 @@ test('openai', async ({ runUITest, server }) => { `); }); -test('anthropic', async ({ runUITest }) => { +test('anthropic', async ({ runUITest, server }) => { + server.setRoute('/v1/messages', async (req, res) => { + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Headers', '*'); + if (req.method === 'OPTIONS') + return res.end(); + + expect(req.headers['x-api-key']).toBe('fake-key'); + expect((await req.postBody).toString()).toContain(`- button \\"Submit\\"`); + const event = { + type: 'content_block_delta', + delta: { text: 'This is a mock response' }, + }; + res.setHeader('Content-Type', 'text/event-stream'); + res.write(`data: ${JSON.stringify(event)}\n\n`); + }); + const { page } = await runUITest({ 'a.test.ts': ` import { test, expect } from '@playwright/test'; @@ -71,19 +87,8 @@ test('anthropic', async ({ runUITest }) => { }); `, }, { - ANTHROPIC_API_KEY: 'fake-key' - }); - - await page.context().route('https://api.anthropic.com/**', async (route, request) => { - expect(await request.headerValue('x-api-key')).toBe('fake-key'); - expect(request.postData()).toContain(`- button \\"Submit\\"`); - const event = { - type: 'content_block_delta', - delta: { text: 'This is a mock response' }, - }; - await route.fulfill({ - body: `\n\ndata: ${JSON.stringify(event)}\n\n` - }); + ANTHROPIC_API_KEY: 'fake-key', + ANTHROPIC_BASE_URL: server.PREFIX, }); await page.getByTitle('Run all').click();