Skip to content

Commit

Permalink
Run CNA tests with Next.js from branch (#65852)
Browse files Browse the repository at this point in the history
This is probably not complete but something in that direction.

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
  • Loading branch information
eps1lon and huozhi committed May 16, 2024
1 parent afe4f2f commit aed5242
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 30 deletions.
47 changes: 37 additions & 10 deletions test/integration/create-next-app/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../lib/create-next-install'
import {
EXAMPLE_PATH,
EXAMPLE_REPO,
Expand All @@ -10,12 +12,23 @@ import {
} from './utils'

describe('create-next-app --example', () => {
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})
it('should create on valid Next.js example name', async () => {
await useTempDir(async (cwd) => {
const projectName = 'valid-example'
const res = await run([projectName, '--example', 'basic-css'], {
cwd,
})
const res = await run(
[projectName, '--example', 'basic-css'],
nextInstall.installDir,
{
cwd,
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
Expand All @@ -34,9 +47,13 @@ describe('create-next-app --example', () => {
it('should create with GitHub URL', async () => {
await useTempDir(async (cwd) => {
const projectName = 'github-url'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down Expand Up @@ -64,6 +81,7 @@ describe('create-next-app --example', () => {
// GH#39665
'https://github.com/vercel/nextjs-portfolio-starter/',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -97,6 +115,7 @@ describe('create-next-app --example', () => {
'--example-path',
EXAMPLE_PATH,
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -131,6 +150,7 @@ describe('create-next-app --example', () => {
'--example-path',
EXAMPLE_PATH,
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -168,6 +188,7 @@ describe('create-next-app --example', () => {
'__internal-testing-retry',
'--import-alias=@/*',
],
nextInstall.installDir,
{
cwd,
input: '\n', // 'Yes' to retry
Expand Down Expand Up @@ -199,6 +220,7 @@ describe('create-next-app --example', () => {
'default',
'--import-alias=@/*',
],
nextInstall.installDir,
{
cwd,
}
Expand All @@ -217,10 +239,14 @@ describe('create-next-app --example', () => {
it('should not create if --example flag value is invalid', async () => {
await useTempDir(async (cwd) => {
const projectName = 'invalid-example'
const res = await run([projectName, '--example', 'not a real example'], {
cwd,
reject: false,
})
const res = await run(
[projectName, '--example', 'not a real example'],
nextInstall.installDir,
{
cwd,
reject: false,
}
)

expect(res.exitCode).toBe(1)
projectFilesShouldNotExist({
Expand All @@ -244,6 +270,7 @@ describe('create-next-app --example', () => {
'--no-tailwind',
'--example',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down
13 changes: 13 additions & 0 deletions test/integration/create-next-app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import {
projectFilesShouldExist,
projectFilesShouldNotExist,
} from './utils'
import { createNextInstall } from '../../lib/create-next-install'
import { trace } from 'next/dist/trace'

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app', () => {
it('should not create if the target directory is not empty', async () => {
Expand All @@ -25,6 +35,7 @@ describe('create-next-app', () => {
'--no-src-dir',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down Expand Up @@ -64,6 +75,7 @@ describe('create-next-app', () => {
'--no-src-dir',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down Expand Up @@ -93,6 +105,7 @@ describe('create-next-app', () => {
'--no-import-alias',
'--skip-install',
],
nextInstall.installDir,
{
cwd,
}
Expand Down
25 changes: 21 additions & 4 deletions test/integration/create-next-app/package-manager/bun.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../../lib/create-next-install'
import {
command,
DEFAULT_FILES,
Expand All @@ -16,6 +18,14 @@ beforeEach(async () => {
.catch(() => command('npm', ['i', '-g', 'bun']))
})

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app with package manager bun', () => {
it('should use bun for --use-bun flag', async () => {
await useTempDir(async (cwd) => {
Expand All @@ -31,6 +41,7 @@ describe('create-next-app with package manager bun', () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -59,6 +70,7 @@ it('should use bun when user-agent is bun', async () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'bun' },
Expand All @@ -79,6 +91,7 @@ it('should use bun for --use-bun flag with example', async () => {
const projectName = 'use-bun-with-example'
const res = await run(
[projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{ cwd }
)

Expand All @@ -94,10 +107,14 @@ it('should use bun for --use-bun flag with example', async () => {
it('should use bun when user-agent is bun with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-bun-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'bun' },
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'bun' },
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down
25 changes: 21 additions & 4 deletions test/integration/create-next-app/package-manager/npm.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { trace } from 'next/dist/trace'
import {
DEFAULT_FILES,
FULL_EXAMPLE_PATH,
projectFilesShouldExist,
run,
useTempDir,
} from '../utils'
import { createNextInstall } from '../../../lib/create-next-install'

const lockFile = 'package-lock.json'
const files = [...DEFAULT_FILES, lockFile]

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app with package manager npm', () => {
it('should use npm for --use-npm flag', async () => {
await useTempDir(async (cwd) => {
Expand All @@ -24,6 +34,7 @@ describe('create-next-app with package manager npm', () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -52,6 +63,7 @@ it('should use npm when user-agent is npm', async () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'npm' },
Expand All @@ -72,6 +84,7 @@ it('should use npm for --use-npm flag with example', async () => {
const projectName = 'use-npm-with-example'
const res = await run(
[projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{ cwd }
)

Expand All @@ -87,10 +100,14 @@ it('should use npm for --use-npm flag with example', async () => {
it('should use npm when user-agent is npm with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-npm-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'npm' },
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'npm' },
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down
25 changes: 21 additions & 4 deletions test/integration/create-next-app/package-manager/pnpm.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../../lib/create-next-install'
import {
command,
DEFAULT_FILES,
Expand All @@ -10,6 +12,14 @@ import {
const lockFile = 'pnpm-lock.yaml'
const files = [...DEFAULT_FILES, lockFile]

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

beforeEach(async () => {
await command('pnpm', ['--version'])
// install pnpm if not available
Expand All @@ -32,6 +42,7 @@ describe('create-next-app with package manager pnpm', () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -60,6 +71,7 @@ it('should use pnpm when user-agent is pnpm', async () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'pnpm' },
Expand All @@ -80,6 +92,7 @@ it('should use pnpm for --use-pnpm flag with example', async () => {
const projectName = 'use-pnpm-with-example'
const res = await run(
[projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{ cwd }
)

Expand All @@ -95,10 +108,14 @@ it('should use pnpm for --use-pnpm flag with example', async () => {
it('should use pnpm when user-agent is pnpm with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-pnpm-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'pnpm' },
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'pnpm' },
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down

0 comments on commit aed5242

Please sign in to comment.