prepare-chapter.test.js 794 B

123456789101112131415161718192021222324252627
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { promises as fs } from 'node:fs'
  4. import path from 'node:path'
  5. import { run } from '../../src/commands/prepare-chapter.js'
  6. import { tempBookCtx } from './_helper.js'
  7. test('prepare-chapter 写出本章写作材料', async () => {
  8. const { ctx, cleanup } = await tempBookCtx()
  9. try {
  10. const r = await run(['3'], {}, ctx)
  11. assert.equal(r.ok, true)
  12. await fs.access(path.join(ctx.repoPath, '工作区', '本章写作材料.md'))
  13. } finally {
  14. await cleanup()
  15. }
  16. })
  17. test('prepare-chapter 非数字章号 → ok=false', async () => {
  18. const { ctx, cleanup } = await tempBookCtx()
  19. try {
  20. const r = await run(['abc'], {}, ctx)
  21. assert.equal(r.ok, false)
  22. } finally {
  23. await cleanup()
  24. }
  25. })