diff --git a/src/ui/fonts.ts b/src/ui/fonts.ts index c8bb7463..520c6ff2 100644 --- a/src/ui/fonts.ts +++ b/src/ui/fonts.ts @@ -2,13 +2,11 @@ import codePro400 from './fonts/source-code-pro-latin-400-normal.woff2?url'; import sans400 from './fonts/source-sans-3-latin-400-normal.woff2?url'; import sans500 from './fonts/source-sans-3-latin-500-normal.woff2?url'; import sans600 from './fonts/source-sans-3-latin-600-normal.woff2?url'; -import sans700 from './fonts/source-sans-3-latin-700-normal.woff2?url'; export const FACES: readonly [family: string, url: string, weight: string][] = [ ['Source Sans 3', sans400, '400'], ['Source Sans 3', sans500, '500'], ['Source Sans 3', sans600, '600'], - ['Source Sans 3', sans700, '700'], ['Source Code Pro', codePro400, '400'], ]; diff --git a/src/ui/fonts/source-sans-3-latin-700-normal.woff2 b/src/ui/fonts/source-sans-3-latin-700-normal.woff2 deleted file mode 100644 index 3cb944ca..00000000 Binary files a/src/ui/fonts/source-sans-3-latin-700-normal.woff2 and /dev/null differ diff --git a/tests/ui/fonts.test.ts b/tests/ui/fonts.test.ts index d05eede3..f863afb7 100644 --- a/tests/ui/fonts.test.ts +++ b/tests/ui/fonts.test.ts @@ -97,27 +97,45 @@ function codePoints(file: string): Set { return found; } +/** The weights `src/` sets as `fontWeight`, plus the 400 a style without one draws in. */ +function usedWeights(): Set { + const used = new Set(['400']); + for (const file of sources('src')) + for (const [, setting] of readFileSync(file, 'utf8').matchAll(/fontWeight:([^,\n}]*)/g)) + for (const [, weight] of setting!.matchAll(/'(\d{3}|bold|normal)'/g)) + used.add(weight === 'bold' ? '700' : weight === 'normal' ? '400' : weight!); + return used; +} + describe('editor fonts', () => { + const loaded = new Set( + FACES.filter(([family]) => family === 'Source Sans 3').map(([, , weight]) => weight), + ); + it('loads a face for every weight the editor sets (#214)', () => { - const loaded = new Set( - FACES.filter(([family]) => family === 'Source Sans 3').map(([, , weight]) => weight), - ); - const used = new Set(['400']); - for (const file of sources('src')) - for (const [, setting] of readFileSync(file, 'utf8').matchAll(/fontWeight:([^,\n}]*)/g)) - for (const [, weight] of setting!.matchAll(/'(\d{3}|bold|normal)'/g)) - used.add(weight === 'bold' ? '700' : weight === 'normal' ? '400' : weight!); + const used = usedWeights(); expect(used.has('500')).toBe(true); for (const weight of used) expect(loaded, `weight ${weight}`).toContain(weight); }); - it('ships a file for every face it loads', () => { - const files = readdirSync(FONT_DIR); + // Every face is waited for before the editor starts (#273). + it('loads no face the editor never sets', () => { + const used = usedWeights(); + for (const weight of loaded) expect(used, `weight ${weight}`).toContain(weight); + }); + + it('ships a file for every face it loads, and no other', () => { + const files = readdirSync(FONT_DIR).filter((f) => f.endsWith('.woff2')); for (const [, url, weight] of FACES) expect( files.some((f) => url.endsWith(f)), `${url} (${weight})`, ).toBe(true); + for (const file of files) + expect( + FACES.some(([, url]) => url.endsWith(file)), + file, + ).toBe(true); }); it('reads the Latin subset from the files themselves', () => {