test: expand heap snapshot formatter and manager coverage - #2522
test: expand heap snapshot formatter and manager coverage#2522ZayanKhan-12 wants to merge 1 commit into
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. |
190045e to
0eb8299
Compare
| it('returns an empty string for an empty array', () => { | ||
| assert.strictEqual(HeapSnapshotFormatter.formatNodes([]), ''); | ||
| }); |
There was a problem hiding this comment.
| it('returns an empty string for an empty array', () => { | |
| assert.strictEqual(HeapSnapshotFormatter.formatNodes([]), ''); | |
| }); |
| // Every class gets a distinct id. | ||
| assert.strictEqual(ids.size, aggregates.length); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
We hand this off to DevTools so this should not be tested here.
| } | ||
| }); | ||
|
|
||
| it('exposes static data once the snapshot is loaded', async () => { |
There was a problem hiding this comment.
We hand this off to DevTools so this should not be tested here.
| }); | ||
|
|
||
| it('reports snapshot statistics', async () => { | ||
| const stats = await manager.getStats(fixturePath); |
There was a problem hiding this comment.
We hand this off to DevTools so this should not be tested here.
Why
tests/HeapSnapshotManager.test.tshad a single test whileHeapSnapshotManagerexposes the aggregation/stats/static-data/native-context API the memory tools are built on, and the exportedisNodeLike/isEdgeLiketype guards insrc/formatters/HeapSnapshotFormatter.tshad no coverage at all. This adds 346 lines of tests only — nosrc/changes.Coverage
HeapSnapshotManager (against the existing example fixture, reusing the file's harness):
getAggregates: class totals, stable class ids that resolve back to class keys,objectsRetainedByContextsfilter,attributedToSpecificNativeContextwithout objectId rejectedgetStats,getStaticData,getNativeContextSizesHeapSnapshotFormatter guards (pure):
isNodeLike: valid minimal/full node shapes, null/undefined, primitives, empty object, missing id/name, edge-shaped near-missisEdgeLike: valid edge with node-like node, null/undefined, empty object, each missing top-level propertyTesting
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