2022-09-22 07:12:59 +02:00
|
|
|
import cheerio from 'cheerio'
|
|
|
|
import { createNext, FileRef } from 'e2e-utils'
|
2024-04-09 00:25:43 +02:00
|
|
|
import { NextInstance } from 'e2e-utils'
|
2022-09-22 07:12:59 +02:00
|
|
|
import { renderViaHTTP } from 'next-test-utils'
|
|
|
|
import { join } from 'path'
|
|
|
|
|
|
|
|
const mockedGoogleFontResponses = require.resolve(
|
|
|
|
'./google-font-mocked-responses.js'
|
|
|
|
)
|
|
|
|
|
2023-02-16 15:33:39 +01:00
|
|
|
describe('next/font/google basepath', () => {
|
2022-09-22 07:12:59 +02:00
|
|
|
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')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
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)
|
2024-03-06 11:21:39 +01:00
|
|
|
expect($('link[as="font"]').get(0).attribs).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
as: 'font',
|
|
|
|
crossorigin: 'anonymous',
|
|
|
|
href: expect.stringMatching(
|
|
|
|
/\/dashboard\/_next\/static\/media\/.*.p.*.woff2/
|
|
|
|
),
|
|
|
|
rel: 'preload',
|
|
|
|
type: 'font/woff2',
|
|
|
|
'data-next-font': 'size-adjust',
|
|
|
|
})
|
|
|
|
)
|
2022-09-22 07:12:59 +02:00
|
|
|
})
|
|
|
|
})
|