Skip to content

Commit

Permalink
chore(test): add logs for create-next-app tests (vercel#56957)
Browse files Browse the repository at this point in the history
This will help us debug why these tests sometimes flake by logging which command was running last.
  • Loading branch information
styfle authored Oct 18, 2023
1 parent 66597be commit 92cccfb
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions test/integration/create-next-app/package-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const env = { ...process.env, COREPACK_ENABLE_STRICT: '0' }
const run = (args: string[], options: execa.Options) => {
const conf = new Conf({ projectName: 'create-next-app' })
conf.clear()
return execa('node', [cli].concat(args), options)
console.log(`Running "create-next-app ${args.join(' ')}"`)
return execa('node', [cli].concat(args), { ...options, stdio: 'inherit' })
}

const command = (cmd: string, args: string[]) => {
console.log(`Running command "${cmd} ${args.join(' ')}"`)
return execa(cmd, args, { stdio: 'inherit' })
}

it('should use npm as the package manager on supplying --use-npm', async () => {
Expand Down Expand Up @@ -120,13 +126,13 @@ it('should use Yarn as the package manager on supplying --use-yarn', async () =>

it('should use Yarn as the package manager on supplying --use-yarn with example', async () => {
try {
await execa('yarn', ['--version'])
await command('yarn', ['--version'])
} catch (_) {
// install yarn if not available
try {
await execa('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
await command('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
} catch (_) {
await execa('npm', ['i', '-g', 'yarn'])
await command('npm', ['i', '-g', 'yarn'])
}
}

Expand Down Expand Up @@ -198,13 +204,13 @@ it('should use pnpm as the package manager on supplying --use-pnpm', async () =>

it('should use pnpm as the package manager on supplying --use-pnpm with example', async () => {
try {
await execa('pnpm', ['--version'])
await command('pnpm', ['--version'])
} catch (_) {
// install pnpm if not available
try {
await execa('corepack', ['prepare', '--activate', 'pnpm@latest'])
await command('corepack', ['prepare', '--activate', 'pnpm@latest'])
} catch (_) {
await execa('npm', ['i', '-g', 'pnpm'])
await command('npm', ['i', '-g', 'pnpm'])
}
}

Expand Down Expand Up @@ -276,10 +282,10 @@ it('should use Bun as the package manager on supplying --use-bun', async () => {

it('should use Bun as the package manager on supplying --use-bun with example', async () => {
try {
await execa('bun', ['--version'])
await command('bun', ['--version'])
} catch (_) {
// install Bun if not available
await execa('npm', ['i', '-g', 'bun'])
await command('npm', ['i', '-g', 'bun'])
}

await useTempDir(async (cwd) => {
Expand Down Expand Up @@ -375,13 +381,13 @@ it('should infer npm as the package manager with example', async () => {

it('should infer yarn as the package manager', async () => {
try {
await execa('yarn', ['--version'])
await command('yarn', ['--version'])
} catch (_) {
// install yarn if not available
try {
await execa('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
await command('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
} catch (_) {
await execa('npm', ['i', '-g', 'yarn'])
await command('npm', ['i', '-g', 'yarn'])
}
}

Expand Down Expand Up @@ -419,13 +425,13 @@ it('should infer yarn as the package manager', async () => {

it('should infer yarn as the package manager with example', async () => {
try {
await execa('yarn', ['--version'])
await command('yarn', ['--version'])
} catch (_) {
// install yarn if not available
try {
await execa('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
await command('corepack', ['prepare', '--activate', 'yarn@1.22.19'])
} catch (_) {
await execa('npm', ['i', '-g', 'yarn'])
await command('npm', ['i', '-g', 'yarn'])
}
}

Expand Down Expand Up @@ -458,13 +464,13 @@ it('should infer yarn as the package manager with example', async () => {

it('should infer pnpm as the package manager', async () => {
try {
await execa('pnpm', ['--version'])
await command('pnpm', ['--version'])
} catch (_) {
// install pnpm if not available
try {
await execa('corepack', ['prepare', '--activate', 'pnpm@latest'])
await command('corepack', ['prepare', '--activate', 'pnpm@latest'])
} catch (_) {
await execa('npm', ['i', '-g', 'pnpm'])
await command('npm', ['i', '-g', 'pnpm'])
}
}

Expand Down Expand Up @@ -502,13 +508,13 @@ it('should infer pnpm as the package manager', async () => {

it('should infer pnpm as the package manager with example', async () => {
try {
await execa('pnpm', ['--version'])
await command('pnpm', ['--version'])
} catch (_) {
// install pnpm if not available
try {
await execa('corepack', ['prepare', '--activate', 'pnpm@latest'])
await command('corepack', ['prepare', '--activate', 'pnpm@latest'])
} catch (_) {
await execa('npm', ['i', '-g', 'pnpm'])
await command('npm', ['i', '-g', 'pnpm'])
}
}

Expand Down Expand Up @@ -541,10 +547,10 @@ it('should infer pnpm as the package manager with example', async () => {

it('should infer Bun as the package manager', async () => {
try {
await execa('bun', ['--version'])
await command('bun', ['--version'])
} catch (_) {
// install Bun if not available
await execa('npm', ['i', '-g', 'bun'])
await command('npm', ['i', '-g', 'bun'])
}

await useTempDir(async (cwd) => {
Expand Down Expand Up @@ -581,10 +587,10 @@ it('should infer Bun as the package manager', async () => {

it('should infer Bun as the package manager with example', async () => {
try {
await execa('bun', ['--version'])
await command('bun', ['--version'])
} catch (_) {
// install Bun if not available
await execa('npm', ['i', '-g', 'bun'])
await command('npm', ['i', '-g', 'bun'])
}

await useTempDir(async (cwd) => {
Expand Down

0 comments on commit 92cccfb

Please sign in to comment.