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
This commit is contained in:
Tobias Koppers 2023-06-21 15:52:14 +02:00 committed by GitHub
parent bc9ed9de98
commit 36a7aff6d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 349 additions and 392 deletions

View file

@ -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:

View file

@ -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([

View file

@ -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 = [
'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 = [
'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',

View file

@ -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) => {
!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('')

View file

@ -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 } =

View file

@ -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()

View file

@ -34,283 +34,287 @@ const setupAppDir = async () => {
} }
describe('page features telemetry', () => { describe('page features telemetry', () => {
it('detects --turbo correctly for `next dev`', async () => { if (process.env.TURBOPACK) {
let port = await findPort() it('detects --turbo correctly for `next dev`', async () => {
let stderr = '' let port = await findPort()
let stderr = ''
const teardown = await setupAppDir() const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await killApp(app)
}
try { try {
expect(stderr).toContain('NEXT_CLI_SESSION_STARTED') const handleStderr = (msg) => {
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/ stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await killApp(app)
}
try {
expect(stderr).toContain('NEXT_CLI_SESSION_STARTED')
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
} finally {
await teardown()
}
})
it('detects --turbo correctly for `next dev` stopped', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
expect(stderr).toContain('NEXT_CLI_SESSION_STOPPED')
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr) .exec(stderr)
.pop() .pop()
expect(event1).toMatch(/"pagesDir": true/) expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/) expect(event1).toMatch(/"turboFlag": true/)
} catch (err) {
require('console').error('failing stderr', stderr, err) expect(
throw err await fs.pathExists(path.join(appDir, '.next/_events.json'))
).toBe(false)
} finally {
await teardown()
} }
} finally { })
await teardown() } else {
} it('detects correctly for `next dev` stopped (no turbo)', async () => {
}) let port = await findPort()
let stderr = ''
it('detects --turbo correctly for `next dev` stopped', async () => { const teardown = await setupAppDir()
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir() try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
try { await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
const handleStderr = (msg) => {
stderr += msg if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
expect(stderr).toContain('NEXT_CLI_SESSION_STOPPED')
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/)
expect(
await fs.pathExists(path.join(appDir, '.next/_events.json'))
).toBe(false)
} finally {
await teardown()
} }
let app = await launchApp(appDir, port, { })
onStderr: handleStderr,
env: { it('should detect app page counts', async () => {
NEXT_TELEMETRY_DEBUG: 1, const teardown = await setupAppDir()
},
turbo: true, try {
await fs.ensureFile(path.join(__dirname, '../app/ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/ssr/page.js'),
`
export const revalidate = 0
export default function Page() {
return <p>ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/edge-ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/edge-ssr/page.js'),
`
export const runtime = 'experimental-edge'
export default function Page() {
return <p>edge-ssr page</p>
}
`
)
await fs.ensureFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js')
)
await fs.writeFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js'),
`
export function generateStaticParams() {
return [
{ slug: 'post-1' },
{ slug: 'post-2' },
]
}
export default function Page() {
return <p>ssg page</p>
}
`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
try {
expect(stderr).toContain('NEXT_BUILD_OPTIMIZED')
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/)
expect(event1).toMatch(/"serverPropsPageCount": 2/)
expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 4/)
expect(event1).toMatch(/"totalPageCount": 11/)
expect(event1).toMatch(/"totalAppPagesCount": 4/)
expect(event1).toMatch(/"serverAppPagesCount": 2/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 1/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
expect(stderr).toContain('NEXT_BUILD_COMPLETED')
const event2 = /NEXT_BUILD_COMPLETED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event2).toMatch(/"totalAppPagesCount": 4/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
} finally {
await teardown()
}
})
it('detects reportWebVitals with no _app correctly for `next build`', async () => {
// Case 1: When _app.js does not exist.
let build = await nextBuild(appDir, [], {
stderr: 'log',
stdout: 'log',
env: { NEXT_TELEMETRY_DEBUG: 1 },
}) })
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/) expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
if (app) { .exec(build.stderr)
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
expect(stderr).toContain('NEXT_CLI_SESSION_STOPPED')
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop() .pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
})
expect(event1).toMatch(/"pagesDir": true/) it('detect with reportWebVitals correctly for `next build`', async () => {
expect(event1).toMatch(/"turboFlag": true/) // Case 2: When _app.js exist with reportWebVitals function.
await fs.utimes(
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe( path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
false new Date(),
new Date()
) )
} finally { await fs.rename(
await teardown() path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
} path.join(appDir, 'pages', '_app.js')
})
it('detects correctly for `next dev` stopped (no turbo)', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
expect(stderr).toContain('NEXT_CLI_SESSION_STOPPED')
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
false
) )
} finally {
await teardown()
}
})
it('should detect app page counts', async () => { const build = await nextBuild(appDir, [], {
const teardown = await setupAppDir()
try {
await fs.ensureFile(path.join(__dirname, '../app/ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/ssr/page.js'),
`
export const revalidate = 0
export default function Page() {
return <p>ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/edge-ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/edge-ssr/page.js'),
`
export const runtime = 'experimental-edge'
export default function Page() {
return <p>edge-ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/app-ssg/[slug]/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js'),
`
export function generateStaticParams() {
return [
{ slug: 'post-1' },
{ slug: 'post-2' },
]
}
export default function Page() {
return <p>ssg page</p>
}
`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 }, env: { NEXT_TELEMETRY_DEBUG: 1 },
}) })
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withreportwebvitals.empty')
)
try { try {
expect(stderr).toContain('NEXT_BUILD_OPTIMIZED') expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/ const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(stderr) .exec(build.stderr)
.pop() .pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/) expect(event1).toMatch(/hasReportWebVitals.*?true/)
expect(event1).toMatch(/"serverPropsPageCount": 2/)
expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 4/)
expect(event1).toMatch(/"totalPageCount": 11/)
expect(event1).toMatch(/"totalAppPagesCount": 4/)
expect(event1).toMatch(/"serverAppPagesCount": 2/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 1/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
expect(stderr).toContain('NEXT_BUILD_COMPLETED')
const event2 = /NEXT_BUILD_COMPLETED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event2).toMatch(/"totalAppPagesCount": 4/)
} catch (err) { } catch (err) {
require('console').error('failing stderr', stderr, err) require('console').error(build.stderr)
throw err throw err
} }
} finally {
await teardown()
}
})
it('detects reportWebVitals with no _app correctly for `next build`', async () => {
// Case 1: When _app.js does not exist.
let build = await nextBuild(appDir, [], {
stderr: 'log',
stdout: 'log',
env: { NEXT_TELEMETRY_DEBUG: 1 },
}) })
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED') it('detect without reportWebVitals correctly for `next build`', async () => {
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/ // Case 3: When _app.js exist without reportWebVitals function.
.exec(build.stderr) await fs.utimes(
.pop() path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
expect(event1).toMatch(/hasReportWebVitals.*?false/) new Date(),
}) new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
it('detect with reportWebVitals correctly for `next build`', async () => { const build = await nextBuild(appDir, [], {
// Case 2: When _app.js exist with reportWebVitals function. stderr: true,
await fs.utimes( env: { NEXT_TELEMETRY_DEBUG: 1 },
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'), })
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
const build = await nextBuild(appDir, [], { await fs.rename(
stderr: true, path.join(appDir, 'pages', '_app.js'),
env: { NEXT_TELEMETRY_DEBUG: 1 }, path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty')
)
try {
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(build.stderr)
.pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
} catch (err) {
require('console').error(build.stderr)
throw err
}
}) })
}
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withreportwebvitals.empty')
)
try {
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(build.stderr)
.pop()
expect(event1).toMatch(/hasReportWebVitals.*?true/)
} catch (err) {
require('console').error(build.stderr)
throw err
}
})
it('detect without reportWebVitals correctly for `next build`', async () => {
// Case 3: When _app.js exist without reportWebVitals function.
await fs.utimes(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
const build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty')
)
try {
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(build.stderr)
.pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
} catch (err) {
require('console').error(build.stderr)
throw err
}
})
}) })

View file

@ -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 {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).not.toContain(
'You are using configuration and/or tools that are not yet'
)
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally {
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, {
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
try {
expect(output).toContain(
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).not.toContain(
'You are using configuration and/or tools that are not yet'
)
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally {
await killApp(app).catch(() => {})
await fs.remove(nextConfigPath)
}
}) })
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,
`module.exports = {
assetPrefix: '/idk'
}`
) )
expect(output).not.toContain( const appPort = await findPort()
'You are using configuration and/or tools that are not yet' const app = await launchApp(appDir, appPort, {
) onStdout(msg) {
expect(await renderViaHTTP(appPort, '/')).toContain('hello world') output += msg
} finally { },
await killApp(app).catch(() => {}) onStderr(msg) {
} output += msg
}) },
const nextConfigPath = join(appDir, 'next.config.js') })
it('should not warn with empty next.config.js', async () => { try {
let output = '' expect(output).toContain(
await fs.writeFile(nextConfigPath, `module.exports = {}`) 'Thank you for trying Next.js v13 with Turbopack!'
const appPort = await findPort() )
const app = await launchApp(appDir, appPort, { expect(output).toContain(
turbo: true, 'You are using configuration and/or tools that are not yet'
onStdout(msg) { )
output += msg } finally {
}, await killApp(app).catch(() => {})
onStderr(msg) { await fs.remove(nextConfigPath)
output += msg }
},
}) })
} else {
try { it.skip('turobpack only', () => {})
expect(output).toContain( }
'Thank you for trying Next.js v13 with Turbopack!'
)
expect(output).not.toContain(
'You are using configuration and/or tools that are not yet'
)
expect(await renderViaHTTP(appPort, '/')).toContain('hello world')
} finally {
await killApp(app).catch(() => {})
await fs.remove(nextConfigPath)
}
})
it('should warn with next.config.js with unsupported field', async () => {
let output = ''
await fs.writeFile(
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 {
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)
}
})
}) })

View file

@ -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() {
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