Skip to content

Commit

Permalink
test(turbo): allow to run test with --experimental-turbo (#53396)
Browse files Browse the repository at this point in the history
### What?

Allows to configure test runs with --experimental turbo.
  • Loading branch information
kwonoj committed Aug 9, 2023
1 parent 6b49297 commit e127c51
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_deploy.yml
Expand Up @@ -457,7 +457,7 @@ jobs:
continue-on-error: true
run: |
ls -al ./test
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0 @aws-sdk/property-provider@3
jrm ./nextjs-test-result-junit.xml "test/test-junit-report/**/*.xml"
DD_ENV=ci datadog-ci junit upload --tags test.type:nextjs_deploy_e2e --service nextjs ./nextjs-test-result-junit.xml
Expand Down Expand Up @@ -506,7 +506,7 @@ jobs:
- name: Upload to Datadog
run: |
ls -al turbopack-bin-size
npm install -g @datadog/datadog-ci
npm install -g @datadog/datadog-ci@2.14.0 @aws-sdk/property-provider@3
for filename in turbopack-bin-size/*; do
export BYTESIZE+=" --metrics $(cat $filename)"
done
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_reusable.yml
Expand Up @@ -200,7 +200,7 @@ jobs:
continue-on-error: true
run: |
ls -al ./test
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0 @aws-sdk/property-provider@3
jrm ./nextjs-test-result-junit.xml "test/test-junit-report/**/*.xml"
jrm ./turbopack-test-result-junit.xml "test/turbopack-test-junit-report/**/*.xml"
# Put a separate tag for the tests with turbopack to distinguish between same test names
Expand Down
13 changes: 10 additions & 3 deletions jest.config.js
Expand Up @@ -39,13 +39,20 @@ 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_TURBOPACK
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'

customJestConfig.reporters.push([
'jest-junit',
{
outputDirectory,
// note: {filename} is not a full path, since putting full path
// makes suite name too long and truncates and not able to read the suite name
suiteNameTemplate: `{title} [${process.env.NEXT_TEST_MODE ?? 'default'}${
process.env.TURBOPACK ? '/t' : ''
}${process.env.EXPERIMENTAL_TURBOPACK ? '/et' : ''}/{filename}]`,
reportTestSuiteErrors: 'true',
uniqueOutputName: 'true',
outputName: 'nextjs-test-junit',
Expand Down
9 changes: 7 additions & 2 deletions test/lib/e2e-utils.ts
Expand Up @@ -7,14 +7,18 @@ import { NextDevInstance } from './next-modes/next-dev'
import { NextStartInstance } from './next-modes/next-start'
import { NextDeployInstance } from './next-modes/next-deploy'
import { shouldRunTurboDevTest } from './next-test-utils'
import { shouldRunExperimentalTurboDevTest } from './turbo'

export type { NextInstance }

// increase timeout to account for yarn install time
// 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
let testTimeout =
shouldRunTurboDevTest() || shouldRunExperimentalTurboDevTest()
? (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,7 +151,8 @@ export async function createNext(
return await trace('createNext').traceAsyncFn(async (rootSpan) => {
const useTurbo = !!process.env.TEST_WASM
? false
: opts?.turbo ?? shouldRunTurboDevTest()
: opts?.turbo ??
(shouldRunTurboDevTest() || shouldRunExperimentalTurboDevTest())

if (testMode === 'dev') {
// next dev
Expand Down
7 changes: 5 additions & 2 deletions test/lib/next-modes/next-dev.ts
@@ -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 @@ -22,12 +23,14 @@ export class NextDevInstance extends NextInstance {
throw new Error('next already started')
}

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

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

Expand Down
10 changes: 7 additions & 3 deletions test/lib/next-test-utils.ts
Expand Up @@ -27,6 +27,7 @@ import type { NextServer } from 'next/dist/server/next'
import type { BrowserInterface } from './browsers/base'

import {
getTurbopackFlag,
shouldRunExperimentalTurboDevTest,
shouldRunTurboDevTest,
} from './turbo'
Expand Down Expand Up @@ -448,9 +449,12 @@ export function launchApp(
const useExperimentalTurbo = shouldRunExperimentalTurboDevTest()

return runNextCommandDev(
[useTurbo ? '--turbo' : undefined, dir, '-p', port as string].filter(
Boolean
),
[
useTurbo || useExperimentalTurbo ? getTurbopackFlag() : undefined,
dir,
'-p',
port as string,
].filter(Boolean),
undefined,
{
...options,
Expand Down
10 changes: 10 additions & 0 deletions test/lib/turbo.ts
Expand Up @@ -50,3 +50,13 @@ export function shouldRunExperimentalTurboDevTest(): boolean {

return shouldRunExperimentalTurboDev
}

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 e127c51

Please sign in to comment.