-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopen-browser.test.ts
More file actions
44 lines (36 loc) · 1.34 KB
/
Copy pathopen-browser.test.ts
File metadata and controls
44 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, it, expect } from 'vitest'
import { openGenerationInBrowser, openUrlSafely } from './open-browser.js'
describe('openGenerationInBrowser', () => {
it('returns null when browser open succeeds', async () => {
const seenUrls: string[] = []
const result = await openGenerationInBrowser('gen_123', async (url) => {
seenUrls.push(url)
return undefined
})
expect(result).toBeNull()
expect(seenUrls).toEqual(['https://www.pixelmuse.studio/g/gen_123'])
})
it('returns error message when browser open fails', async () => {
const result = await openGenerationInBrowser('gen_456', async () => {
throw new Error('no browser available')
})
expect(result).toBe('no browser available')
})
it('returns fallback message for non-Error throws', async () => {
const result = await openGenerationInBrowser('gen_789', async () => {
throw { code: 'EFAIL' }
})
expect(result).toBe('Failed to open browser')
})
})
describe('openUrlSafely', () => {
it('opens an arbitrary URL unchanged', async () => {
const seenUrls: string[] = []
const result = await openUrlSafely('https://checkout.example/session/abc', async (url) => {
seenUrls.push(url)
return undefined
})
expect(result).toBeNull()
expect(seenUrls).toEqual(['https://checkout.example/session/abc'])
})
})