Skip to content

refactor and test (squashed)#3

Closed
james-tindal wants to merge 1 commit intomainfrom
refactor-and-test-squashed
Closed

refactor and test (squashed)#3
james-tindal wants to merge 1 commit intomainfrom
refactor-and-test-squashed

Conversation

@james-tindal
Copy link
Owner

@james-tindal james-tindal commented Feb 11, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added image localization support to download and embed remote images from EPUBs
    • Implemented EPUB merging functionality to combine chapters into a single markdown file
  • Improvements

    • Enhanced EPUB parsing with improved structure and metadata handling
    • Expanded CLI capabilities with better file processing and error handling
  • Dependencies

    • Updated build and testing dependencies; switched testing framework to Vitest

- Reorganise code for improved comprehension
- Separate IO from logic to allow fast testing
- Switch from jest to vitest
- Move fixtures folder inside tests folder
- Add integration tests with snapshot testing
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request refactors the EPUB parsing architecture by modularizing the monolithic src/parseEpub.ts into a new src/epub/ directory with separate parsing, options, and zip handling modules, introduces XML parsing utilities for OPF/NCX/metadata processing, migrates tests from Jest to Vitest, and reorganizes fixtures from fixtures/ to test/fixtures/.

Changes

Cohort / File(s) Summary
EPUB Parsing Modularization
src/parseEpub.ts, src/epub/parseEpub.ts, src/epub/options.ts, src/epub/zip.ts
Removes old monolithic EPUB parser and introduces new modular structure: Epub class with parse() function in parseEpub.ts, configurable ParserOptions in options.ts, and Zip class for zip content handling in zip.ts. Relocates parsing logic to separate concerns.
XML Parsing Infrastructure
src/xml/index.ts, src/xml/opf.ts, src/xml/toc.ts, src/xml/meta-container.ts, src/xml/parseXml.ts
Introduces new XML parsing modules: parseStructure() orchestrator, Opf type with Manifest class for manifest/metadata/spine handling, Toc/TocItem classes for table of contents, parseMetaContainer() for container.xml, and parseXml() utility for XML parsing.
Converter Module Restructure
src/bin/convert.ts, src/convert/convert.ts, src/convert/download-images.ts, src/convert/helper.ts
Removes bin-level Converter class and introduces new src/convert/ module with refactored Converter class supporting merge/localize modes, new downloadRemoteImages() function, and updated sanitizeFileName() helper. Exports new types: RunOptions, FileData, MergeProgress.
CLI Refactor
src/bin/cli.ts
Replaces direct Converter instantiation with new convert() helper function, adds handleFiles() and handleMergedFile() for output processing, refactors input variable naming (pathArg, epubPaths), wraps commands in try/catch blocks, and updates logging to use new converter patterns.
Module Reorganization
src/index.ts, src/utils.ts, src/types.ts, src/parseSection.ts, src/parseHTML.ts, src/converter.ts, src/logger.ts
Updates import paths for parseEpub, removes XML/TOC utilities from utils.ts replacing with Path() function, removes convertFuncType and ParserOptions exports from types.ts, refactors parseSection.ts to use dependency-injected getFile/getItemId, inlines traverseNestedObject utility in parseHTML.ts, applies formatting to logger.ts.
Build & Configuration Updates
build.config.ts, .gitignore, .npmignore, jest.config.ts, examples/simple/main.js
Updates build config to remove bin-specific entry, broadens TS pattern matching with **/*.ts, simplifies post-build cleanup. Updates ignore paths from fixtures/ to test/fixtures/. Removes jest.config.ts content. Updates example to reference test fixtures.
Test Framework Migration
package.json, test/bin.spec.ts, test/convert.spec.ts, test/integration.spec.ts, test/localize.spec.ts, test/parseEpub.spec.ts, test/mergeMarkdowns.spec.ts, test/utilities/*
Replaces Jest with Vitest in package.json, adds test dependencies (folder-hash, nock, vitest), updates test scripts. Refactors tests to use Vitest, implements fixture-driven test discovery, adds integration and unit test suites with snapshot testing, introduces mock network utility and temp directory setup.
Test Snapshots & Fixtures
test/snapshots/, fixtures/file-e.epub
Adds comprehensive snapshot files for integration tests (convert, merge, unzip, autocorrect modes) and unit tests (parseEpub), and unit-level convert snapshots. Minor content updates to fixture file.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Poem

🐰 Whiskers twitch with joy at structured change,
Modules split across the range,
Parsing paths now neat and clean,
Best refactor ever seen!
Tests now swift with Vitest cheer,
Hoppy hops—the code's so clear! 🌿✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-and-test-squashed

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant