Skip to content

Commit

Permalink
[test] Remove describeVariants helper
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 27, 2025
1 parent b80301d commit cf25070
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 68 deletions.
4 changes: 2 additions & 2 deletions test/development/app-dir/basic/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { nextTestSetup } from 'e2e-utils'
import { describeVariants as describe, waitFor } from 'next-test-utils'
import { waitFor } from 'next-test-utils'
import { createSandbox, waitForHydration } from 'development-sandbox'

describe.each(['default', 'turbo'])('basic app-dir tests', () => {
describe('basic app-dir tests', () => {
const { next } = nextTestSetup({
files: __dirname,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
import { nextTestSetup } from 'e2e-utils'
import { describeVariants } from 'next-test-utils'

describeVariants.each(['turbo'])('experimental-lightningcss', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should support css modules', async () => {
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
// swc_css does not include `-module` in the class name, while lightningcss does.
expect($('p').attr('class')).toBe(
'search-keyword style-module__hlQ3RG__blue'
)
})
})
describe('experimental-lightningcss with default mode', () => {
describe('in dev server', () => {
const { isTurbopack, next } = nextTestSetup({
files: __dirname,
dependencies: { lightningcss: '^1.23.0' },
packageJson: {
browserslist: ['chrome 100'],
},
})

// lightningcss produces different class names in turbo mode
describeVariants.each(['default'])(
'experimental-lightningcss with default mode',
() => {
describe('in dev server', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: { lightningcss: '^1.23.0' },
packageJson: {
browserslist: ['chrome 100'],
},
})
it('should support css modules', async () => {
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')

it('should support css modules', async () => {
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
// lightningcss produces different class names in turbo mode
if (isTurbopack) {
// swc_css does not include `-module` in the class name, while lightningcss does.
expect($('p').attr('class')).toBe(
'search-keyword style-module__hlQ3RG__blue'
)
} else {
// We remove hash from the class name in test mode using env var because it is not deterministic.
expect($('p').attr('class')).toBe('search-keyword style-module__blue')
})
}
})

it('should support browserslist', async () => {
const $ = await next.browser('/')
it('should support browserslist', async () => {
const $ = await next.browser('/')

expect(await $.elementByCss('.nested').text()).toBe(
'Red due to nesting'
)
expect(await $.elementByCss('.nested').getComputedCss('color')).toBe(
'rgb(255, 0, 0)'
)
})
expect(await $.elementByCss('.nested').text()).toBe('Red due to nesting')
expect(await $.elementByCss('.nested').getComputedCss('color')).toBe(
'rgb(255, 0, 0)'
)
})
}
)
})
})
22 changes: 0 additions & 22 deletions test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,28 +1520,6 @@ export function getUrlFromBackgroundImage(backgroundImage: string) {
return matches
}

/**
* For better editor support, pass in the variants this should run on (`default` and/or `turbo`) as cases.
*
* This is necessary if separate snapshots are needed for next.js with webpack vs turbopack.
*/
export const describeVariants = {
each(variants: TestVariants[]) {
return (name: string, fn: (variants: TestVariants) => any) => {
if (
!Array.isArray(variants) ||
!variants.every((val) => typeof val === 'string')
) {
throw new Error('variants need to be an array of strings')
}

for (const variant of variants) {
getSnapshotTestDescribe(variant).each([variant])(name, fn)
}
}
},
}

export const getTitle = (browser: BrowserInterface) =>
browser.elementByCss('title').text()

Expand Down

0 comments on commit cf25070

Please sign in to comment.