Skip to content

🔧 chore: one createEvent in log-viewer, not five #1076

Description

@lukecotter

🔧 Chore Description

log-viewer has five functions called createEvent, with five different signatures, across
252 call sites. One of them is the shared helper added in #1069.

file line signature calls
src/__tests__/helpers/events.ts 49 ({ text, self, total, … }) shared, 4 files
features/call-tree/utils/__tests__/ExecutionHighlights.test.ts 19 ({ text, type, category, namespace, self, total, timestamp, exitStamp, parent, isTruncated }) 56
features/timeline/__tests__/event-index.test.ts 24 (timestamp, duration, children?) 59
features/timeline/__tests__/tooltip.test.ts 40 (timestamp, duration, type?, category?) 54
features/timeline/optimised/__tests__/TemporalSegmentTree.test.ts 26 (timestamp, duration, category, children?) 48
features/timeline/optimised/__tests__/RectangleCache.bucket.test.ts 25 byte-identical to the row above 35

The cost is the name, more than the duplication. Someone in a timeline suite reads
createEvent(0, 100), greps for it, finds helpers/events.ts, and is reading the wrong
function. Only one function in log-viewer should carry that name.

Suggested shape

Three pieces, in value order. They can land separately.

  1. Fold ExecutionHighlights.test.ts:19 into the shared helper. It is the shared helper plus
    three fields — same options-object shape, same 'METHOD_ENTRY' / 'default' defaults, same
    parent.children.push. It differs only by category, isTruncated and eventIndex. Add those
    three to EventOptions, keeping eventIndex opt-in and undefaulted for the reason already
    recorded at helpers/events.ts:45-48, then delete the local.

  2. TemporalSegmentTree.test.ts and RectangleCache.bucket.test.ts are copies of each other.
    Their createEvent, their createViewport and their getAllBuckets are all duplicated between
    two sibling files in one directory. One module beside them covers all three.

  3. event-index.test.ts and tooltip.test.ts are the timeline flavour — positional
    (timestamp, duration, …), synthesising exitStamp and text. 113 calls. This wants its own
    helper rather than folding into helpers/events.ts: the two serve different passes and the
    field sets barely overlap.

Related, smaller

  • ev is six different functions across 99 call sites: core/log/__tests__/keyPathIds.test.ts:11,
    components/__tests__/scopedCallTree.test.ts:17, components/__tests__/locatedRow.test.ts:51,
    features/call-tree/utils/__tests__/bucketRows.test.ts:10,
    components/__tests__/categoryTime.test.ts:20, and the exported one in
    components/__tests__/fixtures/logEvents.ts:21. Only locatedRow and bucketRows are the same
    builder (one optional argument apart) and worth merging; the rest want distinct names.
  • components/__tests__/limitsTestUtils.ts and sectionTestUtils.ts are each imported by suites
    in other trees, so they belong in src/__tests__/helpers/ rather than under components/.
  • The six shared helpers use four naming verbs between them (create*, *Of, make*, verb-noun).
    Worth settling on one rule and writing it down; makeViewport is the outlier.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions