Skip to content

Commit

Permalink
test(turbo): allow to run test with --experimental-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 31, 2023
1 parent de873d0 commit 9693beb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion 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
const outputDirectory = (process.env.TURBOPACK || process.env.EXPERIMENTAL_TURBOPACK)
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'

customJestConfig.reporters.push([
'jest-junit',
{
Expand Down
3 changes: 2 additions & 1 deletion test/lib/next-modes/next-dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import spawn from 'cross-spawn'
import { Span } from 'next/src/trace'
import { NextInstance } from './base'
import { getTurbopackFlag } from '../turbo'

export class NextDevInstance extends NextInstance {
private _cliOutput: string = ''
Expand All @@ -27,7 +28,7 @@ export class NextDevInstance extends NextInstance {
let startArgs = [
'yarn',
'next',
useTurbo ? '--turbo' : undefined,
useTurbo ? getTurbopackFlag() : undefined,
useDirArg && this.testDir,
].filter(Boolean) as string[]

Expand Down
11 changes: 7 additions & 4 deletions test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { RequestInit, Response } from 'node-fetch'
import type { NextServer } from 'next/dist/server/next'
import type { BrowserInterface } from './browsers/base'

import { shouldRunTurboDevTest } from './turbo'
import { getTurbopackFlag, shouldRunTurboDevTest } from './turbo'

export { shouldRunTurboDevTest }

Expand Down Expand Up @@ -436,9 +436,12 @@ export function launchApp(
const useTurbo = shouldRunTurboDevTest()

return runNextCommandDev(
[useTurbo ? '--turbo' : undefined, dir, '-p', port as string].filter(
Boolean
),
[
useTurbo ? getTurbopackFlag() : undefined,
dir,
'-p',
port as string,
].filter(Boolean),
undefined,
{
...options,
Expand Down
17 changes: 15 additions & 2 deletions test/lib/turbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ export function shouldRunTurboDevTest(): boolean {
return false
}

const shouldRunTurboDev = !!process.env.TURBOPACK
const shouldRunTurboDev =
!!process.env.TURBOPACK || !!process.env.EXPERIMENTAL_TURBOPACK
if (shouldRunTurboDev && !loggedTurbopack) {
require('console').log(
`Running tests with turbopack because environment variable TURBOPACK is set`
`Running tests with turbopack because environment variable ${
process.env.TURBOPACK ? 'TURBOPACK' : 'EXPERIMENTAL_TURBOPACK'
} is set`
)
loggedTurbopack = true
}

return shouldRunTurboDev
}

export function getTurbopackFlag(): string {
if (!!process.env.TURBOPACK) {
return '--turbo'
} else if (!!process.env.EXPERIMENTAL_TURBOPACK) {
return '--experimental-turbo'
} else {
throw Error(`Cannot get the flag for running turbopack`)
}
}

0 comments on commit 9693beb

Please sign in to comment.