Unverified Commit 36a7aff6 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

use env var to switch next.js to turbopack mode (#51353)

### What?

this forces all tests to use turbopack independent of the way they invoke next dev

### Why?

some tests were not running turbopack

fixes WEB-1187
parent bc9ed9de
...@@ -118,7 +118,7 @@ jobs: ...@@ -118,7 +118,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
skipForDocsOnly: 'yes' skipForDocsOnly: 'yes'
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" __INTERNAL_NEXT_DEV_TEST_TURBO_DEV=TRUE __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" __INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH="*" NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --type development --timings -c ${TEST_CONCURRENCY} afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" TURBOPACK=1 __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --type development --timings -c ${TEST_CONCURRENCY}
secrets: inherit secrets: inherit
test-next-swc-wasm: test-next-swc-wasm:
......
...@@ -39,7 +39,7 @@ if (shouldEnableTestTrace) { ...@@ -39,7 +39,7 @@ if (shouldEnableTestTrace) {
customJestConfig.reporters = ['default'] customJestConfig.reporters = ['default']
} }
const outputDirectory = process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_DEV const outputDirectory = process.env.TURBOPACK
? '<rootDir>/turbopack-test-junit-report' ? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report' : '<rootDir>/test-junit-report'
customJestConfig.reporters.push([ customJestConfig.reporters.push([
......
...@@ -14,7 +14,6 @@ const enabledTests = [ ...@@ -14,7 +14,6 @@ const enabledTests = [
'test/development/basic/define-class-fields.test.ts', 'test/development/basic/define-class-fields.test.ts',
'test/development/basic/emotion-swc.test.ts', 'test/development/basic/emotion-swc.test.ts',
'test/development/basic/legacy-decorators.test.ts', 'test/development/basic/legacy-decorators.test.ts',
'test/development/basic/styled-components-disabled.test.ts',
'test/development/basic/tailwind-jit.test.ts', 'test/development/basic/tailwind-jit.test.ts',
'test/development/basic/theme-ui.test.ts', 'test/development/basic/theme-ui.test.ts',
'test/development/dotenv-default-expansion/index.test.ts', 'test/development/dotenv-default-expansion/index.test.ts',
...@@ -23,7 +22,6 @@ const enabledTests = [ ...@@ -23,7 +22,6 @@ const enabledTests = [
'test/development/project-directory-with-styled-jsx-suffix/index.test.ts', 'test/development/project-directory-with-styled-jsx-suffix/index.test.ts',
'test/development/repeated-dev-edits/repeated-dev-edits.test.ts', 'test/development/repeated-dev-edits/repeated-dev-edits.test.ts',
'test/development/tsconfig-path-reloading/index.test.ts', 'test/development/tsconfig-path-reloading/index.test.ts',
'test/development/typescript-auto-install/index.test.ts',
'test/e2e/app-dir/_allow-underscored-root-directory/_allow-underscored-root-directory.test.ts', 'test/e2e/app-dir/_allow-underscored-root-directory/_allow-underscored-root-directory.test.ts',
'test/e2e/app-dir/actions/app-action-export.test.ts', 'test/e2e/app-dir/actions/app-action-export.test.ts',
'test/e2e/app-dir/app-alias/app-alias.test.ts', 'test/e2e/app-dir/app-alias/app-alias.test.ts',
...@@ -256,6 +254,8 @@ const enabledTests = [ ...@@ -256,6 +254,8 @@ const enabledTests = [
'test/integration/static-page-name/test/index.test.js', 'test/integration/static-page-name/test/index.test.js',
'test/integration/styled-jsx-plugin/test/index.test.js', 'test/integration/styled-jsx-plugin/test/index.test.js',
'test/integration/tsconfig-verifier/test/index.test.js', 'test/integration/tsconfig-verifier/test/index.test.js',
'test/integration/telemetry/test/page-features.test.js',
'test/integration/turbopack-unsupported-log/index.test.ts',
'test/integration/turbotrace-with-webpack-worker/test/index.test.js', 'test/integration/turbotrace-with-webpack-worker/test/index.test.js',
'test/integration/typeof-window-replace/test/index.test.js', 'test/integration/typeof-window-replace/test/index.test.js',
'test/integration/typescript-baseurl/test/index.test.js', 'test/integration/typescript-baseurl/test/index.test.js',
......
...@@ -74,6 +74,10 @@ const nextBuild: CliCommand = (argv) => { ...@@ -74,6 +74,10 @@ const nextBuild: CliCommand = (argv) => {
printAndExit(`> No such directory exists as the project root: ${dir}`) printAndExit(`> No such directory exists as the project root: ${dir}`)
} }
if (args['--experimental-turbo']) {
process.env.TURBOPACK = '1'
}
return build( return build(
dir, dir,
args['--profile'], args['--profile'],
...@@ -81,7 +85,7 @@ const nextBuild: CliCommand = (argv) => { ...@@ -81,7 +85,7 @@ const nextBuild: CliCommand = (argv) => {
!args['--no-lint'], !args['--no-lint'],
args['--no-mangling'], args['--no-mangling'],
args['--experimental-app-only'], args['--experimental-app-only'],
args['--experimental-turbo'], !!process.env.TURBOPACK,
args['--build-mode'] || 'default' args['--build-mode'] || 'default'
).catch((err) => { ).catch((err) => {
console.error('') console.error('')
......
...@@ -221,6 +221,10 @@ const nextDev: CliCommand = async (argv) => { ...@@ -221,6 +221,10 @@ const nextDev: CliCommand = async (argv) => {
} }
if (args['--turbo']) { if (args['--turbo']) {
process.env.TURBOPACK = '1'
}
if (process.env.TURBOPACK) {
isTurboSession = true isTurboSession = true
const { validateTurboNextConfig } = const { validateTurboNextConfig } =
......
...@@ -2732,38 +2732,6 @@ describe('Custom routes', () => { ...@@ -2732,38 +2732,6 @@ describe('Custom routes', () => {
runTests(true) runTests(true)
}) })
// enable once https://github.com/vercel/turbo/pull/3894 is landed
describe.skip('dev mode (turbo)', () => {
let nextConfigContent
beforeAll(async () => {
// ensure cache with rewrites disabled doesn't persist
// after enabling rewrites
await fs.remove(join(appDir, '.next'))
nextConfigContent = await fs.readFile(nextConfigPath, 'utf8')
await fs.writeFile(
nextConfigPath,
nextConfigContent.replace('// no-rewrites comment', 'return []')
)
const tempPort = await findPort()
const tempApp = await launchApp(appDir, tempPort, { turbo: true })
await renderViaHTTP(tempPort, '/')
await killApp(tempApp)
await fs.writeFile(nextConfigPath, nextConfigContent)
appPort = await findPort()
app = await launchApp(appDir, appPort, { turbo: true })
buildId = 'development'
})
afterAll(async () => {
await fs.writeFile(nextConfigPath, nextConfigContent)
await killApp(app)
})
runTests(true, true)
})
describe('no-op rewrite', () => { describe('no-op rewrite', () => {
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() appPort = await findPort()
......
...@@ -3,93 +3,94 @@ import fs from 'fs-extra' ...@@ -3,93 +3,94 @@ import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
describe('turbopack unsupported features log', () => { describe('turbopack unsupported features log', () => {
const appDir = join(__dirname, 'app') if (process.env.TURBOPACK) {
const appDir = join(__dirname, 'app')
it('should not warn by default', async () => { it('should not warn by default', async () => {
let output = '' let output = ''
const appPort = await findPort() const appPort = await findPort()
const app = await launchApp(appDir, appPort, { const app = await launchApp(appDir, appPort, {
turbo: true, onStdout(msg) {
onStdout(msg) { output += msg
output += msg },
}, onStderr(msg) {
onStderr(msg) { output += msg
output += msg },
}, })
})
try { try {
expect(output).toContain( expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!' 'Thank you for trying Next.js v13 with Turbopack!'
) )
expect(output).not.toContain( expect(output).not.toContain(
'You are using configuration and/or tools that are not yet' 'You are using configuration and/or tools that are not yet'
) )
expect(await renderViaHTTP(appPort, '/')).toContain('hello world') expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally { } finally {
await killApp(app).catch(() => {}) await killApp(app).catch(() => {})
} }
})
const nextConfigPath = join(appDir, 'next.config.js')
it('should not warn with empty next.config.js', async () => {
let output = ''
await fs.writeFile(nextConfigPath, `module.exports = {}`)
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
turbo: true,
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
}) })
const nextConfigPath = join(appDir, 'next.config.js')
try { it('should not warn with empty next.config.js', async () => {
expect(output).toContain( let output = ''
'Thank you for trying Next.js v13 with Turbopack!' await fs.writeFile(nextConfigPath, `module.exports = {}`)
) const appPort = await findPort()
expect(output).not.toContain( const app = await launchApp(appDir, appPort, {
'You are using configuration and/or tools that are not yet' onStdout(msg) {
) output += msg
},
onStderr(msg) {
output += msg
},
})
expect(await renderViaHTTP(appPort, '/')).toContain('hello world') try {
} finally { expect(output).toContain(
await killApp(app).catch(() => {}) 'Thank you for trying Next.js v13 with Turbopack!'
await fs.remove(nextConfigPath) )
} expect(output).not.toContain(
}) 'You are using configuration and/or tools that are not yet'
)
it('should warn with next.config.js with unsupported field', async () => { expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
let output = '' } finally {
await fs.writeFile( await killApp(app).catch(() => {})
nextConfigPath, await fs.remove(nextConfigPath)
`module.exports = { }
assetPrefix: '/idk'
}`
)
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
turbo: true,
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
}) })
try { it('should warn with next.config.js with unsupported field', async () => {
expect(output).toContain( let output = ''
'Thank you for trying Next.js v13 with Turbopack!' await fs.writeFile(
) nextConfigPath,
expect(output).toContain( `module.exports = {
'You are using configuration and/or tools that are not yet' assetPrefix: '/idk'
}`
) )
} finally { const appPort = await findPort()
await killApp(app).catch(() => {}) const app = await launchApp(appDir, appPort, {
await fs.remove(nextConfigPath) onStdout(msg) {
} output += msg
}) },
onStderr(msg) {
output += msg
},
})
try {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).toContain(
'You are using configuration and/or tools that are not yet'
)
} finally {
await killApp(app).catch(() => {})
await fs.remove(nextConfigPath)
}
})
} else {
it.skip('turobpack only', () => {})
}
}) })
...@@ -376,9 +376,7 @@ export function runNextCommandDev(argv, stdOut, opts = {}) { ...@@ -376,9 +376,7 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
// Launch the app in dev mode. // Launch the app in dev mode.
export function launchApp(dir, port, opts) { export function launchApp(dir, port, opts) {
const options = opts ?? {} const options = opts ?? {}
const useTurbo = !!process.env.TEST_WASM const useTurbo = shouldRunTurboDevTest()
? false
: options?.turbo ?? shouldRunTurboDevTest()
return runNextCommandDev( return runNextCommandDev(
[useTurbo ? '--turbo' : undefined, dir, '-p', port].filter(Boolean), [useTurbo ? '--turbo' : undefined, dir, '-p', port].filter(Boolean),
...@@ -921,38 +919,16 @@ export function shouldRunTurboDevTest() { ...@@ -921,38 +919,16 @@ export function shouldRunTurboDevTest() {
return false return false
} }
const shouldRunTurboDev = !!process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_DEV const shouldRunTurboDev = !!process.env.TURBOPACK
// short-circuit to run all the test with --turbo enabled skips glob matching costs // short-circuit to run all the test with --turbo enabled skips glob matching costs
if (shouldRunTurboDev) { if (shouldRunTurboDev) {
console.log( console.log(
`Running tests with --turbo via custom environment variable __INTERNAL_NEXT_DEV_TEST_TURBO_DEV` `Running tests with turbopack via custom environment variable TURBOPACK`
) )
return true return true
} }
const shouldRunTurboDevWithMatches = return false
!!process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH
// By default, we do not run any tests with `--turbo` flag.
if (!shouldRunTurboDevWithMatches) {
return false
}
const glob = require('glob')
const matches = glob.sync(
process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH
)
const testPath = expect.getState().testPath
const isMatch = matches.some((match) => testPath.includes(match))
if (isMatch) {
console.log(
`Running tests with --turbo via custom environment variable __INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH`
)
}
// If the test path matches the glob pattern, add additional case to run the test with `--turbo` flag.
return isMatch
} }
// WEB-168: There are some differences / incompletes in turbopack implementation enforces jest requires to update // WEB-168: There are some differences / incompletes in turbopack implementation enforces jest requires to update
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment