Skip to content

test: add unit tests for trace processing helpers - #2514

Open
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-trace-guard
Open

test: add unit tests for trace processing helpers#2514
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-trace-guard

Conversation

@ZayanKhan-12

Copy link
Copy Markdown

Why

src/trace-processing/parse.ts exports several pure, browser-free helpers, but tests/trace-processing/parse.test.ts only exercised the happy parse path, the trace summary snapshot, and the undefined-buffer error. This PR adds direct unit tests for the remaining exported helpers and branches, so regressions in the discriminant logic or the error contracts are caught without needing a browser.

Coverage added

  • traceResultIsSuccess
    • returns true for the result of a real successful parse (fixture trace)
    • returns true for a TraceResult whose insights is null (the guard must only depend on parsedTrace)
    • returns false for the result of a failed parse
    • returns false for a TraceParseError object
    • returns false for a near-miss where the error message text is 'parsedTrace' — the guard checks the key, not values
  • parseRawTraceBuffer (previously untested error branches)
    • empty buffer → 'Decoding the trace buffer returned an empty string.'
    • invalid JSON → returns a TraceParseError instead of throwing
    • valid JSON that is not a trace → returns a TraceParseError instead of throwing
  • getInsightOutput (previously untested)
    • formatted output for a known insight (NAVIGATION_0 / LCPBreakdown from the web-dev-with-commit fixture)
    • error when the trace has no insights
    • error for an unknown insight set id
    • error for an unknown insight name

Tests only — no changes under src/, and no new snapshots (the insight output is asserted with a targeted match so devtools-frontend formatter updates don't churn a snapshot).

Testing

  • npm run build — clean
  • node scripts/test.js tests/trace-processing/parse.test.ts — 15/15 pass (3 suites)
  • npm run test:no-build — full suite green (exit 0)
  • npm run check-format — eslint + prettier clean

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Adds direct unit tests for the pure helpers exported from
src/trace-processing/parse.ts:

- traceResultIsSuccess: accepts real parsed trace results (with and
  without insights) and rejects TraceParseError objects, including a
  near-miss where the error message contains the discriminant key name.
- parseRawTraceBuffer: covers the previously untested error branches for
  empty buffers, invalid JSON, and valid JSON that is not a trace.
- getInsightOutput: covers the formatted output for a known insight and
  all three error branches (no insights, unknown insight set id, unknown
  insight name).
@ZayanKhan-12
ZayanKhan-12 force-pushed the chore/tests-trace-guard branch from 7e939f4 to 14ccacf Compare August 8, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants