Skip to content

Commit

Permalink
test(turbopack): support new env to set --experimental-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 11, 2023
1 parent 56fcd7a commit 7394cd4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 23 deletions.
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ if (shouldEnableTestTrace) {
customJestConfig.reporters = ['default']
}

const outputDirectory = process.env.TURBOPACK
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'
const outputDirectory =
process.env.TURBOPACK || process.env.__EXPERIMENTAL_TURBO
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'
customJestConfig.reporters.push([
'jest-junit',
{
Expand Down
13 changes: 8 additions & 5 deletions packages/next/src/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ const nextDev: CliCommand = async (argv) => {
// We do not set a default host value here to prevent breaking
// some set-ups that rely on listening on other interfaces
const host = args['--hostname']
const experimentalTurbo = args['--experimental-turbo']

if (args['--turbo']) {
process.env.TURBOPACK = '1'
} else if (args['--experimental-turbo']) {
process.env.__EXPERIMENTAL_TURBO = '1'
}

const experimentalTurbo = !!process.env.__EXPERIMENTAL_TURBO

const devServerOptions: StartServerOptions = {
dir,
Expand All @@ -224,10 +231,6 @@ const nextDev: CliCommand = async (argv) => {
isExperimentalTurbo: experimentalTurbo,
}

if (args['--turbo']) {
process.env.TURBOPACK = '1'
}

if (process.env.TURBOPACK) {
isTurboSession = true

Expand Down
4 changes: 3 additions & 1 deletion test/development/basic/emotion-swc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe('emotion SWC option', () => {
let next: NextInstance

beforeAll(async () => {
const useTurbo = !!process.env.TEST_WASM ? false : shouldRunTurboDevTest()
const useTurbo = !!process.env.TEST_WASM
? false
: shouldRunTurboDevTest().turbo
next = await createNext({
files: {
'jsconfig.json': new FileRef(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/next-font/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mockedGoogleFontResponses = require.resolve(

function getClassNameRegex(className: string): RegExp {
// Turbopack uses a different format for its css modules than webpack-based Next.js
return shouldRunTurboDevTest()
return shouldRunTurboDevTest().turbo
? new RegExp(`^${className}__.*__.{8}$`) // e.g. `className__inter_c6e282f1__a8cc5613`
: new RegExp(`^__${className}_.{6}$`) // e.g. `__className_a8cc56`
}
Expand Down
16 changes: 13 additions & 3 deletions test/lib/e2e-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export type { NextInstance }
// if either test runs for the --turbo or have a custom timeout, set reduced timeout instead.
// this is due to current --turbo test have a lot of tests fails with timeouts, ends up the whole
// test job exceeds the 6 hours limit.
let testTimeout = shouldRunTurboDevTest() ? (240 * 1000) / 4 : 240 * 1000
const { turbo, experimental } = shouldRunTurboDevTest()
let testTimeout = turbo || experimental ? (240 * 1000) / 4 : 240 * 1000
if (process.env.NEXT_E2E_TEST_TIMEOUT) {
try {
testTimeout = parseInt(process.env.NEXT_E2E_TEST_TIMEOUT, 10)
Expand Down Expand Up @@ -147,14 +148,23 @@ export async function createNext(
return await trace('createNext').traceAsyncFn(async (rootSpan) => {
const useTurbo = !!process.env.TEST_WASM
? false
: opts?.turbo ?? shouldRunTurboDevTest()
: opts?.turbo ?? shouldRunTurboDevTest().turbo

const useTurboExperimental = !!process.env.TEST_WASM
? false
: shouldRunTurboDevTest().experimental

if (useTurbo && useTurboExperimental) {
throw new Error('Cannot enable both turbo and turboExperimental')
}

if (testMode === 'dev') {
// next dev
rootSpan.traceChild('init next dev instance').traceFn(() => {
nextInstance = new NextDevInstance({
...opts,
turbo: useTurbo,
turboExperimental: experimental,
})
})
} else if (testMode === 'deploy') {
Expand Down Expand Up @@ -252,7 +262,7 @@ export function nextTestSetup(
return Boolean(
(global as any).isNextDev &&
!process.env.TEST_WASM &&
(options.turbo ?? shouldRunTurboDevTest())
(options.turbo ?? shouldRunTurboDevTest().turbo)
)
},

Expand Down
1 change: 1 addition & 0 deletions test/lib/next-modes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface NextInstanceOpts {
env?: Record<string, string>
dirSuffix?: string
turbo?: boolean
turboExperimental?: boolean
forcedPort?: string
}

Expand Down
8 changes: 7 additions & 1 deletion test/lib/next-modes/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ export class NextDevInstance extends NextInstance {

const useTurbo = !process.env.TEST_WASM && (this as any).turbo

const turboArgs = useTurbo
? '--turbo'
: (this as any).turboExperimental
? '--experimental-turbo'
: undefined

let startArgs = [
'yarn',
'next',
useTurbo ? '--turbo' : undefined,
turboArgs,
useDirArg && this.testDir,
].filter(Boolean) as string[]

Expand Down
16 changes: 10 additions & 6 deletions test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,15 @@ export function launchApp(
opts?: NextDevOptions
) {
const options = opts ?? {}
const useTurbo = shouldRunTurboDevTest()
const { turbo: useTurbo, experimental } = shouldRunTurboDevTest()
const turboArgs = useTurbo
? '--turbo'
: experimental
? '--experimental-turbo'
: undefined

return runNextCommandDev(
[useTurbo ? '--turbo' : undefined, dir, '-p', port as string].filter(
Boolean
),
[turboArgs, dir, '-p', port as string].filter(Boolean),
undefined,
{
...options,
Expand Down Expand Up @@ -763,7 +766,7 @@ export async function hasRedbox(browser: BrowserInterface, expected = true) {
export async function getRedboxHeader(browser: BrowserInterface) {
return retry(
() => {
if (shouldRunTurboDevTest()) {
if (shouldRunTurboDevTest().turbo) {
return evaluate(browser, () => {
const portal = [].slice
.call(document.querySelectorAll('nextjs-portal'))
Expand Down Expand Up @@ -1021,7 +1024,8 @@ export function getSnapshotTestDescribe(variant: TestVariants) {
)
}

const shouldRunTurboDev = shouldRunTurboDevTest()
const { turbo, experimental } = shouldRunTurboDevTest()
const shouldRunTurboDev = turbo || experimental
const shouldSkip =
(runningEnv === 'turbo' && !shouldRunTurboDev) ||
(runningEnv === 'default' && shouldRunTurboDev)
Expand Down
23 changes: 20 additions & 3 deletions test/lib/turbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ let loggedTurbopack = false
* it makes hard to conform with existing lint rules. Instead, starting off from manual fixture setup and
* update test cases accordingly as turbopack changes enable more test cases.
*/
export function shouldRunTurboDevTest(): boolean {
export function shouldRunTurboDevTest(): {
turbo: boolean
experimental: boolean
} {
if (!!process.env.TEST_WASM) {
return false
return {
turbo: false,
experimental: false,
}
}

const shouldRunTurboDev = !!process.env.TURBOPACK
Expand All @@ -21,6 +27,17 @@ export function shouldRunTurboDevTest(): boolean {
)
loggedTurbopack = true
}
const shouldRunExperimental = !!process.env.__EXPERIMENTAL_TURBO

return shouldRunTurboDev
if (shouldRunExperimental && !loggedTurbopack) {
require('console').log(
`Running tests with experimental turbopack because environment variable is set`
)
loggedTurbopack = true
}

return {
turbo: shouldRunTurboDev,
experimental: shouldRunExperimental,
}
}

0 comments on commit 7394cd4

Please sign in to comment.