Refactor build-docs.test.ts: extract shared glob/scan/convert helper to reduce duplication #38

Closed
opened 2026-03-05 20:25:18 +00:00 by coderabbitai[bot] · 1 comment
coderabbitai[bot] commented 2026-03-05 20:25:18 +00:00 (Migrated from github.com)

Summary

The glob/scan/convert logic is currently copy-pasted verbatim across all 14 test cases in packages/katana-planner-gui/scripts/build-docs.test.ts. This should be extracted into a shared helper function to reduce duplication and ensure tests exercise the real build-docs.ts module rather than a re-implemented copy.

Proposed refactor

Extract a buildDocs helper at the top of the test file:

async function buildDocs(docsDir: string): Promise<Record<string, string>> {
  const { Glob } = await import("bun");
  const glob = new Glob("*.md");
  const entries: Record<string, string> = {};
  for await (const file of glob.scan(docsDir)) {
    const content = await Bun.file(resolve(docsDir, file)).text();
    entries[file.replace(/\.md$/, "")] = Bun.markdown.html(content);
  }
  return entries;
}

Each test then becomes a single writeFileSync + await buildDocs(docsDir) + assertion, with no repeated boilerplate.

Context

This was flagged during review of #37 (comment: https://github.com/chris-kreidl/katana/pull/37). The refactor was deferred because build-docs.ts does not exist on that branch yet — it should be addressed in a follow-up once everything from #37 is merged.

Requested by @chris-kreidl.

## Summary The glob/scan/convert logic is currently copy-pasted verbatim across all 14 test cases in `packages/katana-planner-gui/scripts/build-docs.test.ts`. This should be extracted into a shared helper function to reduce duplication and ensure tests exercise the real `build-docs.ts` module rather than a re-implemented copy. ## Proposed refactor Extract a `buildDocs` helper at the top of the test file: ```ts async function buildDocs(docsDir: string): Promise<Record<string, string>> { const { Glob } = await import("bun"); const glob = new Glob("*.md"); const entries: Record<string, string> = {}; for await (const file of glob.scan(docsDir)) { const content = await Bun.file(resolve(docsDir, file)).text(); entries[file.replace(/\.md$/, "")] = Bun.markdown.html(content); } return entries; } ``` Each test then becomes a single `writeFileSync` + `await buildDocs(docsDir)` + assertion, with no repeated boilerplate. ## Context This was flagged during review of #37 (comment: https://github.com/chris-kreidl/katana/pull/37). The refactor was deferred because `build-docs.ts` does not exist on that branch yet — it should be addressed in a follow-up once everything from #37 is merged. Requested by @chris-kreidl.
coderabbitai[bot] commented 2026-03-05 20:41:03 +00:00 (Migrated from github.com)

Closing as resolved — the build-docs.test.ts refactor was completed in #37 after rebasing onto docs. The tests now import and call the real buildDocs module, so no further work is needed.

Closing as resolved — the `build-docs.test.ts` refactor was completed in #37 after rebasing onto `docs`. The tests now import and call the real `buildDocs` module, so no further work is needed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/katana#38
No description provided.