umd.test.ts 1.1 KB

123456789101112131415161718192021222324
  1. import { readFileSync } from 'node:fs'
  2. import { join } from 'node:path'
  3. import { describe, expect, it } from 'vitest'
  4. import { parseUmdBook } from './helpers/umdParser'
  5. function loadFixture(name: string): ArrayBuffer {
  6. const buffer = readFileSync(join(__dirname, '..', 'apps', 'viewer-demo', 'public', 'example', name))
  7. return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)
  8. }
  9. describe('umd ebook parser', () => {
  10. it('parses metadata, chapter titles and zlib text segments', () => {
  11. const book = parseUmdBook(loadFixture('book.umd'))
  12. expect(book.kind).toBe('text')
  13. expect(book.title).toBe('Flyfish UMD 电子书样本')
  14. expect(book.author).toBe('Flyfish Viewer')
  15. expect(book.chapters).toHaveLength(2)
  16. expect(book.chapters[0].title).toBe('第一章 旧格式醒来')
  17. expect(book.chapters[0].content).toContain('UMD 是早期移动阅读器常见的电子书封装格式')
  18. expect(book.chapters[1].content).toContain('预览器会把章节偏移还原成目录')
  19. expect(book.warnings).toEqual([])
  20. })
  21. })