Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@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)
- Loading branch information
Hannes Bornö
committed
Nov 8, 2022
1 parent
85b200a
commit 0696920
Showing
12 changed files
with
316 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
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.' | ||
) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
experimental: { | ||
fontLoaders: [ | ||
{ | ||
loader: '@next/font/google', | ||
}, | ||
], | ||
}, | ||
} |
Oops, something went wrong.