29c2e89bd1
This breaks up some of our longest running tests which allows more parallelizing of the tests. This also moves turbopack tests filtering back to an allow list as it is running a lot of unrelated tests currently which isn't ideal. We should only be running against tests that are explicitly testing turbopack e.g. build tests should not be duplicated in the turbopack group. ```sh test/integration/css/test/group-1.test.js: 762.655 test/integration/edge-runtime-module-errors/test/index.test.js: 695.309 test/integration/css/test/group-2.test.js: 671.848 test/integration/i18n-support/test/index.test.js: 518.173 test/integration/scss-modules/test/index.test.js: 451.704 test/integration/css-features/test/index.test.js: 417.318 test/integration/css-modules/test/index.test.js: 403.405 test/integration/eslint/test/index.test.js: 381.563 test/integration/500-page/test/index.test.js: 371.134 test/integration/telemetry/test/index.test.js: 367.691 test/development/acceptance-app/ReactRefreshLogBox.test.ts: 335.878 test/integration/create-next-app/templates.test.ts: 334.01 test/integration/scss/test/group-2.test.js: 327.255 test/integration/scss/test/group-1.test.js: 318.574 test/integration/edge-runtime-configurable-guards/test/index.test.js: 313.834 test/e2e/instrumentation-hook/instrumentation-hook.test.ts: 294.618 test/development/acceptance-app/error-recovery.test.ts: 283.355 test/e2e/app-dir/app/vercel-speed-insights.test.ts: 278.242 test/integration/create-next-app/index.test.ts: 272.442 ```
196 lines
4.8 KiB
TypeScript
196 lines
4.8 KiB
TypeScript
/* eslint-env jest */
|
|
/**
|
|
* @fileoverview
|
|
*
|
|
* This file contains tests for `create-next-app` templates, currently
|
|
* JavaScript (default), TypeScript, and appDir.
|
|
*/
|
|
|
|
import path from 'path'
|
|
import fs from 'fs-extra'
|
|
import {
|
|
createNextApp,
|
|
shouldBeTemplateProject,
|
|
spawnExitPromise,
|
|
} from './lib/utils'
|
|
import { Span } from 'next/dist/trace'
|
|
|
|
import { useTempDir } from '../../lib/use-temp-dir'
|
|
import { fetchViaHTTP, findPort, killApp, launchApp } from 'next-test-utils'
|
|
import resolveFrom from 'resolve-from'
|
|
import { createNextInstall } from '../../lib/create-next-install'
|
|
|
|
const startsWithoutError = async (
|
|
appDir: string,
|
|
modes = ['default', 'turbo'],
|
|
usingAppDirectory: boolean = false
|
|
) => {
|
|
for (const mode of modes) {
|
|
appDir = await fs.realpath(appDir)
|
|
const appPort = await findPort()
|
|
const app = await launchApp(appDir, appPort, {
|
|
turbo: mode === 'turbo',
|
|
cwd: appDir,
|
|
nextBin: resolveFrom(appDir, 'next/dist/bin/next'),
|
|
})
|
|
|
|
try {
|
|
const res = await fetchViaHTTP(appPort, '/')
|
|
expect(await res.text()).toContain('Get started by editing')
|
|
expect(res.status).toBe(200)
|
|
|
|
if (!usingAppDirectory) {
|
|
const apiRes = await fetchViaHTTP(appPort, '/api/hello')
|
|
expect(await apiRes.json()).toEqual({ name: 'John Doe' })
|
|
expect(apiRes.status).toBe(200)
|
|
}
|
|
} finally {
|
|
await killApp(app)
|
|
}
|
|
}
|
|
}
|
|
let testVersion
|
|
|
|
describe('create-next-app --app', () => {
|
|
beforeAll(async () => {
|
|
if (testVersion) return
|
|
const span = new Span({ name: 'parent' })
|
|
testVersion = (
|
|
await createNextInstall({ onlyPackages: true, parentSpan: span })
|
|
).get('next')
|
|
})
|
|
|
|
it('should create TS appDir projects with --ts', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'appdir-test'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--no-tailwind',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
`--import-alias=@/*`,
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
|
|
await startsWithoutError(
|
|
path.join(cwd, projectName),
|
|
['default', 'turbo'],
|
|
true
|
|
)
|
|
})
|
|
})
|
|
|
|
it('should create JS appDir projects with --js', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'appdir-test'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--js',
|
|
'--no-tailwind',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
`--import-alias=@/*`,
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' })
|
|
// is landed
|
|
await startsWithoutError(
|
|
path.join(cwd, projectName),
|
|
['default', 'turbo'],
|
|
true
|
|
)
|
|
})
|
|
})
|
|
|
|
it('should create JS appDir projects with --js --src-dir', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'appdir-test'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--js',
|
|
'--no-tailwind',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--import-alias=@/*',
|
|
],
|
|
{
|
|
cwd,
|
|
stdio: 'inherit',
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app',
|
|
mode: 'js',
|
|
srcDir: true,
|
|
})
|
|
await startsWithoutError(
|
|
path.join(cwd, projectName),
|
|
['default', 'turbo'],
|
|
true
|
|
)
|
|
})
|
|
})
|
|
|
|
it('should create Tailwind CSS appDir projects with --tailwind', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'appdir-tailwind-test'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--tailwind',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
`--import-alias=@/*`,
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app-tw',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await startsWithoutError(
|
|
path.join(cwd, projectName),
|
|
['default', 'turbo'],
|
|
true
|
|
)
|
|
})
|
|
})
|
|
})
|