Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Add unit tests for lib/format.ts

Open Beginner friendly
#12 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
testing

Research direction

Start with src/renderer/src/lib/format.ts, which has no dependencies, and read the exported formatCount, formatBytes, relativeTime, hostOf, fileName and fileExtension. Then look at vitest.config.ts and tsconfig.node.json to add the @renderer alias and the path and include entries. Done means pnpm typecheck and pnpm test pass with a new tests/format.test.ts, and format.ts is unchanged.

Written by the indexing model from the issue text.

Description

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

Dominant language
TypeScript
Stars
0
Forks
3
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from alexsilver8/openpaste

All issues in alexsilver8/openpaste

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.