73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
/**
|
|
* portal.test.ts — portal 父命令烟囱测试
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { execFileSync } from 'node:child_process'
|
|
import { resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
const CLI = resolve(__dirname, '../../src/cli.ts')
|
|
|
|
function run(args: string[]): string {
|
|
try {
|
|
return execFileSync('npx', ['tsx', CLI, ...args], {
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
timeout: 30_000,
|
|
})
|
|
} catch (e) {
|
|
const err = e as { stdout?: Buffer | string; status?: number }
|
|
return (err.stdout?.toString() || '')
|
|
}
|
|
}
|
|
|
|
describe('portal command tree (W8-D3)', () => {
|
|
it('portal --help 列出 4 个子命令', () => {
|
|
const out = run(['portal', '--help'])
|
|
expect(out).toContain('list')
|
|
expect(out).toContain('info')
|
|
expect(out).toContain('create')
|
|
expect(out).toContain('release')
|
|
})
|
|
|
|
it('portal list --help 描述正确', () => {
|
|
const out = run(['portal', 'list', '--help'])
|
|
expect(out).toContain('门户')
|
|
})
|
|
|
|
it('portal list --ai-help 含 API 路径', () => {
|
|
const out = run(['portal', 'list', '--ai-help'])
|
|
expect(out).toContain('/api/visualdev/Portal')
|
|
expect(out).toContain('web 源码')
|
|
})
|
|
|
|
it('portal create --ai-help 提示决策 6', () => {
|
|
const out = run(['portal', 'create', '--ai-help'])
|
|
expect(out).toContain('决策 6')
|
|
expect(out).toContain('/api/visualdev/Portal')
|
|
})
|
|
|
|
it('portal info --help 包含 --id', () => {
|
|
const out = run(['portal', 'info', '--help'])
|
|
expect(out).toContain('--id')
|
|
})
|
|
|
|
it('portal create --help 包含 required 字段', () => {
|
|
const out = run(['portal', 'create', '--help'])
|
|
expect(out).toContain('--fullName')
|
|
expect(out).toContain('--enCode')
|
|
expect(out).toContain('--category')
|
|
})
|
|
|
|
it('portal release --help 包含 --id', () => {
|
|
const out = run(['portal', 'release', '--help'])
|
|
expect(out).toContain('--id')
|
|
})
|
|
|
|
it('顶层 --help 包含 portal', () => {
|
|
const out = run(['--help'])
|
|
expect(out).toContain('portal')
|
|
})
|
|
})
|