Unverified Commit f0e768e0 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Local font family name (#42286)

Use the name of the assigned const as the family name instead of trying
to get it from the font file. That way we know we won't get any invalid
characters in the font-family name.

fixes #42264

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 6d7c4c71
...@@ -53,13 +53,13 @@ function getDistanceFromNormalWeight(weight?: string) { ...@@ -53,13 +53,13 @@ function getDistanceFromNormalWeight(weight?: string) {
const fetchFonts: FontLoader = async ({ const fetchFonts: FontLoader = async ({
functionName, functionName,
variableName,
data, data,
emitFontFile, emitFontFile,
resolve, resolve,
fs, fs,
}) => { }) => {
const { const {
family,
src, src,
display, display,
fallback, fallback,
...@@ -88,7 +88,7 @@ const fetchFonts: FontLoader = async ({ ...@@ -88,7 +88,7 @@ const fetchFonts: FontLoader = async ({
...(declarations ...(declarations
? declarations.map(({ prop, value }) => [prop, value]) ? declarations.map(({ prop, value }) => [prop, value])
: []), : []),
['font-family', `'${fontMetadata?.familyName ?? family}'`], ['font-family', variableName],
['src', `url(${fontUrl}) format('${format}')`], ['src', `url(${fontUrl}) format('${format}')`],
['font-display', display], ['font-display', display],
...(weight ?? defaultWeight ...(weight ?? defaultWeight
......
...@@ -12,7 +12,6 @@ const extToFormat = { ...@@ -12,7 +12,6 @@ const extToFormat = {
} }
type FontOptions = { type FontOptions = {
family: string
src: Array<{ src: Array<{
path: string path: string
weight?: string weight?: string
...@@ -65,15 +64,11 @@ export function validateData(functionName: string, fontData: any): FontOptions { ...@@ -65,15 +64,11 @@ export function validateData(functionName: string, fontData: any): FontOptions {
} }
} }
let family: string | undefined
src = src.map((fontFile: any) => { src = src.map((fontFile: any) => {
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFile.path)?.[1] const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFile.path)?.[1]
if (!ext) { if (!ext) {
throw new Error(`Unexpected file \`${fontFile.path}\``) throw new Error(`Unexpected file \`${fontFile.path}\``)
} }
if (!family) {
family = /(.*\/)?(.+?)\.(woff|woff2|eot|ttf|otf)$/.exec(fontFile.path)![2]
}
return { return {
...fontFile, ...fontFile,
...@@ -99,7 +94,6 @@ export function validateData(functionName: string, fontData: any): FontOptions { ...@@ -99,7 +94,6 @@ export function validateData(functionName: string, fontData: any): FontOptions {
} }
return { return {
family: family!,
src, src,
display, display,
weight, weight,
......
...@@ -11,7 +11,11 @@ pub struct FontImportsGenerator<'a> { ...@@ -11,7 +11,11 @@ pub struct FontImportsGenerator<'a> {
} }
impl<'a> FontImportsGenerator<'a> { impl<'a> FontImportsGenerator<'a> {
fn check_call_expr(&mut self, call_expr: &CallExpr) -> Option<ImportDecl> { fn check_call_expr(
&mut self,
call_expr: &CallExpr,
variable_name: &Result<Ident, &Pat>,
) -> Option<ImportDecl> {
if let Callee::Expr(callee_expr) = &call_expr.callee { if let Callee::Expr(callee_expr) = &call_expr.callee {
if let Expr::Ident(ident) = &**callee_expr { if let Expr::Ident(ident) = &**callee_expr {
if let Some(font_function) = self.state.font_functions.get(&ident.to_id()) { if let Some(font_function) = self.state.font_functions.get(&ident.to_id()) {
...@@ -48,6 +52,12 @@ impl<'a> FontImportsGenerator<'a> { ...@@ -48,6 +52,12 @@ impl<'a> FontImportsGenerator<'a> {
query_json_values query_json_values
.insert(String::from("import"), Value::String(function_name)); .insert(String::from("import"), Value::String(function_name));
query_json_values.insert(String::from("arguments"), Value::Array(json)); query_json_values.insert(String::from("arguments"), Value::Array(json));
if let Ok(ident) = variable_name {
query_json_values.insert(
String::from("variableName"),
Value::String(ident.sym.to_string()),
);
}
let query_json = Value::Object(query_json_values); let query_json = Value::Object(query_json_values);
...@@ -81,7 +91,7 @@ impl<'a> FontImportsGenerator<'a> { ...@@ -81,7 +91,7 @@ impl<'a> FontImportsGenerator<'a> {
}; };
if let Some(expr) = &decl.init { if let Some(expr) = &decl.init {
if let Expr::Call(call_expr) = &**expr { if let Expr::Call(call_expr) = &**expr {
let import_decl = self.check_call_expr(call_expr); let import_decl = self.check_call_expr(call_expr, &ident);
if let Some(mut import_decl) = import_decl { if let Some(mut import_decl) = import_decl {
match var_decl.kind { match var_decl.kind {
......
import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[]}'; import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[],"variableName":"firaCode"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[],"variableName":"inter"}';
import React from 'react'; import React from 'react';
export { firaCode }; export { firaCode };
export { inter }; export { inter };
import inter1 from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"400"}]}'; import inter1 from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"400"}],"variableName":"inter1"}';
import inter2 from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"400"}]}'; import inter2 from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"400"}],"variableName":"inter2"}';
var i = 10; var i = 10;
var i2 = 20; var i2 = 20;
import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}]}'; import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}],"variableName":"a"}';
import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}]}'; import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}],"variableName":"a"}';
import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}]}'; import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}],"variableName":"a"}';
import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}]}'; import a from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"ABeeZee","arguments":[{}],"variableName":"a"}';
const a = fn({ const a = fn({
10: 'hello' 10: 'hello'
}); });
......
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{},[]]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{},[]],"variableName":"inter"}';
const a = fn(...{}, ...[]); const a = fn(...{}, ...[]);
import font from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"","arguments":[{"prop":true}]}'; import font from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"","arguments":[{"prop":true}],"variableName":"font"}';
import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[]}'; import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[],"variableName":"firaCode"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[],"variableName":"inter"}';
import React from 'react'; import React from 'react';
export { firaCode }; export { firaCode };
export { inter }; export { inter };
import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[]}'; import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Abel","arguments":[],"variableName":"firaCode"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[],"variableName":"inter"}';
import React from 'react'; import React from 'react';
export { firaCode }; export { firaCode };
export default inter; export default inter;
import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","fallback":["system-ui",{"key":false},[]],"preload":true,"key":{"key2":{}}}]}'; import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","fallback":["system-ui",{"key":false},[]],"preload":true,"key":{"key2":{}}}],"variableName":"firaCode"}';
import React from 'react'; import React from 'react';
console.log(firaCode); console.log(firaCode);
import acme1 from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"Acme","arguments":[{"variant":"400"}]}'; import acme1 from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"Acme","arguments":[{"variant":"400"}],"variableName":"acme1"}';
import React from 'react'; import React from 'react';
import geo from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Geo","arguments":["test",[1.0],{"a":2.0},3.0]}'; import geo from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Geo","arguments":["test",[1.0],{"a":2.0},3.0],"variableName":"geo"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}],"variableName":"inter"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}],"variableName":"inter"}';
import React from 'react'; import React from 'react';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900"}]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900"}],"variableName":"inter"}';
import fira from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","display":"swap"}]}'; import fira from 'cool-fonts/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","display":"swap"}],"variableName":"fira"}';
import React from 'react'; import React from 'react';
import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","fallback":["system-ui"]}]}'; import firaCode from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","fallback":["system-ui"]}],"variableName":"firaCode"}';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900","display":"swap"}],"variableName":"inter"}';
import React from 'react'; import React from 'react';
import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900"}]}'; import inter from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Inter","arguments":[{"variant":"900"}],"variableName":"inter"}';
import fira from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","display":"swap"}]}'; import fira from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[{"variant":"400","display":"swap"}],"variableName":"fira"}';
import React from 'react'; import React from 'react';
import fira from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[]}'; import fira from '@next/font/google/target.css?{"path":"pages/test.tsx","import":"Fira_Code","arguments":[],"variableName":"fira"}';
...@@ -57,6 +57,7 @@ export default async function nextFontLoader(this: any) { ...@@ -57,6 +57,7 @@ export default async function nextFontLoader(this: any) {
path: relativeFilePathFromRoot, path: relativeFilePathFromRoot,
import: functionName, import: functionName,
arguments: data, arguments: data,
variableName,
} = JSON.parse(this.resourceQuery.slice(1)) } = JSON.parse(this.resourceQuery.slice(1))
try { try {
...@@ -67,6 +68,7 @@ export default async function nextFontLoader(this: any) { ...@@ -67,6 +68,7 @@ export default async function nextFontLoader(this: any) {
let { css, fallbackFonts, adjustFontFallback, weight, style, variable } = let { css, fallbackFonts, adjustFontFallback, weight, style, variable } =
await fontLoader({ await fontLoader({
functionName, functionName,
variableName,
data, data,
config: fontLoaderOptions, config: fontLoaderOptions,
emitFontFile, emitFontFile,
......
...@@ -14,6 +14,7 @@ export type AdjustFontFallback = { ...@@ -14,6 +14,7 @@ export type AdjustFontFallback = {
export type FontLoader = (options: { export type FontLoader = (options: {
functionName: string functionName: string
variableName: string
data: any[] data: any[]
config: any config: any
emitFontFile: (content: Buffer, ext: string, preload: boolean) => string emitFontFile: (content: Buffer, ext: string, preload: boolean) => string
......
...@@ -108,7 +108,7 @@ describe('@next/font/google', () => { ...@@ -108,7 +108,7 @@ describe('@next/font/google', () => {
className: expect.stringMatching(/__className_.{6}/), className: expect.stringMatching(/__className_.{6}/),
style: { style: {
fontFamily: expect.stringMatching( fontFamily: expect.stringMatching(
/^'__Fraunces_.{6}', system-ui, '__Fraunces_Fallback_.{6}'$/ /^'__myFont1_.{6}', system-ui, '__myFont1_Fallback_.{6}'$/
), ),
fontStyle: 'italic', fontStyle: 'italic',
fontWeight: 100, fontWeight: 100,
...@@ -119,7 +119,7 @@ describe('@next/font/google', () => { ...@@ -119,7 +119,7 @@ describe('@next/font/google', () => {
variable: expect.stringMatching(/^__variable_.{6}$/), variable: expect.stringMatching(/^__variable_.{6}$/),
style: { style: {
fontFamily: expect.stringMatching( fontFamily: expect.stringMatching(
/^'__Indie_Flower_.{6}', '__Indie_Flower_Fallback_.{6}'$/ /^'__myFont2_.{6}', '__myFont2_Fallback_.{6}'$/
), ),
}, },
}) })
...@@ -238,7 +238,7 @@ describe('@next/font/google', () => { ...@@ -238,7 +238,7 @@ describe('@next/font/google', () => {
).not.toMatch(roboto100ItalicRegex) ).not.toMatch(roboto100ItalicRegex)
// Local font // Local font
const localFontRegex = /^__Fraunces_.{6}, __Fraunces_Fallback_.{6}$/ const localFontRegex = /^__myFont_.{6}, __myFont_Fallback_.{6}$/
expect( expect(
await browser.eval( await browser.eval(
'getComputedStyle(document.querySelector("#variables-local-font")).fontFamily' 'getComputedStyle(document.querySelector("#variables-local-font")).fontFamily'
...@@ -361,22 +361,22 @@ describe('@next/font/google', () => { ...@@ -361,22 +361,22 @@ describe('@next/font/google', () => {
const browser = await webdriver(next.url, '/with-local-fonts') const browser = await webdriver(next.url, '/with-local-fonts')
const ascentOverride = await browser.eval( const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Indie_Flower_Fallback")).ascentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont2_Fallback")).ascentOverride'
) )
expect(ascentOverride).toBe('103.26%') expect(ascentOverride).toBe('103.26%')
const descentOverride = await browser.eval( const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Indie_Flower_Fallback")).descentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont2_Fallback")).descentOverride'
) )
expect(descentOverride).toBe('51.94%') expect(descentOverride).toBe('51.94%')
const lineGapOverride = await browser.eval( const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Indie_Flower_Fallback")).lineGapOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont2_Fallback")).lineGapOverride'
) )
expect(lineGapOverride).toBe('0%') expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval( const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Indie_Flower_Fallback")).sizeAdjust' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont2_Fallback")).sizeAdjust'
) )
expect(sizeAdjust).toBe('94%') expect(sizeAdjust).toBe('94%')
}) })
...@@ -385,22 +385,22 @@ describe('@next/font/google', () => { ...@@ -385,22 +385,22 @@ describe('@next/font/google', () => {
const browser = await webdriver(next.url, '/with-local-fonts') const browser = await webdriver(next.url, '/with-local-fonts')
const ascentOverride = await browser.eval( const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Fraunces_Fallback")).ascentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont1_Fallback")).ascentOverride'
) )
expect(ascentOverride).toBe('84.71%') expect(ascentOverride).toBe('84.71%')
const descentOverride = await browser.eval( const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Fraunces_Fallback")).descentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont1_Fallback")).descentOverride'
) )
expect(descentOverride).toBe('22.09%') expect(descentOverride).toBe('22.09%')
const lineGapOverride = await browser.eval( const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Fraunces_Fallback")).lineGapOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont1_Fallback")).lineGapOverride'
) )
expect(lineGapOverride).toBe('0%') expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval( const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Fraunces_Fallback")).sizeAdjust' 'Array.from(document.fonts.values()).find(font => font.family.includes("myFont1_Fallback")).sizeAdjust'
) )
expect(sizeAdjust).toBe('115.45%') expect(sizeAdjust).toBe('115.45%')
}) })
...@@ -409,22 +409,22 @@ describe('@next/font/google', () => { ...@@ -409,22 +409,22 @@ describe('@next/font/google', () => {
const browser = await webdriver(next.url, '/with-local-fonts') const browser = await webdriver(next.url, '/with-local-fonts')
const ascentOverride = await browser.eval( const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Thin_Fallback")).ascentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("roboto_Fallback")).ascentOverride'
) )
expect(ascentOverride).toBe('92.49%') expect(ascentOverride).toBe('92.49%')
const descentOverride = await browser.eval( const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Thin_Fallback")).descentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("roboto_Fallback")).descentOverride'
) )
expect(descentOverride).toBe('24.34%') expect(descentOverride).toBe('24.34%')
const lineGapOverride = await browser.eval( const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Thin_Fallback")).lineGapOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("roboto_Fallback")).lineGapOverride'
) )
expect(lineGapOverride).toBe('0%') expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval( const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Thin_Fallback")).sizeAdjust' 'Array.from(document.fonts.values()).find(font => font.family.includes("roboto_Fallback")).sizeAdjust'
) )
expect(sizeAdjust).toBe('100.3%') expect(sizeAdjust).toBe('100.3%')
}) })
...@@ -433,22 +433,22 @@ describe('@next/font/google', () => { ...@@ -433,22 +433,22 @@ describe('@next/font/google', () => {
const browser = await webdriver(next.url, '/with-local-fonts') const browser = await webdriver(next.url, '/with-local-fonts')
const ascentOverride = await browser.eval( const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Fallback")).ascentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar1_Fallback")).ascentOverride'
) )
expect(ascentOverride).toBe('92.49%') expect(ascentOverride).toBe('92.49%')
const descentOverride = await browser.eval( const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Fallback")).descentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar1_Fallback")).descentOverride'
) )
expect(descentOverride).toBe('24.34%') expect(descentOverride).toBe('24.34%')
const lineGapOverride = await browser.eval( const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Fallback")).lineGapOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar1_Fallback")).lineGapOverride'
) )
expect(lineGapOverride).toBe('0%') expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval( const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Fallback")).sizeAdjust' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar1_Fallback")).sizeAdjust'
) )
expect(sizeAdjust).toBe('100.3%') expect(sizeAdjust).toBe('100.3%')
}) })
...@@ -457,22 +457,22 @@ describe('@next/font/google', () => { ...@@ -457,22 +457,22 @@ describe('@next/font/google', () => {
const browser = await webdriver(next.url, '/with-local-fonts') const browser = await webdriver(next.url, '/with-local-fonts')
const ascentOverride = await browser.eval( const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Black_Fallback")).ascentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar2_Fallback")).ascentOverride'
) )
expect(ascentOverride).toBe('92.49%') expect(ascentOverride).toBe('92.49%')
const descentOverride = await browser.eval( const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Black_Fallback")).descentOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar2_Fallback")).descentOverride'
) )
expect(descentOverride).toBe('24.34%') expect(descentOverride).toBe('24.34%')
const lineGapOverride = await browser.eval( const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Black_Fallback")).lineGapOverride' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar2_Fallback")).lineGapOverride'
) )
expect(lineGapOverride).toBe('0%') expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval( const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Roboto_Black_Fallback")).sizeAdjust' 'Array.from(document.fonts.values()).find(font => font.family.includes("robotoVar2_Fallback")).sizeAdjust'
) )
expect(sizeAdjust).toBe('100.3%') expect(sizeAdjust).toBe('100.3%')
}) })
......
...@@ -86,6 +86,7 @@ describe('@next/font/google loader', () => { ...@@ -86,6 +86,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
expect(css).toBe('OK\n') expect(css).toBe('OK\n')
expect(fetch).toHaveBeenCalledTimes(1) expect(fetch).toHaveBeenCalledTimes(1)
...@@ -112,6 +113,7 @@ describe('@next/font/google loader', () => { ...@@ -112,6 +113,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
expect(css).toBe('1\n2\n3\n4\n5\n6\n') expect(css).toBe('1\n2\n3\n4\n5\n6\n')
expect(fetch).toHaveBeenCalledTimes(6) expect(fetch).toHaveBeenCalledTimes(6)
...@@ -163,6 +165,7 @@ describe('@next/font/google loader', () => { ...@@ -163,6 +165,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Failed to fetch font \`Alkalami\`. "Failed to fetch font \`Alkalami\`.
...@@ -180,6 +183,7 @@ describe('@next/font/google loader', () => { ...@@ -180,6 +183,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"@next/font/google has no default export"` `"@next/font/google has no default export"`
...@@ -196,6 +200,7 @@ describe('@next/font/google loader', () => { ...@@ -196,6 +200,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unknown font \`Unknown Font\`"` `"Unknown font \`Unknown Font\`"`
...@@ -212,6 +217,7 @@ describe('@next/font/google loader', () => { ...@@ -212,6 +217,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Unknown weight \`123\` for font \`Inter\`. "Unknown weight \`123\` for font \`Inter\`.
...@@ -229,6 +235,7 @@ describe('@next/font/google loader', () => { ...@@ -229,6 +235,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Missing weight for font \`Abel\`. "Missing weight for font \`Abel\`.
...@@ -246,6 +253,7 @@ describe('@next/font/google loader', () => { ...@@ -246,6 +253,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Unknown style \`normal\` for font \`Molle\`. "Unknown style \`normal\` for font \`Molle\`.
...@@ -263,6 +271,7 @@ describe('@next/font/google loader', () => { ...@@ -263,6 +271,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid display value \`invalid\` for font \`Inter\`. "Invalid display value \`invalid\` for font \`Inter\`.
...@@ -280,6 +289,7 @@ describe('@next/font/google loader', () => { ...@@ -280,6 +289,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Axes can only be defined for variable fonts"` `"Axes can only be defined for variable fonts"`
...@@ -296,6 +306,7 @@ describe('@next/font/google loader', () => { ...@@ -296,6 +306,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Font \`Lora\` has no definable \`axes\`"` `"Font \`Lora\` has no definable \`axes\`"`
...@@ -312,6 +323,7 @@ describe('@next/font/google loader', () => { ...@@ -312,6 +323,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid axes value for font \`Inter\`, expected an array of axes. "Invalid axes value for font \`Inter\`, expected an array of axes.
...@@ -329,6 +341,7 @@ describe('@next/font/google loader', () => { ...@@ -329,6 +341,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid axes value \`INVALID\` for font \`Roboto Flex\`. "Invalid axes value \`INVALID\` for font \`Roboto Flex\`.
...@@ -346,6 +359,7 @@ describe('@next/font/google loader', () => { ...@@ -346,6 +359,7 @@ describe('@next/font/google loader', () => {
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, fs: {} as any,
isServer: true, isServer: true,
variableName: 'myFont',
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unexpected \`variable\` in weight array for font \`Inter\`. You only need \`variable\`, it includes all available weights."` `"Unexpected \`variable\` in weight array for font \`Inter\`. You only need \`variable\`, it includes all available weights."`
......
...@@ -10,6 +10,7 @@ describe('@next/font/local', () => { ...@@ -10,6 +10,7 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
...@@ -17,7 +18,7 @@ describe('@next/font/local', () => { ...@@ -17,7 +18,7 @@ describe('@next/font/local', () => {
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
"@font-face { "@font-face {
font-family: 'my-font'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
} }
...@@ -33,6 +34,7 @@ describe('@next/font/local', () => { ...@@ -33,6 +34,7 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
...@@ -40,7 +42,7 @@ describe('@next/font/local', () => { ...@@ -40,7 +42,7 @@ describe('@next/font/local', () => {
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
"@font-face { "@font-face {
font-family: 'my-font'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 100 900; font-weight: 100 900;
...@@ -66,6 +68,7 @@ describe('@next/font/local', () => { ...@@ -66,6 +68,7 @@ describe('@next/font/local', () => {
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
...@@ -75,7 +78,7 @@ describe('@next/font/local', () => { ...@@ -75,7 +78,7 @@ describe('@next/font/local', () => {
"@font-face { "@font-face {
font-feature-settings: \\"smcp\\" on; font-feature-settings: \\"smcp\\" on;
ascent-override: 90%; ascent-override: 90%;
font-family: 'my-font'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
} }
...@@ -115,6 +118,7 @@ describe('@next/font/local', () => { ...@@ -115,6 +118,7 @@ describe('@next/font/local', () => {
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`, emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { fs: {
readFile: (path, cb) => cb(null, path), readFile: (path, cb) => cb(null, path),
}, },
...@@ -122,7 +126,7 @@ describe('@next/font/local', () => { ...@@ -122,7 +126,7 @@ describe('@next/font/local', () => {
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
"@font-face { "@font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 100; font-weight: 100;
...@@ -130,7 +134,7 @@ describe('@next/font/local', () => { ...@@ -130,7 +134,7 @@ describe('@next/font/local', () => {
} }
@font-face { @font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 400; font-weight: 400;
...@@ -138,7 +142,7 @@ describe('@next/font/local', () => { ...@@ -138,7 +142,7 @@ describe('@next/font/local', () => {
} }
@font-face { @font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 700; font-weight: 700;
...@@ -146,7 +150,7 @@ describe('@next/font/local', () => { ...@@ -146,7 +150,7 @@ describe('@next/font/local', () => {
} }
@font-face { @font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 400; font-weight: 400;
...@@ -183,6 +187,7 @@ describe('@next/font/local', () => { ...@@ -183,6 +187,7 @@ describe('@next/font/local', () => {
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`, emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { fs: {
readFile: (path, cb) => cb(null, path), readFile: (path, cb) => cb(null, path),
}, },
...@@ -190,7 +195,7 @@ describe('@next/font/local', () => { ...@@ -190,7 +195,7 @@ describe('@next/font/local', () => {
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
"@font-face { "@font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 400; font-weight: 400;
...@@ -198,7 +203,7 @@ describe('@next/font/local', () => { ...@@ -198,7 +203,7 @@ describe('@next/font/local', () => {
} }
@font-face { @font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 400; font-weight: 400;
...@@ -206,7 +211,7 @@ describe('@next/font/local', () => { ...@@ -206,7 +211,7 @@ describe('@next/font/local', () => {
} }
@font-face { @font-face {
font-family: 'font1'; font-family: myFont;
src: url(/_next/static/media/my-font.woff2) format('woff2'); src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional; font-display: optional;
font-weight: 700; font-weight: 700;
...@@ -226,6 +231,7 @@ describe('@next/font/local', () => { ...@@ -226,6 +231,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
...@@ -242,6 +248,7 @@ describe('@next/font/local', () => { ...@@ -242,6 +248,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
...@@ -258,6 +265,7 @@ describe('@next/font/local', () => { ...@@ -258,6 +265,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn().mockResolvedValue(''), resolve: jest.fn().mockResolvedValue(''),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
...@@ -274,6 +282,7 @@ describe('@next/font/local', () => { ...@@ -274,6 +282,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
...@@ -297,6 +306,7 @@ describe('@next/font/local', () => { ...@@ -297,6 +306,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
...@@ -313,6 +323,7 @@ describe('@next/font/local', () => { ...@@ -313,6 +323,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: {}, fs: {},
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
...@@ -339,6 +350,7 @@ describe('@next/font/local', () => { ...@@ -339,6 +350,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { readFile: (path, cb) => cb(null, path) }, fs: { readFile: (path, cb) => cb(null, path) },
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
...@@ -366,6 +378,7 @@ describe('@next/font/local', () => { ...@@ -366,6 +378,7 @@ describe('@next/font/local', () => {
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isServer: true, isServer: true,
variableName: 'myFont',
fs: { readFile: (path, cb) => cb(null, path) }, fs: { readFile: (path, cb) => cb(null, path) },
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment