test: add unit tests for trace processing helpers - #2514
Open
ZayanKhan-12 wants to merge 1 commit into
Open
Conversation
|
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
force-pushed
the
chore/tests-trace-guard
branch
from
August 8, 2026 21:46
7e939f4 to
14ccacf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
src/trace-processing/parse.tsexports several pure, browser-free helpers, buttests/trace-processing/parse.test.tsonly exercised the happy parse path, the trace summary snapshot, and theundefined-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
traceResultIsSuccesstruefor the result of a real successful parse (fixture trace)truefor aTraceResultwhoseinsightsisnull(the guard must only depend onparsedTrace)falsefor the result of a failed parsefalsefor aTraceParseErrorobjectfalsefor a near-miss where the error message text is'parsedTrace'— the guard checks the key, not valuesparseRawTraceBuffer(previously untested error branches)'Decoding the trace buffer returned an empty string.'TraceParseErrorinstead of throwingTraceParseErrorinstead of throwinggetInsightOutput(previously untested)NAVIGATION_0/LCPBreakdownfrom theweb-dev-with-commitfixture)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— cleannode 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