read-character.test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/read-character.js'
  4. import { fixtureCtx } from './_helper.js'
  5. let ctx, cleanup
  6. before(async () => {
  7. ;({ ctx, cleanup } = await fixtureCtx())
  8. })
  9. after(async () => {
  10. await cleanup()
  11. })
  12. test('read-character --front-matter 返回 JSON 含姓名', async () => {
  13. const r = await run(['林晚'], { 'front-matter': true }, ctx)
  14. assert.equal(r.ok, true)
  15. const data = JSON.parse(r.output)
  16. assert.equal(data.姓名, '林晚')
  17. })
  18. test('read-character 默认返回完整(frontMatter + body)', async () => {
  19. const r = await run(['林晚'], {}, ctx)
  20. assert.equal(r.ok, true)
  21. const data = JSON.parse(r.output)
  22. assert.ok(data.frontMatter)
  23. assert.ok(data.body.includes('设定'))
  24. })
  25. test('read-character 缺正名 → ok=false', async () => {
  26. const r = await run([], {}, ctx)
  27. assert.equal(r.ok, false)
  28. })
  29. test('read-character 不存在的角色 → ok=false 且不崩', async () => {
  30. const r = await run(['查无此人'], { 'front-matter': true }, ctx)
  31. assert.equal(r.ok, false)
  32. assert.match(r.error, /不存在/)
  33. })