|
| 1 | +// @vitest-environment jsdom |
| 2 | + |
| 3 | +import { describe, expect, it, vi } from 'vitest'; |
| 4 | +import { resolveTerminalFonts } from '../fonts'; |
| 5 | + |
| 6 | +describe('resolveTerminalFonts', () => { |
| 7 | + it('preserves the Window receiver while probing local fallbacks', async () => { |
| 8 | + const queryLocalFonts = vi.fn(function (this: Window) { |
| 9 | + expect(this).toBe(window); |
| 10 | + return Promise.resolve([ |
| 11 | + { |
| 12 | + family: 'Hiragino Sans GB', |
| 13 | + fullName: 'Hiragino Sans GB W3', |
| 14 | + postscriptName: 'HiraginoSansGB-W3', |
| 15 | + }, |
| 16 | + { |
| 17 | + family: 'Apple Color Emoji', |
| 18 | + fullName: 'Apple Color Emoji', |
| 19 | + postscriptName: 'AppleColorEmoji', |
| 20 | + }, |
| 21 | + ]); |
| 22 | + }); |
| 23 | + Object.defineProperty(window, 'queryLocalFonts', { |
| 24 | + configurable: true, |
| 25 | + value: queryLocalFonts, |
| 26 | + }); |
| 27 | + |
| 28 | + const fonts = await resolveTerminalFonts('code-150-test'); |
| 29 | + const families = fonts.flatMap((font) => |
| 30 | + typeof font === 'object' && 'family' in font ? [font.family] : [], |
| 31 | + ); |
| 32 | + |
| 33 | + expect(queryLocalFonts).toHaveBeenCalledOnce(); |
| 34 | + expect(families).toContain('Hiragino Sans GB'); |
| 35 | + expect(families).toContain('Apple Color Emoji'); |
| 36 | + }); |
| 37 | +}); |
0 commit comments