Skip to content

test: expand heap snapshot formatter and manager coverage - #2522

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

test: expand heap snapshot formatter and manager coverage#2522
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-heapsnapshot

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

Why

tests/HeapSnapshotManager.test.ts had a single test while HeapSnapshotManager exposes the aggregation/stats/static-data/native-context API the memory tools are built on, and the exported isNodeLike/isEdgeLike type guards in src/formatters/HeapSnapshotFormatter.ts had no coverage at all. This adds 346 lines of tests only — no src/ changes.

Coverage

HeapSnapshotManager (against the existing example fixture, reusing the file's harness):

  • snapshot caching by resolved path; lifecycle tracking + dispose; class-key lookups rejected for unloaded snapshots
  • getAggregates: class totals, stable class ids that resolve back to class keys, objectsRetainedByContexts filter, attributedToSpecificNativeContext without objectId rejected
  • getStats, getStaticData, getNativeContextSizes

HeapSnapshotFormatter guards (pure):

  • isNodeLike: valid minimal/full node shapes, null/undefined, primitives, empty object, missing id/name, edge-shaped near-miss
  • isEdgeLike: valid edge with node-like node, null/undefined, empty object, each missing top-level property

Testing

  • node scripts/test.js tests/formatters/HeapSnapshotFormatter.test.ts tests/HeapSnapshotManager.test.ts → pass (exit 0)
  • npm run test:no-build → full suite pass (exit 0)
  • npm run check-format → eslint + prettier clean

@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.

@ZayanKhan-12
ZayanKhan-12 force-pushed the chore/tests-heapsnapshot branch from 190045e to 0eb8299 Compare August 8, 2026 21:46
@Lightning00Blade
Lightning00Blade self-requested a review August 10, 2026 08:52
Comment on lines +289 to +291
it('returns an empty string for an empty array', () => {
assert.strictEqual(HeapSnapshotFormatter.formatNodes([]), '');
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('returns an empty string for an empty array', () => {
assert.strictEqual(HeapSnapshotFormatter.formatNodes([]), '');
});

Comment on lines +84 to +85
// Every class gets a distinct id.
assert.strictEqual(ids.size, aggregates.length);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not need it handled by line 76

let objectCount = 0;
let totalSelfSize = 0;
const ids = new Set<number>();
for (const aggregate of aggregates) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same code that we have, which means we are not testing anything.
We should assert at hard coded values as the fixture is hard coded as well.

});

it('returns stable class ids that resolve back to class keys', async () => {
const first = await manager.getAggregates(fixturePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a test that showcases that the two are the same so we can just use one.

let objectCount = 0;
let totalSelfSize = 0;
const ids = new Set<number>();
for (const aggregate of aggregates) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same code that we have, which means we are not testing anything.
We should assert at hard coded values as the fixture is hard coded as well.

assert.strictEqual(staticData.totalSize, stats.total);
});

it('computes native context sizes', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hand this off to DevTools so this should not be tested here.

}
});

it('exposes static data once the snapshot is loaded', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hand this off to DevTools so this should not be tested here.

});

it('reports snapshot statistics', async () => {
const stats = await manager.getStats(fixturePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hand this off to DevTools so this should not be tested here.

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.

3 participants