SecretWriter.test.js 957 B

123456789101112131415161718192021
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { SecretWriter } from '../../../src/storage/adapters/SecretWriter.js'
  4. import { makeRepo, cleanup, read } from '../_tmprepo.js'
  5. test('SecretWriter.write 写信息差(防呆 front matter + 内容)', async () => {
  6. const root = await makeRepo()
  7. try {
  8. const w = new SecretWriter(root)
  9. const fm = { 强度: '高', 谁知道: ['林晚'], 读者知道: false, 登记章: 152, 关键词: ['血书'] }
  10. const r = await w.write('信息差-021-血书真相', fm, '## 内容\n血书写着真凶名讳。')
  11. assert.equal(r.ok, true)
  12. const content = await read(root, '定稿/设定/信息差/信息差-021-血书真相.md')
  13. assert.match(content, /读者知道: false/)
  14. assert.match(content, /关键词:\n {2}- 血书/)
  15. assert.match(content, /## 内容/)
  16. assert.match(content, /血书写着真凶名讳/)
  17. } finally {
  18. await cleanup(root)
  19. }
  20. })