diff --git a/knip.json b/knip.json index 7fa3dd15f..f9f3ab9d2 100644 --- a/knip.json +++ b/knip.json @@ -1,11 +1,6 @@ { "$schema": "https://unpkg.com/knip@5/schema.json", "workspaces": { - ".": { - "ignoreDependencies": [ - "pkg-pr-new" - ] - }, "playground": { "ignoreDependencies": [ "nuxi", diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index ce936e1c5..9af8adf10 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -1,9 +1,13 @@ import type { TestFunction } from 'vitest' import type { commands } from '../../src/commands' +import { existsSync } from 'node:fs' + +import { readdir, rm } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { isWindows } from 'std-env' - import { x } from 'tinyexec' import { describe, expect, it } from 'vitest' @@ -12,7 +16,15 @@ const fixtureDir = fileURLToPath(new URL('../../playground', import.meta.url)) describe('commands', () => { const tests: Record> = { _dev: 'todo', - add: 'todo', + add: async () => { + const file = join(fixtureDir, 'server/api/test.ts') + await rm(file, { force: true }) + await x('nuxi', ['add', 'api', 'test'], { + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, + }) + expect(existsSync(file)).toBeTruthy() + await rm(file, { force: true }) + }, analyze: 'todo', build: 'todo', cleanup: 'todo', @@ -26,12 +38,28 @@ describe('commands', () => { upgrade: 'todo', dev: 'todo', generate: 'todo', - init: 'todo', + init: async () => { + const dir = tmpdir() + for (const pm of ['pnpm']) { + const installPath = join(dir, pm) + await rm(installPath, { recursive: true, force: true }) + try { + await x('nuxi', ['init', installPath, `--packageManager=${pm}`, '--gitInit=false', '--preferOffline'], { + nodeOptions: { stdio: 'inherit', cwd: fixtureDir }, + }) + const files = await readdir(installPath).catch(() => []) + expect(files).toContain('nuxt.config.ts') + } + finally { + await rm(installPath, { recursive: true, force: true }) + } + } + }, info: 'todo', } it('throws error if no command is provided', async () => { - const res = await x('pnpm', ['nuxi'], { + const res = await x('nuxi', [], { nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1) @@ -40,7 +68,7 @@ describe('commands', () => { // TODO: FIXME - windows currently throws 'nuxt-foo' is not recognized as an internal or external command, operable program or batch file. it.skipIf(isWindows)('throws error if wrong command is provided', async () => { - const res = await x('pnpm', ['nuxi', 'foo'], { + const res = await x('nuxi', ['foo'], { nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) expect(res.exitCode).toBe(1) @@ -48,7 +76,7 @@ describe('commands', () => { }) const testsToRun = Object.entries(tests).filter(([_, value]) => value !== 'todo') - it.each(testsToRun)(`%s`, (_, test) => (test as () => Promise)()) + it.each(testsToRun)(`%s`, (_, test) => (test as () => Promise)(), { timeout: isWindows ? 100000 : 50000 }) for (const [command, value] of Object.entries(tests)) { if (value === 'todo') {