Add fonts, autotable, autotable examples
This commit is contained in:
@@ -215,3 +215,61 @@ func TestExtractCandidatesRegexLiterals(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The preflight is written against Tailwind's compile-time CSS functions, e.g.
|
||||
// `font-family: --theme(--default-font-family, …)`. If those are not resolved, they
|
||||
// reach the browser verbatim; the browser cannot parse `--theme(…)` and DROPS THE
|
||||
// WHOLE DECLARATION. The symptom is subtle and global: every page silently loses its
|
||||
// font-family and falls back to the browser default, and no @theme override of
|
||||
// --font-sans can ever take effect. That shipped for a while, so pin it.
|
||||
func TestPreflightResolvesThemeFunctions(t *testing.T) {
|
||||
css, _, err := twCompile(`@import "tailwindcss";`, ".", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
flat := strings.Join(strings.Fields(css), " ")
|
||||
if strings.Contains(css, "--theme(") {
|
||||
t.Error("the compiled CSS still contains an unresolved --theme(…); the browser will drop those declarations")
|
||||
}
|
||||
if !strings.Contains(flat, "font-family: var(--default-font-family)") {
|
||||
t.Error("preflight did not resolve html's font-family to a var()")
|
||||
}
|
||||
}
|
||||
|
||||
// And the whole point of resolving it: an app's @theme override of --font-sans must
|
||||
// actually reach the page.
|
||||
func TestThemeFontOverrideReachesHTML(t *testing.T) {
|
||||
css, _, err := twCompile(`
|
||||
@import "tailwindcss";
|
||||
|
||||
@font-face {
|
||||
font-family: "Lora";
|
||||
src: url("/fonts/lora.woff2") format("woff2");
|
||||
}
|
||||
|
||||
@theme {
|
||||
--font-sans: "Lora", serif;
|
||||
}
|
||||
`, ".", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The chain the browser walks: html -> --default-font-family -> --font-sans.
|
||||
flat := strings.Join(strings.Fields(css), " ")
|
||||
for _, want := range []string{
|
||||
"font-family: var(--default-font-family)",
|
||||
"--default-font-family: var(--font-sans)",
|
||||
`--font-sans: "Lora", serif`,
|
||||
} {
|
||||
if !strings.Contains(flat, want) {
|
||||
t.Errorf("missing %q — the font override does not reach the page", want)
|
||||
}
|
||||
}
|
||||
// A vendored face must survive the build; dropping it would leave the family
|
||||
// declared but never loaded.
|
||||
if !strings.Contains(css, "@font-face") || !strings.Contains(css, "lora.woff2") {
|
||||
t.Error("@font-face was dropped from the output")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user