assertFileExists( $manifestPath, 'Run `npm run build` before this suite — the font manifest is a build artifact.' ); $manifest = json_decode((string) file_get_contents($manifestPath), true); $this->assertIsArray($manifest); $this->assertNotEmpty($manifest['preloads'] ?? [], 'The critical font weights must still be preloaded.'); foreach ($manifest['preloads'] as $preload) { $this->assertStringEndsWith('.woff2', (string) ($preload['file'] ?? '')); } foreach ($manifest['families'] ?? [] as $alias => $family) { foreach ($family['variants'] ?? [] as $key => $variant) { $this->assertNotEmpty($variant['files'] ?? [], "{$alias} {$key} lost every font file."); foreach ($variant['files'] as $file) { $this->assertSame( 'woff2', $file['format'] ?? null, "{$alias} {$key} declares a {$file['format']} file. Only woff2 is served — a second " .'format with the same family, weight and unicode-range overrides the woff2 rule and ' .'doubles the font traffic on the critical path.' ); } } } $stylesheet = $manifest['style']['file'] ?? null; $this->assertIsString($stylesheet); $css = (string) file_get_contents(public_path('build/'.$stylesheet)); $this->assertStringContainsString('format("woff2")', $css); $this->assertStringNotContainsString('format("woff")', $css); } public function test_no_woff_files_are_emitted_into_the_build(): void { $emitted = glob(public_path('build/assets/*.woff')) ?: []; $this->assertSame( [], array_map('basename', $emitted), 'The build emitted legacy woff files. They are never requested by a browser that supports woff2, ' .'which is every browser this site targets.' ); } }