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:
parent
bc9ed9de98
commit
36a7aff6d6
9 changed files with 349 additions and 392 deletions
2
.github/workflows/build_and_test.yml
vendored
2
.github/workflows/build_and_test.yml
vendored
|
@ -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:
|
||||
|
|
|
@ -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([
|
||||
|
|
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
|
|
@ -74,6 +74,10 @@ 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'],
|
||||
|
@ -81,7 +85,7 @@ const nextBuild: CliCommand = (argv) => {
|
|||
!args['--no-lint'],
|
||||
args['--no-mangling'],
|
||||
args['--experimental-app-only'],
|
||||
args['--experimental-turbo'],
|
||||
!!process.env.TURBOPACK,
|
||||
args['--build-mode'] || 'default'
|
||||
).catch((err) => {
|
||||
console.error('')
|
||||
|
|
|
@ -221,6 +221,10 @@ const nextDev: CliCommand = async (argv) => {
|
|||
}
|
||||
|
||||
if (args['--turbo']) {
|
||||
process.env.TURBOPACK = '1'
|
||||
}
|
||||
|
||||
if (process.env.TURBOPACK) {
|
||||
isTurboSession = true
|
||||
|
||||
const { validateTurboNextConfig } =
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -34,283 +34,287 @@ const setupAppDir = async () => {
|
|||
}
|
||||
|
||||
describe('page features telemetry', () => {
|
||||
it('detects --turbo correctly for `next dev`', async () => {
|
||||
let port = await findPort()
|
||||
let stderr = ''
|
||||
if (process.env.TURBOPACK) {
|
||||
it('detects --turbo correctly for `next dev`', 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)
|
||||
}
|
||||
const teardown = await setupAppDir()
|
||||
|
||||
try {
|
||||
expect(stderr).toContain('NEXT_CLI_SESSION_STARTED')
|
||||
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
|
||||
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 {
|
||||
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)
|
||||
.pop()
|
||||
|
||||
expect(event1).toMatch(/"pagesDir": true/)
|
||||
expect(event1).toMatch(/"turboFlag": true/)
|
||||
} catch (err) {
|
||||
require('console').error('failing stderr', stderr, err)
|
||||
throw err
|
||||
|
||||
expect(
|
||||
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 () => {
|
||||
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,
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
const handleStderr = (msg) => {
|
||||
stderr += msg
|
||||
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()
|
||||
}
|
||||
let app = await launchApp(appDir, port, {
|
||||
onStderr: handleStderr,
|
||||
env: {
|
||||
NEXT_TELEMETRY_DEBUG: 1,
|
||||
},
|
||||
turbo: true,
|
||||
})
|
||||
|
||||
it('should detect app page counts', async () => {
|
||||
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,
|
||||
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/)
|
||||
|
||||
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)
|
||||
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
|
||||
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
|
||||
.exec(build.stderr)
|
||||
.pop()
|
||||
expect(event1).toMatch(/hasReportWebVitals.*?false/)
|
||||
})
|
||||
|
||||
expect(event1).toMatch(/"pagesDir": true/)
|
||||
expect(event1).toMatch(/"turboFlag": true/)
|
||||
|
||||
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
|
||||
false
|
||||
it('detect with reportWebVitals correctly for `next build`', async () => {
|
||||
// Case 2: When _app.js exist with reportWebVitals function.
|
||||
await fs.utimes(
|
||||
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
|
||||
new Date(),
|
||||
new Date()
|
||||
)
|
||||
} finally {
|
||||
await teardown()
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
await fs.rename(
|
||||
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
|
||||
path.join(appDir, 'pages', '_app.js')
|
||||
)
|
||||
} finally {
|
||||
await teardown()
|
||||
}
|
||||
})
|
||||
|
||||
it('should detect app page counts', async () => {
|
||||
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, [], {
|
||||
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_withreportwebvitals.empty')
|
||||
)
|
||||
|
||||
try {
|
||||
expect(stderr).toContain('NEXT_BUILD_OPTIMIZED')
|
||||
expect(build.stderr).toContain('NEXT_BUILD_OPTIMIZED')
|
||||
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
|
||||
.exec(stderr)
|
||||
.exec(build.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/)
|
||||
expect(event1).toMatch(/hasReportWebVitals.*?true/)
|
||||
} catch (err) {
|
||||
require('console').error('failing stderr', stderr, err)
|
||||
require('console').error(build.stderr)
|
||||
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')
|
||||
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
|
||||
.exec(build.stderr)
|
||||
.pop()
|
||||
expect(event1).toMatch(/hasReportWebVitals.*?false/)
|
||||
})
|
||||
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')
|
||||
)
|
||||
|
||||
it('detect with reportWebVitals correctly for `next build`', async () => {
|
||||
// Case 2: When _app.js exist with reportWebVitals function.
|
||||
await fs.utimes(
|
||||
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, [], {
|
||||
stderr: true,
|
||||
env: { NEXT_TELEMETRY_DEBUG: 1 },
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -3,93 +3,94 @@ import fs from 'fs-extra'
|
|||
import { join } from 'path'
|
||||
|
||||
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 () => {
|
||||
let output = ''
|
||||
const appPort = await findPort()
|
||||
const app = await launchApp(appDir, appPort, {
|
||||
turbo: true,
|
||||
onStdout(msg) {
|
||||
output += msg
|
||||
},
|
||||
onStderr(msg) {
|
||||
output += msg
|
||||
},
|
||||
it('should not warn by default', async () => {
|
||||
let output = ''
|
||||
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(() => {})
|
||||
}
|
||||
})
|
||||
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 {
|
||||
expect(output).toContain(
|
||||
'Thank you for trying Next.js v13 with Turbopack!'
|
||||
it('should warn with next.config.js with unsupported field', async () => {
|
||||
let output = ''
|
||||
await fs.writeFile(
|
||||
nextConfigPath,
|
||||
`module.exports = {
|
||||
assetPrefix: '/idk'
|
||||
}`
|
||||
)
|
||||
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')
|
||||
const appPort = await findPort()
|
||||
const app = await launchApp(appDir, appPort, {
|
||||
onStdout(msg) {
|
||||
output += msg
|
||||
},
|
||||
onStderr(msg) {
|
||||
output += msg
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
},
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
it.skip('turobpack only', () => {})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -376,9 +376,7 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
|
|||
// Launch the app in dev mode.
|
||||
export function launchApp(dir, port, opts) {
|
||||
const options = opts ?? {}
|
||||
const useTurbo = !!process.env.TEST_WASM
|
||||
? false
|
||||
: options?.turbo ?? shouldRunTurboDevTest()
|
||||
const useTurbo = shouldRunTurboDevTest()
|
||||
|
||||
return runNextCommandDev(
|
||||
[useTurbo ? '--turbo' : undefined, dir, '-p', port].filter(Boolean),
|
||||
|
@ -921,38 +919,16 @@ export function shouldRunTurboDevTest() {
|
|||
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
|
||||
if (shouldRunTurboDev) {
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
return false
|
||||
}
|
||||
|
||||
// WEB-168: There are some differences / incompletes in turbopack implementation enforces jest requires to update
|
||||
|
|
Loading…
Reference in a new issue