Skip to content

Commit

Permalink
Run CNA tests with Next.js from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 16, 2024
1 parent aafa682 commit fdde722
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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
10 changes: 6 additions & 4 deletions test/integration/create-next-app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ export const DEFAULT_FILES = [
'node_modules/next',
]

export const run = (
export const run = async (
args: string[],
nextJSVersion: string,
options:
| execa.Options
| {
reject?: boolean
env?: Record<string, string>
}
) =>
execa('node', [CNA_PATH].concat(args), {
) => {
return execa('node', [CNA_PATH].concat(args), {
// tests with options.reject false are expected to exit(1) so don't inherit
stdio: options.reject === false ? 'pipe' : 'inherit',
...options,
env: {
...process.env,
...options.env,
NEXT_PRIVATE_TEST_VERSION: 'canary',
NEXT_PRIVATE_TEST_VERSION: nextJSVersion,
},
})
}

export const command = (cmd: string, args: string[]) =>
execa(cmd, args, {
Expand Down

0 comments on commit fdde722

Please sign in to comment.