Skip to content

[P0] Stabilize the Vitest environment for pdfjs/react-pdf #8

Open

Description

@nkanf-dev

Summary

Fix the unit/UI test environment so pdfjs-dist and react-pdf dependencies do not crash the suite in jsdom.

Why

The current test environment fails with DOMMatrix is not defined, preventing the suite from validating actual logic changes.

Current evidence

  • npm run test:unit and UI tests fail before assertions run.
  • src/services/PDFService.ts and src/components/reader/ReaderViewport.tsx import PDF dependencies directly in test contexts.

Scope

  • Add the required polyfills or targeted mocks for DOMMatrix and related PDF primitives.
  • Isolate rendering-heavy dependencies so store/service tests do not load browser-only code unnecessarily.
  • Document the chosen strategy in test setup.
  • Keep the fix minimal and maintainable.

Acceptance criteria

  • Unit and UI test suites start reliably in jsdom.
  • PDF-related modules no longer crash test initialization.
  • The setup is documented and reproducible on CI.

Out of scope

  • Replacing react-pdf or pdfjs-dist entirely.

Activity

  1. rjiangDoFashion commented on Oct 4, 2026

    @rjiangDoFashion

    状态核查(2026-10-04):

    • 已验证(默认分支 main):vitest.config.ts 明确使用 environment: 'jsdom' 并加载 src/tests/setup.ts;setup 中有带注释的 DOMMatrix mock,以及 jsdom 的 URL.createObjectURL/revokeObjectURL 兜底。测试文件还对 react-pdf/ pdfjs-dist 做了边界 mock/隔离(例如 PDFService、ThumbnailService 与 Reader UI 测试)。
    • CI 可复现性:.github/workflows/quality.yml 在 Node 22 执行 npm ci、npm run test:unit、npm run test:ui;main 当前提交 fb8356d 对应的 Product quality run #178(Actions run 37185313360)中 checks 成功,日志显示 UI 为 19 个文件/370 tests 通过;同一 job 的 unit 步骤也成功。此前 PR Fix CJK thumbnail glyphs and long library filenames #47 的 run 37172178676 也成功完成 unit/UI 步骤。
    • 与本 Issue 无关的证据:PR Fix CJK thumbnail glyphs and long library filenames #47 主要是 CJK 字体、长文件名与浏览器 gate;其描述明确把浏览器执行留给 normal PR gate。PR feat: add named held pages with conflict-safe saving #48 主要是 held-page 编辑/冲突保存;其大量 unit/UI/浏览器结果及部署成功不能单独证明本 Issue 的 jsdom 配置、DOMMatrix mock 或专门验收。

    结论:实现、隔离策略和 CI 中 unit/UI 的成功运行已有直接证据,且与 Issue #8 的三项验收相符;但现有记录没有一条专门标注为 Issue #8 的验收运行或单独的 DOMMatrix 回归测试,故保留该 Issue open,待补充专门的 jsdom/DOMMatrix 验收证据后再关闭。

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions