"""Tests for `.astro` extraction (#850). Astro files have a TypeScript frontmatter block (`---...---`) at the top where nearly all imports live, followed by an HTML-with-expressions template and optionally ` """, ) layout = _write(tmp_path / "src/layouts/Layout.astro", "---\n---\n\n") hydrate = _write(tmp_path / "src/client/hydrate.ts", "export function hydrate(){}\n") result = extract_astro(page) targets = _import_targets(result, relation="imports_from") assert _make_id(str(layout)) in targets assert _make_id(str(hydrate)) in targets def test_extract_astro_no_frontmatter_does_not_crash(tmp_path): """Astro permits frontmatter-less files (pure-HTML pages). Must not raise.""" page = _write( tmp_path / "src/pages/plain.astro", "

no frontmatter here

\n", ) result = extract_astro(page) # Empty/no-imports result is acceptable; the extractor must just not crash. assert isinstance(result, dict) assert _import_targets(result, relation="imports_from") == set() def test_extract_astro_handles_tsconfig_path_alias(tmp_path): _write( tmp_path / "tsconfig.json", """{ "compilerOptions": { "baseUrl": ".", "paths": { "@components/*": ["src/components/*"] } } } """, ) page = _write( tmp_path / "src/pages/alias.astro", """--- import Hero from '@components/Hero.astro'; --- """, ) hero = _write(tmp_path / "src/components/Hero.astro", "---\n---\n

h

\n") result = extract_astro(page) targets = _import_targets(result, relation="imports_from") assert _make_id(str(hero)) in targets