|
6 | 6 | setConfig, |
7 | 7 | } from '@doc-kit/core/utils/configuration/index.mjs'; |
8 | 8 |
|
| 9 | +import { FONTS } from '../../constants.mjs'; |
9 | 10 | import { |
| 11 | + buildPreloads, |
10 | 12 | buildHead, |
11 | 13 | populateWithEvaluation, |
12 | 14 | resolvePageRoot, |
@@ -111,6 +113,36 @@ describe('resolvePageRoot', () => { |
111 | 113 | }); |
112 | 114 | }); |
113 | 115 |
|
| 116 | +describe('buildPreloads', () => { |
| 117 | + it('resolves every shipped font against the page root', () => { |
| 118 | + const result = buildPreloads('../'); |
| 119 | + |
| 120 | + // A hint per shipped face, or the unlisted ones load late after all. |
| 121 | + assert.strictEqual(result.match(/rel="preload"/g).length, FONTS.length); |
| 122 | + |
| 123 | + for (const font of FONTS) { |
| 124 | + assert.ok(result.includes(`href="../assets/fonts/${font}"`)); |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + it('keeps an absolute root absolute', () => { |
| 129 | + const result = buildPreloads('https://nodejs.org/docs/'); |
| 130 | + |
| 131 | + assert.ok( |
| 132 | + result.includes(`href="https://nodejs.org/docs/assets/fonts/${FONTS[0]}"`) |
| 133 | + ); |
| 134 | + }); |
| 135 | + |
| 136 | + it('renders crossorigin valueless, since fonts are fetched in CORS mode', () => { |
| 137 | + // Without it the stylesheet re-fetches the font instead of reusing it. |
| 138 | + const hints = buildPreloads('./').split('\n'); |
| 139 | + |
| 140 | + for (const hint of hints) { |
| 141 | + assert.match(hint, /as="font" type="font\/woff2" crossorigin \/>$/); |
| 142 | + } |
| 143 | + }); |
| 144 | +}); |
| 145 | + |
114 | 146 | describe('buildHead', () => { |
115 | 147 | it('renders meta tags from attribute bags', () => { |
116 | 148 | const result = buildHead({ |
|
0 commit comments