From c7a76fa8564dbd996afc558a8318e0ca13ed970b Mon Sep 17 00:00:00 2001 From: dsh Date: Tue, 17 Nov 2026 12:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=91=BD=E4=BB=A4=E5=86=92?= =?UTF-8?q?=E7=83=9F=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ test/command.mjs | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/command.mjs diff --git a/README.md b/README.md index 0ad9c7b..ae0ed54 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,12 @@ github-sync/ 同一个作者的手机原生插件(`local-github-upload`,带输入框上方胶囊和面板)和本插件**共用**同一份配置和令牌,两边可以混用。 +## 测试 + +```bash +node test/command.mjs # 命令注册与 status/用法检查 +``` + ## 许可 MIT diff --git a/test/command.mjs b/test/command.mjs new file mode 100644 index 0000000..00a673a --- /dev/null +++ b/test/command.mjs @@ -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