Skip to content

Commit b28a804

Browse files
committed
fixup! e2e test
1 parent ffbc751 commit b28a804

File tree

2 files changed

+108
-21
lines changed

2 files changed

+108
-21
lines changed

tests/features/jimaku.spec.ts

+81-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,86 @@ test('測試彈出同傳視窗', async ({ room, context, optionPageUrl, page, co
125125
await expect(checkbox).not.toBeChecked()
126126
})
127127

128+
test('测试同传字幕AI总结', { tag: "@scoped" }, async ({ room, content: p, context, optionPageUrl, page }) => {
129+
130+
logger.info('正在修改設定...')
131+
const settingsPage = await context.newPage()
132+
await settingsPage.bringToFront()
133+
await settingsPage.goto(optionPageUrl, { waitUntil: 'domcontentloaded' })
134+
await settingsPage.waitForTimeout(1000)
135+
136+
await settingsPage.getByText('功能设定').click()
137+
await settingsPage.getByText('AI 设定').click()
138+
await settingsPage.getByText('启用同传字幕AI总结').click()
139+
await settingsPage.getByText('保存设定').click()
140+
await settingsPage.waitForTimeout(2000)
141+
142+
logger.info('正在測試AI总结...')
143+
await page.bringToFront()
144+
const buttonList = await getButtonList(p)
145+
expect(buttonList.length).toBe(3)
146+
await expect(buttonList[2]).toHaveText('同传字幕AI总结')
147+
148+
149+
await p.locator('#subtitle-list').waitFor({ state: 'visible' })
150+
const conversations = [
151+
'大家好',
152+
'早上好',
153+
'知道我今天吃了什么吗?',
154+
'是麦当劳哦!',
155+
'"不就个麦当劳而已吗"不是啦',
156+
'是最近那个很热门的新品',
157+
'对,就是那个',
158+
'然后呢, 今天久违的出门了',
159+
'对,平时都是宅在家里的呢',
160+
'"终于长大了"喂w',
161+
'然后今天去了漫展来着',
162+
'很多人呢',
163+
'之前的我看到那么多人肯定社恐了',
164+
'但今次意外的没有呢',
165+
'"果然是长大了"也是呢',
166+
'然后呢, 今天买了很多东西',
167+
'插画啊,手办啊,周边之类的',
168+
'荷包大出血w',
169+
'不过觉得花上去应该值得的...吧?',
170+
'喂,好过分啊',
171+
'不过确实不应该花那么多钱的',
172+
'然后呢,回家途中看到了蟑螂的尸体',
173+
'太恶心了',
174+
'然后把我一整天好心情搞没了w',
175+
'"就因为一个蟑螂"对www',
176+
'不过跟你们谈完反而心情好多了',
177+
'谢谢大家',
178+
'那么今天的杂谈就到这里吧',
179+
'下次再见啦',
180+
'拜拜~'
181+
]
182+
183+
for (const danmaku of conversations.map(t => `主播:${t}`)) {
184+
await room.sendDanmaku(`【${danmaku}】`)
185+
}
186+
await p.waitForTimeout(3000)
187+
188+
let subtitleList = await p.locator('#subtitle-list > p').filter({ hasText: '主播:' }).all()
189+
expect(subtitleList.length).toBe(conversations.length)
190+
191+
const newWindow = context.waitForEvent('page', { predicate: p => p.url().includes('summarizer.html') })
192+
await buttonList[2].click()
193+
const summarizer = await newWindow
194+
await summarizer.bringToFront()
195+
await expect(summarizer.getByText('正在加载同传字幕总结')).toBeVisible()
196+
await summarizer.waitForTimeout(3000)
197+
198+
await expect(summarizer.getByText('正在加载同传字幕总结')).toBeHidden()
199+
200+
await expect(summarizer.getByText('这位日本Vtuber')).toBeVisible()
201+
await expect(summarizer.getByText('直播')).toBeVisible()
202+
await expect(summarizer.getByText('观众')).toBeVisible()
203+
await expect(summarizer.getByText('麦当劳')).toBeVisible()
204+
await expect(summarizer.getByText('漫展')).toBeVisible()
205+
await expect(summarizer.getByText('蟑螂')).toBeVisible()
206+
})
207+
128208

129209
test('測試離線記錄彈幕', async ({ room, content: p, context, optionPageUrl, page }) => {
130210

@@ -340,7 +420,7 @@ test('測試保存設定後 css 能否生效', async ({ context, content, option
340420
settingsPage.getByTestId('jimaku-position'),
341421
'置左'
342422
)
343-
423+
344424
await settingsPage.getByTestId('jimaku-color').fill('#123456')
345425

346426

tests/units/llm.spec.ts

+27-20
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@ test('嘗試使用 Cloudflare AI 對話', { tag: "@scoped" }, async () => {
77

88
test.skip(!process.env.CF_ACCOUNT_ID || !process.env.CF_API_TOKEN, '請設定 CF_ACCOUNT_ID 和 CF_API_TOKEN 環境變數')
99

10-
// await modules['llm'].loadToPage()
11-
// await modules['utils'].loadToPage()
12-
13-
// const res = await page.evaluate(async ({ accountId, apiToken }) => {
14-
// const { llms } = window as any
15-
// console.log('llms: ', llms)
16-
// const llm = await llms.createLLMProvider('cloudflare', accountId, apiToken)
17-
// return await llm.prompt('你好')
18-
// }, { accountId: process.env.CF_ACCOUNT_ID, apiToken: process.env.CF_API_TOKEN })
19-
2010
const llm = createLLMProvider('qwen', process.env.CF_ACCOUNT_ID, process.env.CF_API_TOKEN)
11+
12+
logger.info('正在测试 json 返回请求...')
2113
const res = await llm.prompt('你好')
2214

2315
logger.info('response: ', res)
2416
expect(res).not.toBeUndefined()
2517
expect(res).not.toBe('')
2618

19+
logger.info('正在测试 SSE 请求...')
20+
const res2 = llm.promptStream('地球为什么是圆的?')
21+
22+
let msg = '';
23+
for await (const r of res2) {
24+
logger.info('response: ', r)
25+
msg += r
26+
}
27+
28+
expect(msg).not.toBeUndefined()
29+
expect(msg).not.toBe('')
2730
})
2831

2932
test('嘗試使用 Gemini Nano 對話', { tag: "@scoped" }, async ({ page, modules }) => {
@@ -51,21 +54,25 @@ test('嘗試使用 Gemini Nano 對話', { tag: "@scoped" }, async ({ page, modul
5154

5255
test('嘗試使用 Remote Worker 對話', { tag: "@scoped" }, async () => {
5356

54-
// await modules['llm'].loadToPage()
55-
// await modules['utils'].loadToPage()
56-
57-
// const res = await page.evaluate(async () => {
58-
// const { llms } = window as any
59-
// console.log('llms: ', llms)
60-
// const llm = await llms.createLLMProvider('worker')
61-
// return await llm.prompt('你好')
62-
// })
63-
6457
const llm = createLLMProvider('worker')
58+
59+
logger.info('正在测试 json 返回请求...')
6560
const res = await llm.prompt('你好')
6661

6762
logger.info('response: ', res)
6863
expect(res).not.toBeUndefined()
6964
expect(res).not.toBe('')
7065

66+
logger.info('正在测试 SSE 请求...')
67+
const res2 = llm.promptStream('地球为什么是圆的?')
68+
69+
let msg = '';
70+
for await (const r of res2) {
71+
logger.info('response: ', r)
72+
msg += r
73+
}
74+
75+
expect(msg).not.toBeUndefined()
76+
expect(msg).not.toBe('')
77+
7178
})

0 commit comments

Comments
 (0)