Spaces:
Paused
Paused
Download src/lib/web-search.test.ts from WaveCut/Bonsai-Chat-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/WaveCut/Bonsai-Chat-WebGPU/resolve/main/src/lib/web-search.test.ts
- Command line
-
hf download hf://spaces/WaveCut/Bonsai-Chat-WebGPU/src/lib/web-search.test.ts
-
curl -L -o web-search.test.ts https://huggingface.co/spaces/WaveCut/Bonsai-Chat-WebGPU/resolve/main/src/lib/web-search.test.ts
1.7 kB
| import { describe, expect, it, vi } from 'vitest'; | |
| import { searchWikipedia } from './web-search'; | |
| describe('Wikipedia search provider', () => { | |
| it('uses anonymous CORS search and returns plain-text results', async () => { | |
| const fetchMock = vi.fn(async () => new Response(JSON.stringify({ | |
| query: { search: [{ title: 'WebGPU', snippet: '<span>GPU</span> API & browser', timestamp: '2026-01-01T00:00:00Z' }] }, | |
| }), { status: 200 })) as unknown as typeof fetch; | |
| const result = await searchWikipedia(' WebGPU ', 'en', 3, undefined, fetchMock); | |
| const [url, init] = vi.mocked(fetchMock).mock.calls[0] ?? []; | |
| expect(String(url)).toContain('en.wikipedia.org/w/api.php'); | |
| expect(String(url)).toContain('list=search'); | |
| expect(String(url)).toContain('origin=*'); | |
| expect(init).toMatchObject({ credentials: 'omit', referrerPolicy: 'no-referrer' }); | |
| expect(result).toEqual({ | |
| provider: 'wikipedia', | |
| query: 'WebGPU', | |
| language: 'en', | |
| results: [{ | |
| title: 'WebGPU', | |
| snippet: 'GPU API & browser', | |
| url: 'https://en.wikipedia.org/wiki/WebGPU', | |
| updatedAt: '2026-01-01T00:00:00Z', | |
| }], | |
| }); | |
| }); | |
| it('infers Russian and bounds the requested result count', async () => { | |
| const fetchMock = vi.fn(async () => new Response('{"query":{"search":[]}}', { status: 200 })) as unknown as typeof fetch; | |
| const result = await searchWikipedia('браузер', undefined, 99, undefined, fetchMock); | |
| const [url] = vi.mocked(fetchMock).mock.calls[0] ?? []; | |
| expect(result.language).toBe('ru'); | |
| expect(String(url)).toContain('ru.wikipedia.org'); | |
| expect(String(url)).toContain('srlimit=8'); | |
| }); | |
| }); | |