Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add unit tests for lib/format.ts

Aperta Adatta ai principianti
#12 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
testing

Direzione di ricerca

Inizia da src/renderer/src/lib/format.ts, che non ha dipendenze, e leggi le funzioni esportate formatCount, formatBytes, relativeTime, hostOf, fileName e fileExtension. Poi guarda vitest.config.ts e tsconfig.node.json per aggiungere l'alias @renderer e le voci path e include. Il lavoro è completato quando pnpm typecheck e pnpm test passano con un nuovo tests/format.test.ts e format.ts è invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
0
Fork
3
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di alexsilver8/openpaste

Tutte le issue di alexsilver8/openpaste

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.