refactor(test): DRY shared setup + selective arrange/act/assert #23

Merged
fiatcode merged 2 commits from refactor/tests-cleanup into main 2026-06-18 10:38:51 +07:00
Owner

Pure test refactor across all packages — no production code changed, no test behavior changed. Same scenarios, same assertions, identical pass counts before/after in every package.

What changed

  • DRY — extracted repeated setup into package-local test helpers (each t.Helper()):
    • views: quietTerm (collapses ~154 TERM/NO_COLOR setenv pairs) + writeGraph (the tempdir → pages/ → write .mdBuildIndex dance); existing bootApp/bootAppAt now route env setup through quietTerm instead of duplicating it.
    • graph: fixturePath / buildFixtureIndex / buildTempIndex / mapReader / linkifyOK.
    • sync: cloneSibling; reused existing writeFile.
    • search: fixtureGraph / writePage; reused the rg-missing skip guard.
    • render: mustRender / mustRenderEmphasis / plainText / rowOf.
  • Selective arrange/act/assert — added // arrange, // act, // assert sections to imperative single-scenario tests; left table-driven (cases := []struct{…} loop) tests as clean loops. cmd/weft was already a clean table test and is untouched.

Verification

  • go build ./..., go vet ./... — clean
  • gofmt -l — clean on all test files
  • go test -count=1 ./... — all green
  • Pass counts unchanged per package: views 261, graph 31, render 24, sync 9, search 5, cmd 10.

Two new shared helpers_test.go files (internal/views, internal/graph). Follows the internal/edit/editor_test.go style established in #22.

Pure test refactor across all packages — **no production code changed, no test behavior changed**. Same scenarios, same assertions, identical pass counts before/after in every package. ## What changed - **DRY** — extracted repeated setup into package-local test helpers (each `t.Helper()`): - `views`: `quietTerm` (collapses ~154 `TERM`/`NO_COLOR` setenv pairs) + `writeGraph` (the tempdir → `pages/` → write `.md` → `BuildIndex` dance); existing `bootApp`/`bootAppAt` now route env setup through `quietTerm` instead of duplicating it. - `graph`: `fixturePath` / `buildFixtureIndex` / `buildTempIndex` / `mapReader` / `linkifyOK`. - `sync`: `cloneSibling`; reused existing `writeFile`. - `search`: `fixtureGraph` / `writePage`; reused the `rg`-missing skip guard. - `render`: `mustRender` / `mustRenderEmphasis` / `plainText` / `rowOf`. - **Selective arrange/act/assert** — added `// arrange`, `// act`, `// assert` sections to imperative single-scenario tests; left table-driven (`cases := []struct{…}` loop) tests as clean loops. `cmd/weft` was already a clean table test and is untouched. ## Verification - `go build ./...`, `go vet ./...` — clean - `gofmt -l` — clean on all test files - `go test -count=1 ./...` — all green - Pass counts unchanged per package: views 261, graph 31, render 24, sync 9, search 5, cmd 10. Two new shared `helpers_test.go` files (`internal/views`, `internal/graph`). Follows the `internal/edit/editor_test.go` style established in #22.
refactor(test): DRY shared setup + selective arrange/act/assert
All checks were successful
CI / vet-and-test (pull_request) Successful in 24s
2566579989
Pure test refactor across all packages — no production code changed, no test
behavior changed (same scenarios, assertions, and pass counts).

- Extract repeated setup into package-local helpers (t.Helper()): views gets
  quietTerm + writeGraph (collapsing ~154 TERM/NO_COLOR setenv pairs and the
  tempdir/BuildIndex fixture dance); graph gets fixturePath/buildFixtureIndex/
  buildTempIndex/mapReader/linkifyOK; sync gets cloneSibling; search gets
  fixtureGraph/writePage; render gets mustRender/plainText/rowOf.
- Apply // arrange, // act, // assert sections to imperative single-scenario
  tests; leave table-driven (cases-loop) tests as clean loops.

Pass counts unchanged per package; go build/vet and full suite green.
style: gofmt internal/views production files
All checks were successful
CI / vet-and-test (pull_request) Successful in 26s
5e4a4599ce
Pre-existing struct-field alignment / comment-spacing drift in backlinks.go,
editor.go, overlay.go, page.go. gofmt-only, no semantic change.
Sign in to join this conversation.
No reviewers
No labels
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
fiatcode/weft!23
No description provided.