2022-09-22 07:12:59 +02:00
|
|
|
import cheerio from 'cheerio'
|
|
|
|
import { createNext, FileRef } from 'e2e-utils'
|
|
|
|
import { NextInstance } from 'test/lib/next-modes/base'
|
|
|
|
import { renderViaHTTP } from 'next-test-utils'
|
|
|
|
import { join } from 'path'
|
|
|
|
|
|
|
|
const mockedGoogleFontResponses = require.resolve(
|
|
|
|
'./google-font-mocked-responses.js'
|
|
|
|
)
|
|
|
|
|
|
|
|
describe('@next/font/google basepath', () => {
|
|
|
|
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, 'basepath/pages')),
|
|
|
|
'next.config.js': new FileRef(
|
|
|
|
join(__dirname, 'basepath/next.config.js')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
dependencies: {
|
|
|
|
'@next/font': 'canary',
|
|
|
|
},
|
|
|
|
env: {
|
|
|
|
NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
afterAll(() => next.destroy())
|
|
|
|
|
|
|
|
test('preload correct files', async () => {
|
|
|
|
const html = await renderViaHTTP(next.url, '/dashboard')
|
|
|
|
const $ = cheerio.load(html)
|
|
|
|
|
|
|
|
// Preconnect
|
|
|
|
expect($('link[rel="preconnect"]').length).toBe(0)
|
|
|
|
|
|
|
|
// Preload
|
|
|
|
expect($('link[as="font"]').length).toBe(1)
|
|
|
|
expect($('link[as="font"]').get(0).attribs).toEqual({
|
|
|
|
as: 'font',
|
|
|
|
crossorigin: 'anonymous',
|
2023-01-31 23:16:13 +01:00
|
|
|
href: '/dashboard/_next/static/media/0812efcfaefec5ea-s.p.woff2',
|
2022-09-22 07:12:59 +02:00
|
|
|
rel: 'preload',
|
|
|
|
type: 'font/woff2',
|
2023-01-31 23:16:13 +01:00
|
|
|
'data-next-font': 'size-adjust',
|
2022-09-22 07:12:59 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|