Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Add unit tests for lib/format.ts

Đang mở Phù hợp với người mới
#12 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu từ src/renderer/src/lib/format.ts, file này không có phụ thuộc, và đọc các hàm được export formatCount, formatBytes, relativeTime, hostOf, fileName và fileExtension. Sau đó xem vitest.config.ts và tsconfig.node.json để thêm alias @renderer cùng các mục path và include. Hoàn thành khi pnpm typecheck và pnpm test đều chạy đạt với một tests/format.test.ts mới và format.ts không bị thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

good first issue tests

src/renderer/src/lib/format.ts formats sizes, counts, times, link hosts and file names for the shelf. It has no dependencies, so it's easy to test on its own, but so far only hostOf has tests: two cases in tests/format.test.ts, added with the fix for #13.

The setup is already done. Tests import the file the way the app does, as @renderer/lib/format, and pnpm typecheck covers it.

What to do

Add to tests/format.test.ts:

  • formatCount: 1 file, 2 files, a custom plural, a number with a thousands separator
  • formatBytes: plain bytes, the KB → MB → GB steps, and one decimal under 10 (1.5 KB but 12 KB). Leave out sizes just under the next unit, like 1048575 bytes: they round to 1024 KB, and #29 fixes that
  • relativeTime: pass a fixed now so the result doesn't depend on the clock. "Just now", "min ago", "h ago" and "Yesterday" are plain strings. Weekday and date output depend on the machine's locale, so compare those against toLocaleDateString with the same options instead of hard-coding "Tuesday"
  • hostOf: a normal link, www. stripped, a mailto: link, and text that isn't a URL, next to the two % cases already there
  • fileName and fileExtension: macOS and Windows paths, a dotfile (.env has no extension), an upper-case extension
Done when
  • pnpm typecheck and pnpm test pass
  • format.ts itself is unchanged. If a test turns up another bug, say so in the pull request rather than fixing it in the same one

Suggested pull request title: test: cover the shelf's format helpers

New to OpenPaste? CONTRIBUTING.md covers setup, the code conventions and the checks to run before a pull request (pnpm typecheck, pnpm test, pnpm format, pnpm cleaner). Leave a comment if you're picking this up so nobody doubles up.


Generated by Claude Code

Ngôn ngữ chính
TypeScript
Star
0
Fork
3
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của alexsilver8/openpaste

Tất cả issue của alexsilver8/openpaste

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.