read-secret.test.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/read-secret.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-secret --基本信息 返回 JSON(含读者知道/关键词)', async () => {
  13. const r = await run(['信息差-001'], { 基本信息: true }, ctx)
  14. assert.equal(r.ok, true)
  15. const data = JSON.parse(r.output)
  16. assert.equal(data.读者知道, false)
  17. assert.ok(Array.isArray(data.关键词))
  18. })
  19. test('read-secret --内容 返回内容段落', async () => {
  20. const r = await run(['信息差-001'], { 内容: true }, ctx)
  21. assert.equal(r.ok, true)
  22. assert.ok(r.output.includes('封印邪灵'))
  23. })
  24. test('read-secret 不存在 → ok=false', async () => {
  25. const r = await run(['信息差-999'], { 基本信息: true }, ctx)
  26. assert.equal(r.ok, false)
  27. assert.match(r.error, /不存在/)
  28. })