Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Bornö committed Sep 21, 2022
1 parent 1ef575c commit 3ff7e16
Showing 1 changed file with 48 additions and 36 deletions.
84 changes: 48 additions & 36 deletions test/e2e/next-font/with-font-declarations-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const mockedGoogleFontResponses = require.resolve(
'./google-font-mocked-responses.js'
)

const isDev = (global as any).isNextDev

describe('@next/font/google with-font-declarations-file', () => {
let next: NextInstance

Expand Down Expand Up @@ -44,24 +46,29 @@ describe('@next/font/google with-font-declarations-file', () => {
// Preconnect
expect($('link[rel="preconnect"]').length).toBe(0)

// Preload
expect($('link[as="font"]').length).toBe(2)
// From /_app
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
// From /inter
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/4a7f86e553ee7e51.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
if (isDev) {
// In dev all fonts will be preloaded since it's before DCE
expect($('link[as="font"]').length).toBe(3)
} else {
// Preload
expect($('link[as="font"]').length).toBe(2)
// From /_app
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
// From /inter
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/4a7f86e553ee7e51.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
}
})

test('preload correct files at /roboto', async () => {
Expand All @@ -71,23 +78,28 @@ describe('@next/font/google with-font-declarations-file', () => {
// Preconnect
expect($('link[rel="preconnect"]').length).toBe(0)

// Preload
expect($('link[as="font"]').length).toBe(2)
// From /_app
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
// From /roboto
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/9a7e84b4dd095b33.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
if (isDev) {
// In dev all fonts will be preloaded since it's before DCE
expect($('link[as="font"]').length).toBe(3)
} else {
// Preload
expect($('link[as="font"]').length).toBe(2)
// From /_app
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
// From /roboto
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/9a7e84b4dd095b33.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
}
})
})

0 comments on commit 3ff7e16

Please sign in to comment.