prepare.test.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { prepareChapterMaterials } from '../../src/prep/index.js'
  4. import { tempBookCtx } from '../commands/_helper.js'
  5. import { read } from '../storage/_tmprepo.js'
  6. test('prepareChapterMaterials 组装本章写作材料(八组件锚点)并写出', async () => {
  7. const { ctx, cleanup } = await tempBookCtx()
  8. try {
  9. const r = await prepareChapterMaterials(ctx, { chapterNum: 3 })
  10. assert.equal(r.ok, true)
  11. const c = r.content
  12. assert.match(c, /全书近况/)
  13. assert.match(c, /第\s*1\s*卷/)
  14. assert.match(c, /本章要写到的事/)
  15. assert.match(c, /查到玉佩/) // 来自细纲
  16. assert.match(c, /信息差边界/)
  17. assert.match(c, /信息差-001/) // 未揭晓信息差,勿泄
  18. assert.match(c, /文风锚点/)
  19. assert.match(c, /节奏/) // 来自文风铁律
  20. assert.match(c, /反和解/)
  21. assert.match(c, /反派恶意/) // 来自文风铁律反和解段
  22. const onDisk = await read(ctx.repoPath, '工作区/本章写作材料.md')
  23. assert.match(onDisk, /第 3 章写作材料/)
  24. } finally {
  25. await cleanup()
  26. }
  27. })