The task
src/utils/codeblock-utils.ts has seven exported functions and no test file. Add one.
Why this is a good first issue
Every function in it is pure: same input, same output, no DOM, no network, no Supabase. You can
run it in isolation and reason about it entirely from the file. Verified — the module contains
zero references to document, window, fetch, localStorage or a database client.
The functions
| function |
signature |
generateBlockId |
(content: string) => string |
countLines |
(text: string) => number |
extractLanguage |
(className: string) => string | null |
formatLineNumber |
(num: number, totalLines: number) => string |
stripLineNumbers |
(content: string) => string |
getLanguageDisplayName |
(language: string) => string |
detectLanguage |
(content: string) => string |
Where the test goes
src/utils/codeblock-utils.test.ts, beside the source. Look at any existing *.test.ts for the
house style — Vitest, describe / it / expect.
Acceptance criteria
The one thing that matters here
Before you open the PR, break the function on purpose and check your test goes red. Change a
+ 1 to a - 1, return an empty string, whatever. Then undo it.
A test that passes but would also pass against broken code is worse than no test, because it
tells the next person the function is covered. This repo has a whole catalogue of those (#396),
and a gate that could not fail is the single most common defect we've found in it. Say in your
PR which mutation you tried — that's the most valuable line in the description.
Getting set up
Docker-first, always — never npm install or pnpm install on your host machine:
docker compose up -d
docker compose exec scripthammer pnpm test --run src/utils/codeblock-utils.test.ts
The task
src/utils/codeblock-utils.tshas seven exported functions and no test file. Add one.Why this is a good first issue
Every function in it is pure: same input, same output, no DOM, no network, no Supabase. You can
run it in isolation and reason about it entirely from the file. Verified — the module contains
zero references to
document,window,fetch,localStorageor a database client.The functions
generateBlockId(content: string) => stringcountLines(text: string) => numberextractLanguage(className: string) => string | nullformatLineNumber(num: number, totalLines: number) => stringstripLineNumbers(content: string) => stringgetLanguageDisplayName(language: string) => stringdetectLanguage(content: string) => stringWhere the test goes
src/utils/codeblock-utils.test.ts, beside the source. Look at any existing*.test.tsfor thehouse style — Vitest,
describe/it/expect.Acceptance criteria
src/utils/codeblock-utils.test.tsstring, a
classNamewith no language in it,formatLineNumber(9, 100)where paddingmatters, content that has no line numbers to strip
docker compose exec scripthammer pnpm test --run src/utils/codeblock-utils.test.tspassesThe one thing that matters here
Before you open the PR, break the function on purpose and check your test goes red. Change a
+ 1to a- 1, return an empty string, whatever. Then undo it.A test that passes but would also pass against broken code is worse than no test, because it
tells the next person the function is covered. This repo has a whole catalogue of those (#396),
and a gate that could not fail is the single most common defect we've found in it. Say in your
PR which mutation you tried — that's the most valuable line in the description.
Getting set up
Docker-first, always — never
npm installorpnpm installon your host machine: