Skip to content

Commit

Permalink
use env var to switch next.js to turbopack mode (#51353)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
sokra committed Jun 21, 2023
1 parent bc9ed9d commit 36a7aff
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 378 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
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

test-next-swc-wasm:
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (shouldEnableTestTrace) {
customJestConfig.reporters = ['default']
}

const outputDirectory = process.env.__INTERNAL_NEXT_DEV_TEST_TURBO_DEV
const outputDirectory = process.env.TURBOPACK
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'
customJestConfig.reporters.push([
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-dev-tests/tests-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const enabledTests = [
'test/development/basic/define-class-fields.test.ts',
'test/development/basic/emotion-swc.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/theme-ui.test.ts',
'test/development/dotenv-default-expansion/index.test.ts',
Expand All @@ -23,7 +22,6 @@ const enabledTests = [
'test/development/project-directory-with-styled-jsx-suffix/index.test.ts',
'test/development/repeated-dev-edits/repeated-dev-edits.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/actions/app-action-export.test.ts',
'test/e2e/app-dir/app-alias/app-alias.test.ts',
Expand Down Expand Up @@ -256,6 +254,8 @@ const enabledTests = [
'test/integration/static-page-name/test/index.test.js',
'test/integration/styled-jsx-plugin/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/typeof-window-replace/test/index.test.js',
'test/integration/typescript-baseurl/test/index.test.js',
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/cli/next-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ const nextBuild: CliCommand = (argv) => {
printAndExit(`> No such directory exists as the project root: ${dir}`)
}

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

return build(
dir,
args['--profile'],
args['--debug'] || process.env.NEXT_DEBUG_BUILD,
!args['--no-lint'],
args['--no-mangling'],
args['--experimental-app-only'],
args['--experimental-turbo'],
!!process.env.TURBOPACK,
args['--build-mode'] || 'default'
).catch((err) => {
console.error('')
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ const nextDev: CliCommand = async (argv) => {
}

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

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

const { validateTurboNextConfig } =
Expand Down
32 changes: 0 additions & 32 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2732,38 +2732,6 @@ describe('Custom routes', () => {
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', () => {
beforeAll(async () => {
appPort = await findPort()
Expand Down

0 comments on commit 36a7aff

Please sign in to comment.