Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions knip.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"workspaces": {
".": {
"ignoreDependencies": [
"pkg-pr-new"
]
},
"playground": {
"ignoreDependencies": [
"nuxi",
Expand Down
40 changes: 34 additions & 6 deletions test/e2e/commands.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -12,7 +16,15 @@ const fixtureDir = fileURLToPath(new URL('../../playground', import.meta.url))
describe('commands', () => {
const tests: Record<keyof typeof commands, 'todo' | TestFunction<object>> = {
_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',
Expand All @@ -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)
Expand All @@ -40,15 +68,15 @@ 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)
expect(res.stderr).toBe('[error] Unknown command `foo`\n')
})

const testsToRun = Object.entries(tests).filter(([_, value]) => value !== 'todo')
it.each(testsToRun)(`%s`, (_, test) => (test as () => Promise<void>)())
it.each(testsToRun)(`%s`, (_, test) => (test as () => Promise<void>)(), { timeout: isWindows ? 100000 : 50000 })

for (const [command, value] of Object.entries(tests)) {
if (value === 'todo') {
Expand Down
Loading