Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next/font tests: support Turbopack css module format #46658

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions test/e2e/next-font/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
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 { renderViaHTTP, shouldRunTurboDevTest } from 'next-test-utils'
import { join } from 'path'
import webdriver from 'next-webdriver'

const mockedGoogleFontResponses = require.resolve(
'./google-font-mocked-responses.js'
)

function getClassNameRegex(className: string): RegExp {
// Turbopack uses a different format for its css modules than webpack-based Next.js
return shouldRunTurboDevTest()
? new RegExp(`^${className}__.*__.{8}$`) // e.g. `className__inter_c6e282f1__a8cc5613`
: new RegExp(`^__${className}_.{6}$`) // e.g. `__className_a8cc56`
}

describe('next/font', () => {
describe.each([['app'], ['app-old']])('%s', (fixture: string) => {
let next: NextInstance
Expand Down Expand Up @@ -45,8 +52,8 @@ describe('next/font', () => {

// _app.js
expect(JSON.parse($('#app-open-sans').text())).toEqual({
className: expect.stringMatching(/^__className_.{6}$/),
variable: expect.stringMatching(/^__variable_.{6}$/),
className: expect.stringMatching(getClassNameRegex('className')),
variable: expect.stringMatching(getClassNameRegex('variable')),
style: {
fontFamily: expect.stringMatching(
/^'__Open_Sans_.{6}', '__Open_Sans_Fallback_.{6}'$/
Expand All @@ -57,8 +64,8 @@ describe('next/font', () => {

// with-fonts.js
expect(JSON.parse($('#with-fonts-open-sans').text())).toEqual({
className: expect.stringMatching(/^__className_.{6}$/),
variable: expect.stringMatching(/^__variable_.{6}$/),
className: expect.stringMatching(getClassNameRegex('className')),
variable: expect.stringMatching(getClassNameRegex('variable')),
style: {
fontFamily: expect.stringMatching(
/^'__Open_Sans_.{6}', '__Open_Sans_Fallback_.{6}'$/
Expand All @@ -69,7 +76,7 @@ describe('next/font', () => {

// CompWithFonts.js
expect(JSON.parse($('#comp-with-fonts-inter').text())).toEqual({
className: expect.stringMatching(/^__className_.{6}$/),
className: expect.stringMatching(getClassNameRegex('className')),
style: {
fontFamily: expect.stringMatching(
/^'__Inter_.{6}', '__Inter_Fallback_.{6}'$/
Expand All @@ -79,7 +86,7 @@ describe('next/font', () => {
},
})
expect(JSON.parse($('#comp-with-fonts-roboto').text())).toEqual({
className: expect.stringMatching(/^__className_.{6}$/),
className: expect.stringMatching(getClassNameRegex('className')),
style: {
fontFamily: expect.stringMatching(
/^'__Roboto_.{6}', '__Roboto_Fallback_.{6}'$/
Expand All @@ -96,8 +103,8 @@ describe('next/font', () => {

// _app.js
expect(JSON.parse($('#app-open-sans').text())).toEqual({
className: expect.stringMatching(/__className_.{6}/),
variable: expect.stringMatching(/__variable_.{6}/),
className: expect.stringMatching(getClassNameRegex('className')),
variable: expect.stringMatching(getClassNameRegex('variable')),
style: {
fontFamily: expect.stringMatching(
/^'__Open_Sans_.{6}', '__Open_Sans_Fallback_.{6}'$/
Expand All @@ -108,7 +115,7 @@ describe('next/font', () => {

// with-local-fonts.js
expect(JSON.parse($('#first-local-font').text())).toEqual({
className: expect.stringMatching(/__className_.{6}/),
className: expect.stringMatching(getClassNameRegex('className')),
style: {
fontFamily: expect.stringMatching(
/^'__myFont1_.{6}', '__myFont1_Fallback_.{6}', system-ui$/
Expand All @@ -118,8 +125,8 @@ describe('next/font', () => {
},
})
expect(JSON.parse($('#second-local-font').text())).toEqual({
className: expect.stringMatching(/^__className_.{6}$/),
variable: expect.stringMatching(/^__variable_.{6}$/),
className: expect.stringMatching(getClassNameRegex('className')),
variable: expect.stringMatching(getClassNameRegex('variable')),
style: {
fontFamily: expect.stringMatching(
/^'__myFont2_.{6}', '__myFont2_Fallback_.{6}'$/
Expand All @@ -136,7 +143,7 @@ describe('next/font', () => {
const $ = cheerio.load(html)

expect(JSON.parse($('#nabla').text())).toEqual({
className: expect.stringMatching(/__className_.{6}/),
className: expect.stringMatching(getClassNameRegex('className')),
style: {
fontFamily: expect.stringMatching(/^'__Nabla_.{6}'$/),
fontStyle: 'normal',
Expand Down