BookConfigReader.test.js 890 B

12345678910111213141516171819202122
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import path from 'node:path'
  4. import os from 'node:os'
  5. import { fileURLToPath } from 'node:url'
  6. import { BookConfigReader } from '../../../src/storage/adapters/BookConfigReader.js'
  7. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  8. const fixtureRoot = path.join(__dirname, '../../fixtures/sample-book')
  9. test('BookConfigReader 读 book.yaml 平铺字段', async () => {
  10. const r = await new BookConfigReader(fixtureRoot).read()
  11. assert.equal(r.ok, true)
  12. assert.equal(r.data.书名, '测试书')
  13. assert.equal(r.data.每章目标字数, 3000)
  14. assert.equal(r.data.伏笔悬了太久章数, 10)
  15. })
  16. test('BookConfigReader 缺 book.yaml → ok=false(不崩)', async () => {
  17. const r = await new BookConfigReader(path.join(os.tmpdir(), 'wnw-nonexistent-xyz')).read()
  18. assert.equal(r.ok, false)
  19. })