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()
......
...@@ -34,6 +34,7 @@ const setupAppDir = async () => { ...@@ -34,6 +34,7 @@ const setupAppDir = async () => {
} }
describe('page features telemetry', () => { describe('page features telemetry', () => {
if (process.env.TURBOPACK) {
it('detects --turbo correctly for `next dev`', async () => { it('detects --turbo correctly for `next dev`', async () => {
let port = await findPort() let port = await findPort()
let stderr = '' let stderr = ''
...@@ -107,14 +108,14 @@ describe('page features telemetry', () => { ...@@ -107,14 +108,14 @@ describe('page features telemetry', () => {
expect(event1).toMatch(/"pagesDir": true/) expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/) expect(event1).toMatch(/"turboFlag": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe( expect(
false await fs.pathExists(path.join(appDir, '.next/_events.json'))
) ).toBe(false)
} finally { } finally {
await teardown() await teardown()
} }
}) })
} else {
it('detects correctly for `next dev` stopped (no turbo)', async () => { it('detects correctly for `next dev` stopped (no turbo)', async () => {
let port = await findPort() let port = await findPort()
let stderr = '' let stderr = ''
...@@ -149,9 +150,9 @@ describe('page features telemetry', () => { ...@@ -149,9 +150,9 @@ describe('page features telemetry', () => {
expect(event1).toMatch(/"pagesDir": true/) expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/) expect(event1).toMatch(/"appDir": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe( expect(
false await fs.pathExists(path.join(appDir, '.next/_events.json'))
) ).toBe(false)
} finally { } finally {
await teardown() await teardown()
} }
...@@ -181,7 +182,9 @@ describe('page features telemetry', () => { ...@@ -181,7 +182,9 @@ describe('page features telemetry', () => {
} }
` `
) )
await fs.ensureFile(path.join(__dirname, '../app/app-ssg/[slug]/page.js')) await fs.ensureFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js')
)
await fs.writeFile( await fs.writeFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js'), path.join(__dirname, '../app/app-ssg/[slug]/page.js'),
` `
...@@ -313,4 +316,5 @@ describe('page features telemetry', () => { ...@@ -313,4 +316,5 @@ describe('page features telemetry', () => {
throw err throw err
} }
}) })
}
}) })
...@@ -3,13 +3,13 @@ import fs from 'fs-extra' ...@@ -3,13 +3,13 @@ import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
describe('turbopack unsupported features log', () => { describe('turbopack unsupported features log', () => {
if (process.env.TURBOPACK) {
const appDir = join(__dirname, 'app') 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
}, },
...@@ -37,7 +37,6 @@ describe('turbopack unsupported features log', () => { ...@@ -37,7 +37,6 @@ describe('turbopack unsupported features log', () => {
await fs.writeFile(nextConfigPath, `module.exports = {}`) await fs.writeFile(nextConfigPath, `module.exports = {}`)
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
}, },
...@@ -71,7 +70,6 @@ describe('turbopack unsupported features log', () => { ...@@ -71,7 +70,6 @@ describe('turbopack unsupported features log', () => {
) )
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
}, },
...@@ -92,4 +90,7 @@ describe('turbopack unsupported features log', () => { ...@@ -92,4 +90,7 @@ describe('turbopack unsupported features log', () => {
await fs.remove(nextConfigPath) 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 =
!!process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH
// By default, we do not run any tests with `--turbo` flag.
if (!shouldRunTurboDevWithMatches) {
return false 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