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

@next/font/google fetch error dev (#42637)

If `@next/font/google` fails to fetch the font in DEV, return the
fallback font instead of throwing so you still can run the app. In build
it still throws.

## 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)
parent 85b200a8
...@@ -34,7 +34,9 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -34,7 +34,9 @@ const downloadGoogleFonts: FontLoader = async ({
data, data,
config, config,
emitFontFile, emitFontFile,
isDev,
isServer, isServer,
loaderContext,
}) => { }) => {
const subsets = config?.subsets || [] const subsets = config?.subsets || []
...@@ -69,14 +71,41 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -69,14 +71,41 @@ const downloadGoogleFonts: FontLoader = async ({
) )
const url = getUrl(fontFamily, fontAxes, display) const url = getUrl(fontFamily, fontAxes, display)
let cachedCssRequest = cssCache.get(url) // Find fallback font metrics
const fontFaceDeclarations = let adjustFontFallbackMetrics: AdjustFontFallback | undefined
cachedCssRequest ?? (await fetchCSSFromGoogleFonts(url, fontFamily)) if (adjustFontFallback) {
if (!cachedCssRequest) { try {
const { ascent, descent, lineGap, fallbackFont, sizeAdjust } =
calculateSizeAdjustValues(
require('next/dist/server/google-font-metrics.json')[fontFamily]
)
adjustFontFallbackMetrics = {
fallbackFont,
ascentOverride: `${ascent}%`,
descentOverride: `${descent}%`,
lineGapOverride: `${lineGap}%`,
sizeAdjust: `${sizeAdjust}%`,
}
} catch {
Log.error(
`Failed to find font override values for font \`${fontFamily}\``
)
}
}
try {
const hasCachedCSS = cssCache.has(url)
const fontFaceDeclarations = hasCachedCSS
? cssCache.get(url)
: await fetchCSSFromGoogleFonts(url, fontFamily).catch(() => null)
if (!hasCachedCSS) {
cssCache.set(url, fontFaceDeclarations) cssCache.set(url, fontFaceDeclarations)
} else { } else {
cssCache.delete(url) cssCache.delete(url)
} }
if (fontFaceDeclarations === null) {
throw new Error(`Failed to fetch \`${fontFamily}\` from Google Fonts.`)
}
// Find font files to download // Find font files to download
const fontFiles: Array<{ const fontFiles: Array<{
...@@ -109,14 +138,20 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -109,14 +138,20 @@ const downloadGoogleFonts: FontLoader = async ({
// Download font files // Download font files
const downloadedFiles = await Promise.all( const downloadedFiles = await Promise.all(
fontFiles.map(async ({ googleFontFileUrl, preloadFontFile }) => { fontFiles.map(async ({ googleFontFileUrl, preloadFontFile }) => {
let cachedFontRequest = fontCache.get(googleFontFileUrl) const hasCachedFont = fontCache.has(googleFontFileUrl)
const fontFileBuffer = const fontFileBuffer = hasCachedFont
cachedFontRequest ?? (await fetchFontFile(googleFontFileUrl)) ? fontCache.get(googleFontFileUrl)
if (!cachedFontRequest) { : await fetchFontFile(googleFontFileUrl).catch(() => null)
if (!hasCachedFont) {
fontCache.set(googleFontFileUrl, fontFileBuffer) fontCache.set(googleFontFileUrl, fontFileBuffer)
} else { } else {
fontCache.delete(googleFontFileUrl) fontCache.delete(googleFontFileUrl)
} }
if (fontFileBuffer === null) {
throw new Error(
`Failed to fetch \`${fontFamily}\` from Google Fonts.`
)
}
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(googleFontFileUrl)![1] const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(googleFontFileUrl)![1]
// Emit font file to .next/static/fonts // Emit font file to .next/static/fonts
...@@ -142,30 +177,41 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -142,30 +177,41 @@ const downloadGoogleFonts: FontLoader = async ({
) )
} }
// Add fallback font return {
let adjustFontFallbackMetrics: AdjustFontFallback | undefined css: updatedCssResponse,
if (adjustFontFallback) { fallbackFonts: fallback,
try { weight:
const { ascent, descent, lineGap, fallbackFont, sizeAdjust } = weights.length === 1 && weights[0] !== 'variable'
calculateSizeAdjustValues( ? weights[0]
require('next/dist/server/google-font-metrics.json')[fontFamily] : undefined,
) style: styles.length === 1 ? styles[0] : undefined,
adjustFontFallbackMetrics = { variable,
fallbackFont, adjustFontFallback: adjustFontFallbackMetrics,
ascentOverride: `${ascent}%`,
descentOverride: `${descent}%`,
lineGapOverride: `${lineGap}%`,
sizeAdjust: `${sizeAdjust}%`,
} }
} catch { } catch (err) {
loaderContext.cacheable(false)
if (isDev) {
if (isServer) {
Log.error( Log.error(
`Failed to find font override values for font \`${fontFamily}\`` `Failed to download \`${fontFamily}\` from Google Fonts. Using fallback font instead.`
) )
} }
// In dev we should return the fallback font instead of throwing an error
let css = `@font-face {
font-family: '${fontFamily} Fallback';
src: local("${adjustFontFallbackMetrics?.fallbackFont ?? 'Arial'}");`
if (adjustFontFallbackMetrics) {
css += `
ascent-override:${adjustFontFallbackMetrics.ascentOverride};
descent-override:${adjustFontFallbackMetrics.descentOverride};
line-gap-override:${adjustFontFallbackMetrics.lineGapOverride};
size-adjust:${adjustFontFallbackMetrics.sizeAdjust};`
} }
css += '\n}'
return { return {
css: updatedCssResponse, css,
fallbackFonts: fallback, fallbackFonts: fallback,
weight: weight:
weights.length === 1 && weights[0] !== 'variable' weights.length === 1 && weights[0] !== 'variable'
...@@ -173,7 +219,10 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -173,7 +219,10 @@ const downloadGoogleFonts: FontLoader = async ({
: undefined, : undefined,
style: styles.length === 1 ? styles[0] : undefined, style: styles.length === 1 ? styles[0] : undefined,
variable, variable,
adjustFontFallback: adjustFontFallbackMetrics, }
} else {
throw err
}
} }
} }
......
...@@ -57,7 +57,7 @@ const fetchFonts: FontLoader = async ({ ...@@ -57,7 +57,7 @@ const fetchFonts: FontLoader = async ({
data, data,
emitFontFile, emitFontFile,
resolve, resolve,
fs, loaderContext,
}) => { }) => {
const { const {
src, src,
...@@ -74,7 +74,7 @@ const fetchFonts: FontLoader = async ({ ...@@ -74,7 +74,7 @@ const fetchFonts: FontLoader = async ({
const fontFiles = await Promise.all( const fontFiles = await Promise.all(
src.map(async ({ path, style, weight, ext, format }) => { src.map(async ({ path, style, weight, ext, format }) => {
const resolved = await resolve(path) const resolved = await resolve(path)
const fileBuffer = await promisify(fs.readFile)(resolved) const fileBuffer = await promisify(loaderContext.fs.readFile)(resolved)
const fontUrl = emitFontFile(fileBuffer, ext, preload) const fontUrl = emitFontFile(fileBuffer, ext, preload)
let fontMetadata: any let fontMetadata: any
......
...@@ -59,6 +59,7 @@ export function getFontLoader( ...@@ -59,6 +59,7 @@ export function getFontLoader(
loaders.push({ loaders.push({
loader: 'next-font-loader', loader: 'next-font-loader',
options: { options: {
isDev: ctx.isDevelopment,
isServer: ctx.isServer, isServer: ctx.isServer,
assetPrefix: ctx.assetPrefix, assetPrefix: ctx.assetPrefix,
fontLoaderOptions, fontLoaderOptions,
......
...@@ -13,6 +13,7 @@ export default async function nextFontLoader(this: any) { ...@@ -13,6 +13,7 @@ export default async function nextFontLoader(this: any) {
return fontLoaderSpan.traceAsyncFn(async () => { return fontLoaderSpan.traceAsyncFn(async () => {
const callback = this.async() const callback = this.async()
const { const {
isDev,
isServer, isServer,
assetPrefix, assetPrefix,
fontLoaderOptions, fontLoaderOptions,
...@@ -79,8 +80,9 @@ export default async function nextFontLoader(this: any) { ...@@ -79,8 +80,9 @@ export default async function nextFontLoader(this: any) {
), ),
src.startsWith('.') ? src : `./${src}` src.startsWith('.') ? src : `./${src}`
), ),
fs: this.fs, isDev,
isServer, isServer,
loaderContext: this,
}) })
const { postcss } = await getPostcss() const { postcss } = await getPostcss()
......
...@@ -51,7 +51,7 @@ const postcssFontLoaderPlugn = ({ ...@@ -51,7 +51,7 @@ const postcssFontLoaderPlugn = ({
} }
if (!fontFamily) { if (!fontFamily) {
throw new Error('Font loaders must have exactly one font family') throw new Error("Font loaders must return one or more @font-face's")
} }
// Add fallback font with override values // Add fallback font with override values
......
...@@ -19,8 +19,9 @@ export type FontLoader = (options: { ...@@ -19,8 +19,9 @@ export type FontLoader = (options: {
config: any config: any
emitFontFile: (content: Buffer, ext: string, preload: boolean) => string emitFontFile: (content: Buffer, ext: string, preload: boolean) => string
resolve: (src: string) => string resolve: (src: string) => string
fs: any isDev: boolean
isServer: boolean isServer: boolean
loaderContext: any
}) => Promise<{ }) => Promise<{
css: string css: string
fallbackFonts?: string[] fallbackFonts?: string[]
......
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { join } from 'path'
import webdriver from 'next-webdriver'
const mockedGoogleFontResponses = require.resolve(
'./google-font-mocked-responses.js'
)
describe('@next/font/google fetch error', () => {
const isDev = (global as any).isNextDev
let next: NextInstance
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
}
beforeAll(async () => {
next = await createNext({
files: {
pages: new FileRef(join(__dirname, 'google-fetch-error/pages')),
'next.config.js': new FileRef(
join(__dirname, 'google-fetch-error/next.config.js')
),
},
dependencies: {
'@next/font': 'canary',
},
env: {
NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses,
},
skipStart: true,
})
})
afterAll(() => next.destroy())
if (isDev) {
it('should use a fallback font in dev', async () => {
await next.start()
const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/')
const ascentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter_Fallback")).ascentOverride'
)
expect(ascentOverride).toBe('90%')
const descentOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter_Fallback")).descentOverride'
)
expect(descentOverride).toBe('22.43%')
const lineGapOverride = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter_Fallback")).lineGapOverride'
)
expect(lineGapOverride).toBe('0%')
const sizeAdjust = await browser.eval(
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter_Fallback")).sizeAdjust'
)
expect(sizeAdjust).toBe('107.64%')
expect(next.cliOutput.slice(outputIndex)).toInclude(
'Failed to download `Inter` from Google Fonts. Using fallback font instead.'
)
})
} else {
it('should error when not in dev', async () => {
await expect(next.start()).rejects.toThrow('next build failed')
expect(next.cliOutput).toInclude(
'Failed to fetch `Inter` from Google Fonts.'
)
})
}
})
module.exports = {
experimental: {
fontLoaders: [
{
loader: '@next/font/google',
},
],
},
}
import { Inter } from '@next/font/google'
const inter = Inter({ weight: '400', subsets: ['latin'] })
export default function Page() {
return (
<p id="inter-fallback" className={inter.className}>
{JSON.stringify(inter)}
</p>
)
}
...@@ -936,4 +936,6 @@ module.exports = { ...@@ -936,4 +936,6 @@ module.exports = {
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} }
`, `,
'https://fonts.googleapis.com/css2?family=Inter:wght@400&display=optional':
null,
} }
...@@ -108,7 +108,8 @@ describe('@next/font/google loader', () => { ...@@ -108,7 +108,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -119,28 +120,6 @@ describe('@next/font/google loader', () => { ...@@ -119,28 +120,6 @@ describe('@next/font/google loader', () => {
}) })
describe('Errors', () => { describe('Errors', () => {
test('Failed to fetch', async () => {
fetch.mockResolvedValue({
ok: false,
})
await expect(
loader({
functionName: 'Alkalami',
data: [{ weight: '400' }],
config: { subsets: [] },
emitFontFile: jest.fn(),
resolve: jest.fn(),
fs: {} as any,
isServer: true,
variableName: 'myFont',
})
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Failed to fetch font \`Alkalami\`.
URL: https://fonts.googleapis.com/css2?family=Alkalami:wght@400&display=optional"
`)
})
test('Missing function name', async () => { test('Missing function name', async () => {
await expect( await expect(
loader({ loader({
...@@ -149,7 +128,8 @@ describe('@next/font/google loader', () => { ...@@ -149,7 +128,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -166,7 +146,8 @@ describe('@next/font/google loader', () => { ...@@ -166,7 +146,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -183,7 +164,8 @@ describe('@next/font/google loader', () => { ...@@ -183,7 +164,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -201,7 +183,8 @@ describe('@next/font/google loader', () => { ...@@ -201,7 +183,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -219,7 +202,8 @@ describe('@next/font/google loader', () => { ...@@ -219,7 +202,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -237,7 +221,8 @@ describe('@next/font/google loader', () => { ...@@ -237,7 +221,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -255,7 +240,8 @@ describe('@next/font/google loader', () => { ...@@ -255,7 +240,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -272,7 +258,8 @@ describe('@next/font/google loader', () => { ...@@ -272,7 +258,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -289,7 +276,8 @@ describe('@next/font/google loader', () => { ...@@ -289,7 +276,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -307,7 +295,8 @@ describe('@next/font/google loader', () => { ...@@ -307,7 +295,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -325,7 +314,8 @@ describe('@next/font/google loader', () => { ...@@ -325,7 +314,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
...@@ -379,7 +369,8 @@ describe('@next/font/google loader', () => { ...@@ -379,7 +369,8 @@ describe('@next/font/google loader', () => {
config: { subsets: [] }, config: { subsets: [] },
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
fs: {} as any, loaderContext: {} as any,
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
}) })
......
...@@ -9,11 +9,14 @@ describe('@next/font/local', () => { ...@@ -9,11 +9,14 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
} as any,
}) })
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
...@@ -33,11 +36,14 @@ describe('@next/font/local', () => { ...@@ -33,11 +36,14 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
} as any,
}) })
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
...@@ -67,11 +73,14 @@ describe('@next/font/local', () => { ...@@ -67,11 +73,14 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: () => '/_next/static/media/my-font.woff2', emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { fs: {
readFile: (_, cb) => cb(null, 'fontdata'), readFile: (_, cb) => cb(null, 'fontdata'),
}, },
} as any,
}) })
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
...@@ -117,11 +126,14 @@ describe('@next/font/local', () => { ...@@ -117,11 +126,14 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`, emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { fs: {
readFile: (path, cb) => cb(null, path), readFile: (path, cb) => cb(null, path),
}, },
} as any,
}) })
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
...@@ -186,11 +198,14 @@ describe('@next/font/local', () => { ...@@ -186,11 +198,14 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`, emitFontFile: (buffer) => `/_next/static/media/my-font.woff2`,
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { fs: {
readFile: (path, cb) => cb(null, path), readFile: (path, cb) => cb(null, path),
}, },
} as any,
}) })
expect(css).toMatchInlineSnapshot(` expect(css).toMatchInlineSnapshot(`
...@@ -230,9 +245,10 @@ describe('@next/font/local', () => { ...@@ -230,9 +245,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"@next/font/local has no named exports"` `"@next/font/local has no named exports"`
...@@ -247,9 +263,10 @@ describe('@next/font/local', () => { ...@@ -247,9 +263,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Missing required \`src\` property"` `"Missing required \`src\` property"`
...@@ -264,9 +281,10 @@ describe('@next/font/local', () => { ...@@ -264,9 +281,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn().mockResolvedValue(''), resolve: jest.fn().mockResolvedValue(''),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unexpected file \`./font/font-file.abc\`"` `"Unexpected file \`./font/font-file.abc\`"`
...@@ -281,9 +299,10 @@ describe('@next/font/local', () => { ...@@ -281,9 +299,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid display value \`invalid\`. "Invalid display value \`invalid\`.
...@@ -305,9 +324,10 @@ describe('@next/font/local', () => { ...@@ -305,9 +324,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid declaration prop: \`src\`"` `"Invalid declaration prop: \`src\`"`
...@@ -322,9 +342,10 @@ describe('@next/font/local', () => { ...@@ -322,9 +342,10 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
fs: {}, loaderContext: {} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot( ).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unexpected empty \`src\` array."` `"Unexpected empty \`src\` array."`
...@@ -349,10 +370,13 @@ describe('@next/font/local', () => { ...@@ -349,10 +370,13 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { readFile: (path, cb) => cb(null, path) }, fs: { readFile: (path, cb) => cb(null, path) },
}) } as any,
} as any)
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid weight value in src array: \`abc\`. "Invalid weight value in src array: \`abc\`.
Expected \`normal\`, \`bold\` or a number." Expected \`normal\`, \`bold\` or a number."
...@@ -377,9 +401,12 @@ describe('@next/font/local', () => { ...@@ -377,9 +401,12 @@ describe('@next/font/local', () => {
config: {}, config: {},
emitFontFile: jest.fn(), emitFontFile: jest.fn(),
resolve: jest.fn(), resolve: jest.fn(),
isDev: false,
isServer: true, isServer: true,
variableName: 'myFont', variableName: 'myFont',
loaderContext: {
fs: { readFile: (path, cb) => cb(null, path) }, fs: { readFile: (path, cb) => cb(null, path) },
} as any,
}) })
).rejects.toThrowErrorMatchingInlineSnapshot(` ).rejects.toThrowErrorMatchingInlineSnapshot(`
"Invalid weight value in src array: \`100 abc\`. "Invalid weight value in src array: \`100 abc\`.
......
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