Buckets:
evalstate/sandbox-testing-2 / hf-mcp-server /packages /app /test /server /utils /browser-detection.test.ts
| import { describe, it, expect } from 'vitest'; | |
| import { isBrowser } from '../../../src/server/utils/browser-detection.js'; | |
| describe('isBrowser', () => { | |
| it('returns false when accept header is missing', () => { | |
| expect(isBrowser({})).toBe(false); | |
| expect(isBrowser({ 'user-agent': 'Mozilla/5.0' })).toBe(false); | |
| }); | |
| it('returns false when accept contains text/event-stream', () => { | |
| // this is VSCode | |
| expect(isBrowser({ accept: 'text/event-stream' })).toBe(false); | |
| expect(isBrowser({ accept: 'text/event-stream, text/html' })).toBe(false); | |
| }); | |
| it('returns false when accept contains application/json', () => { | |
| expect(isBrowser({ accept: 'application/json' })).toBe(false); | |
| expect(isBrowser({ accept: 'application/json, text/plain' })).toBe(false); | |
| }); | |
| it('returns true when accept contains */*', () => { | |
| expect(isBrowser({ accept: '*/*' })).toBe(true); | |
| expect(isBrowser({ accept: 'text/html, */*' })).toBe(true); | |
| }); | |
| it('returns false for other accept headers', () => { | |
| expect(isBrowser({ accept: 'text/html' })).toBe(false); | |
| expect(isBrowser({ accept: 'text/plain' })).toBe(false); | |
| expect(isBrowser({ accept: 'image/png' })).toBe(false); | |
| }); | |
| it('handles array accept headers', () => { | |
| expect(isBrowser({ accept: ['text/event-stream'] })).toBe(false); | |
| expect(isBrowser({ accept: ['*/*', 'text/html'] })).toBe(true); | |
| expect(isBrowser({ accept: ['application/json', 'text/plain'] })).toBe(false); | |
| }); | |
| it('real browser examples', () => { | |
| // Chrome | |
| expect( | |
| isBrowser({ | |
| accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8', | |
| }) | |
| ).toBe(true); | |
| // Safari | |
| expect( | |
| isBrowser({ | |
| accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
| }) | |
| ).toBe(true); | |
| // hugging face javascript mcp-client | |
| expect( | |
| isBrowser({ | |
| accept: 'text/event-stream', | |
| }) | |
| ).toBe(false); | |
| // hugging face javascript mcp-client | |
| expect( | |
| isBrowser({ | |
| accept: 'text/event-stream', | |
| }) | |
| ).toBe(false); | |
| }); | |
| it('API client examples', () => { | |
| // SSE client | |
| expect(isBrowser({ accept: 'text/event-stream' })).toBe(false); | |
| // JSON API client | |
| expect(isBrowser({ accept: 'application/json' })).toBe(false); | |
| // Mixed API client | |
| expect(isBrowser({ accept: 'application/json, text/event-stream' })).toBe(false); | |
| }); | |
| }); | |
Xet Storage Details
- Size:
- 2.36 kB
- Xet hash:
- 5f63d77d2280fd4523860f6f0b47e156c8f6e26a7d8d071e6e51c262596dcf61
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.