加入命令冒烟测试

This commit is contained in:
dsh committed 2026-11-17 12:10:05 +08:00
1 parent 0eaf052051
commit c7a76fa856
2 files changed
+33

No files matched your search

+6
View File
@@ -79,6 +79,12 @@ github-sync/
同一个作者的手机原生插件(`local-github-upload`,带输入框上方胶囊和面板)和本插件**共用**同一份配置和令牌,两边可以混用。
## 测试
```bash
node test/command.mjs # 命令注册与 status/用法检查
```
## 许可
MIT
+27
View File
@@ -0,0 +1,27 @@
// 命令冒烟测试:注册 /github,并检查 status / 空输入 / 非法子命令的返回。
import { mkdtempSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'gs-home-'))
const { apply } = await import('../index.js')
let def
const ctx = { commands: { register: (d) => { def = d; return () => {} } }, get: () => undefined }
apply(ctx)
const inv = { agent: { session: { header: { cwd: process.cwd() } } }, rawInput: 'status' }
const cases = [
['注册', def?.name === 'github', `命令名 ${def?.name}`],
['status', (await def.handler(inv)).text.includes('令牌'), ''],
['空输入(无令牌应报令牌提示)', (await def.handler({ ...inv, rawInput: '' })).text.includes('令牌'), ''],
['非法子命令回用法', (await def.handler({ ...inv, rawInput: 'nonsense' })).text.includes('用法'), ''],
]
let bad = 0
for (const [name, pass, detail] of cases) {
console.log(`${pass ? '✓' : '✗'} ${name}${detail ? ` — ${detail}` : ''}`)
if (!pass) bad += 1
}
process.exitCode = bad === 0 ? 0 : 1