Skip to content

Chrome DevTools for coding agents

test: migrate memory tests off withMcpContext (#2729)

Mahesh Singh350404e88f0a
diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts
index 2deddd81..b91a4a51 100644
--- a/tests/McpResponse.test.ts
+++ b/tests/McpResponse.test.ts
@@ -14,8 +14,9 @@ import sinon from 'sinon';
import type {ParsedArguments} from '../src/config/mcp-options.js';
import type {McpContext} from '../src/McpContext.js';
-import type {McpResponse} from '../src/McpResponse.js';
-import type {Extension} from '../src/third_party/index.js';
+import {McpResponse} from '../src/McpResponse.js';
+import {DevTools, type Extension} from '../src/third_party/index.js';
+import {stableIdSymbol} from '../src/utils/id.js';
import {
closePage,
listPages,
@@ -32,10 +33,20 @@ import {
import {serverHooks} from './server.js';
import {loadTraceAsBuffer} from './trace-processing/fixtures/load.js';
import {
+ createMockAggregatedInfo,
createMockCSSMatchedStyles,
createMockCSSProperty,
createMockCSSStyleDeclaration,
createMockCSSStyleRule,
+ createMockClassDiffs,
+ createMockDetailedClassDiff,
+ createMockHeapSnapshotEdge,
+ createMockHeapSnapshotNode,
+ createMockHeapSnapshotStats,
+ createMockHeapSnapshotStaticData,
+ createMockMcpContext,
+ createMockObjectInfo,
+ createMockParsedArguments,
} from './mocks.js';
import {
getImageContent,
@@ -1191,3 +1202,338 @@ describe('webmcp', () => {
});
});
});
+
+describe('McpResponse heap snapshot formatting', () => {
+ DevTools.I18n.DevToolsLocale.DevToolsLocale.instance({
+ create: true,
+ data: {
+ navigatorLanguage: 'en-US',
+ settingLanguage: 'en-US',
+ lookupClosestDevToolsLocale: l => l,
+ },
+ });
+ DevTools.I18n.i18n.registerLocaleDataForTest('en-US', {});
+
+ it('formats stats, staticData, nativeContextSizes, and retainedByContextSummary', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const stats = createMockHeapSnapshotStats();
+ const staticData = createMockHeapSnapshotStaticData();
+ const nativeContextSizes = {
+ nativeContexts: [
+ {
+ nodeId: 10,
+ nodeIndex: 1,
+ nodeName: 'system / NativeContext',
+ attributedSize: 500,
+ retainedSize: 1000,
+ selfSize: 100,
+ },
+ ],
+ sharedSize: 300,
+ noAttributionSize: 400,
+ };
+ const retainedByContextSummary = {
+ contextCount: 2,
+ retainedByContextSize: 5000,
+ retainedByContextCount: 10,
+ notRetainedByContextSize: 1000,
+ notRetainedByContextCount: 5,
+ totalSize: 6000,
+ };
+ response.setHeapSnapshotStats(
+ stats,
+ staticData,
+ nativeContextSizes,
+ retainedByContextSummary,
+ );
+ const context = createMockMcpContext();
+ const {content, structuredContent} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('## Heap Snapshot Data'));
+ assert.ok(text.includes('Statistics: '));
+ assert.ok(text.includes('Static Data: '));
+ assert.ok(text.includes('### Native Contexts'));
+ assert.ok(text.includes('system / NativeContext'));
+ assert.ok(text.includes('### Retained by Context Summary'));
+ assert.ok(text.includes('Context count: 2'));
+ assert.ok(text.includes('Total size: '));
+
+ const heapData: unknown = Reflect.get(structuredContent, 'heapSnapshot');
+ assert.ok(heapData && typeof heapData === 'object');
+ assert.deepStrictEqual(Reflect.get(heapData, 'stats'), stats);
+ assert.deepStrictEqual(Reflect.get(heapData, 'staticData'), staticData);
+ assert.deepStrictEqual(
+ Reflect.get(heapData, 'nativeContextSizes'),
+ nativeContextSizes,
+ );
+ assert.deepStrictEqual(
+ Reflect.get(heapData, 'retainedByContextSummary'),
+ retainedByContextSummary,
+ );
+ });
+
+ it('formats aggregate data with shallow size and pagination summaries', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const aggregates = {
+ aggregates: {
+ ObjectA: createMockAggregatedInfo({
+ name: 'ObjectA',
+ count: 10,
+ self: 100,
+ maxRet: 1000,
+ distance: 1,
+ idxs: [],
+ [stableIdSymbol]: 1,
+ }),
+ ObjectB: createMockAggregatedInfo({
+ name: 'ObjectB',
+ count: 5,
+ self: 50,
+ maxRet: 500,
+ distance: 2,
+ idxs: [],
+ [stableIdSymbol]: 2,
+ }),
+ },
+ objectCount: 15,
+ totalSelfSize: 150,
+ };
+
+ response.setHeapSnapshotAggregates(aggregates, {
+ pageSize: 1,
+ pageIdx: 0,
+ });
+ const context = createMockMcpContext();
+ const {content, structuredContent} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('## Heap Snapshot Data'));
+ assert.ok(text.includes('Objects: 15'));
+ assert.ok(text.includes('Total shallow size: '));
+ assert.ok(text.includes('Showing 1-1 of 2 (Page 1 of 2).'));
+ assert.ok(text.includes('Next page: 1'));
+ assert.ok(text.includes('ObjectA'));
+ assert.ok(!text.includes('ObjectB'));
+
+ const heapData: unknown = Reflect.get(structuredContent, 'heapSnapshot');
+ assert.ok(heapData && typeof heapData === 'object');
+ assert.deepStrictEqual(Reflect.get(heapData, 'aggregateStats'), {
+ objectCount: 15,
+ totalSelfSize: 150,
+ });
+ });
+
+ it('sorts nodes descending by retainedSize and formats pagination summaries', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const nodeSmall = createMockHeapSnapshotNode({
+ id: 1,
+ name: 'SmallNode',
+ retainedSize: 100,
+ });
+ const nodeLarge = createMockHeapSnapshotNode({
+ id: 2,
+ name: 'LargeNode',
+ retainedSize: 500,
+ });
+ const nodeMedium = createMockHeapSnapshotNode({
+ id: 3,
+ name: 'MediumNode',
+ retainedSize: 200,
+ });
+
+ const itemsRange =
+ new DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange(0, 3, 3, [
+ nodeSmall,
+ nodeLarge,
+ nodeMedium,
+ ]);
+
+ response.setHeapSnapshotNodes(itemsRange, {
+ pageSize: 2,
+ pageIdx: 0,
+ });
+
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('Showing 1-2 of 3 (Page 1 of 2).'));
+ assert.ok(text.includes('Next page: 1'));
+
+ const largeIndex = text.indexOf('LargeNode');
+ const mediumIndex = text.indexOf('MediumNode');
+ assert.ok(largeIndex !== -1, 'LargeNode should be present');
+ assert.ok(mediumIndex !== -1, 'MediumNode should be present');
+ assert.ok(
+ largeIndex < mediumIndex,
+ 'LargeNode should precede MediumNode due to descending retainedSize sorting',
+ );
+ assert.ok(
+ !text.includes('SmallNode'),
+ 'SmallNode should be on page 1, not page 0',
+ );
+ });
+
+ it('formats edge nodes correctly', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const edge = createMockHeapSnapshotEdge({
+ name: 'myProp',
+ type: 'property',
+ node: createMockHeapSnapshotNode({id: 42, name: 'TargetNode'}),
+ });
+
+ const itemsRange =
+ new DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange(0, 1, 1, [
+ edge,
+ ]);
+
+ response.setHeapSnapshotNodes(itemsRange);
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('name,type,nodeId,nodeName,selfSize,retainedSize'));
+ assert.ok(text.includes('myProp,property,42,TargetNode'));
+ });
+
+ it('formats retaining paths with truncation note when limits are reached', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const retainingPaths = {
+ paths: [
+ {
+ edgeIndex: 0,
+ edgeName: 'ref',
+ edgeType: 'property',
+ nodeId: 10,
+ nodeIndex: 1,
+ nodeName: 'ParentClass',
+ distance: 1,
+ children: [],
+ },
+ ],
+ limitsReached: {
+ depth: true,
+ nodes: false,
+ siblings: false,
+ },
+ };
+
+ response.setHeapSnapshotRetainingPaths(retainingPaths);
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('### Retaining Paths'));
+ assert.ok(
+ text.includes('<- @10 ParentClass via property ref (distance: 1)'),
+ );
+ assert.ok(
+ text.includes(
+ 'Note: results are truncated, the following limits were reached: depth.',
+ ),
+ );
+ });
+
+ it('formats empty retaining paths with no paths message', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ response.setHeapSnapshotRetainingPaths({
+ paths: [],
+ limitsReached: {depth: false, nodes: false, siblings: false},
+ });
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('### Retaining Paths'));
+ assert.ok(text.includes('No retaining paths found.'));
+ });
+
+ it('formats dominator chain and handles empty dominators', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const dominators = [
+ {
+ nodeId: 10,
+ nodeIndex: 1,
+ nodeName: 'DomClass',
+ retainedSize: 1000,
+ selfSize: 100,
+ },
+ ];
+
+ response.setHeapSnapshotDominators(dominators);
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('### Dominator Chain'));
+ assert.ok(text.includes('10,DomClass'));
+
+ const emptyResponse = new McpResponse(createMockParsedArguments());
+ emptyResponse.setHeapSnapshotDominators([]);
+ const emptyResult = await emptyResponse.handle(context);
+ const emptyText = getTextContent(emptyResult.content[0]);
+ assert.ok(emptyText.includes('### Dominator Chain'));
+ assert.ok(emptyText.includes('No dominators found.'));
+ });
+
+ it('formats class diff summary and detailed diff headers', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const diffs = createMockClassDiffs();
+ response.setHeapSnapshotClassDiffs(diffs);
+
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('### Heap Snapshot Diff'));
+ assert.ok(text.includes('TestClass'));
+
+ const detailedResponse = new McpResponse(createMockParsedArguments());
+ const detailedDiff = createMockDetailedClassDiff();
+ detailedResponse.setHeapSnapshotDetailedClassDiff(detailedDiff);
+
+ const detailedResult = await detailedResponse.handle(context);
+ const detailedText = getTextContent(detailedResult.content[0]);
+ assert.ok(detailedText.includes('### Heap Snapshot Detailed Diff'));
+ assert.ok(detailedText.includes('TestClass: # new: 1, # deleted: 0'));
+ });
+
+ it('formats duplicate strings with pagination and object details', async () => {
+ const response = new McpResponse(createMockParsedArguments());
+ const duplicateStrings = [
+ {
+ value: 'duplicated-string-value',
+ count: 5,
+ totalSelfSize: 100,
+ totalRetainedSize: 500,
+ nodes: [
+ {id: 10, selfSize: 50, retainedSize: 250, distance: 1},
+ {id: 20, selfSize: 50, retainedSize: 250, distance: 2},
+ ],
+ },
+ ];
+ response.setHeapSnapshotDuplicateStrings(duplicateStrings, {
+ pageSize: 1,
+ pageIdx: 0,
+ });
+
+ const context = createMockMcpContext();
+ const {content} = await response.handle(context);
+ const text = getTextContent(content[0]);
+
+ assert.ok(text.includes('### Duplicate Strings'));
+ assert.ok(text.includes('duplicated-string-value'));
+ assert.ok(text.includes('Showing 1-1 of 1 (Page 1 of 1).'));
+
+ const objectInfoResponse = new McpResponse(createMockParsedArguments());
+ const objectInfo = createMockObjectInfo();
+ objectInfoResponse.setHeapSnapshotObjectDetails(objectInfo);
+
+ const objectResult = await objectInfoResponse.handle(context);
+ const objectText = getTextContent(objectResult.content[0]);
+ assert.ok(objectText.includes('### Object Details'));
+ assert.ok(objectText.includes('id: @1'));
+ assert.ok(objectText.includes('name: Object'));
+ });
+});
diff --git a/tests/formatters/HeapSnapshotFormatter.test.js.snapshot b/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
index 03b24169..e715dd25 100644
--- a/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
+++ b/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
@@ -3,3 +3,590 @@ id,name,count,selfSize,retainedSize
1,ObjectA,10,0.1 kB,1.0 kB
2,ObjectB,5,0.1 kB,0.5 kB
`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats detailed diff comparing heap-1 to heap-2 with classIndex filter 1`] = `
+NewObject: # new: 2, # deleted: 0, # delta: +2, alloc size: +0.1 kB, freed size: 0.0 kB, size delta: +0.1 kB
+Objects:
+ + @35179 (self_size: 0.1 kB)
+ + @35181 (self_size: 0.1 kB)
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-1 to heap-2 1`] = `
+index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
+0,(object shape),11,1,10,0.4 kB,0.0 kB,0.4 kB
+1,(compiled code),7,1,6,0.3 kB,0.0 kB,0.2 kB
+2,NewObject,2,0,2,0.1 kB,0.0 kB,0.1 kB
+3,(concatenated string),45,43,2,0.9 kB,0.9 kB,0.0 kB
+4,Array,2,0,2,0.0 kB,0.0 kB,0.0 kB
+5,{constructor},1,0,1,0.0 kB,0.0 kB,0.0 kB
+6,(string),4,4,0,0.1 kB,0.1 kB,0.0 kB
+7,(number),0,2,-2,0.0 kB,0.0 kB,-0.0 kB
+8,Object,0,2,-2,0.0 kB,0.0 kB,-0.0 kB
+9,InitialObject,0,2,-2,0.0 kB,0.1 kB,-0.1 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-2 to heap-3 1`] = `
+index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
+0,(concatenated string),105,0,105,2.1 kB,0.0 kB,2.1 kB
+1,(object shape),7,1,6,0.3 kB,0.1 kB,0.3 kB
+2,(string),10,0,10,0.2 kB,0.0 kB,0.2 kB
+3,NewObject,5,0,5,0.1 kB,0.0 kB,0.1 kB
+4,Array,5,0,5,0.1 kB,0.0 kB,0.1 kB
+5,system / PropertyArray,1,0,1,0.0 kB,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDominators > formats dominator chain for a valid nodeId 1`] = `
+nodeId,nodeName,selfSize,retainedSize
+25341,String,0.2 kB,1.6 kB
+7199,system / NativeContext,1.2 kB,84.4 kB
+1,,0.0 kB,802 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDuplicateStrings > formats duplicate strings with default options 1`] = `
+value,count,totalSelfSize,totalRetainedSize,truncated,nodeIds
+"get disposed",8,0.2 kB,0.2 kB,false,@30685 @30731 @33713 @33781 @42891 @42947 @45203 @45233
+"WebAssembly.Suspending",4,0.1 kB,0.1 kB,false,@44967 @45473 @46069 @46195
+"extensions::SafeBuiltins",2,0.1 kB,0.1 kB,false,@25155 @26209
+"WebAssembly",2,0.0 kB,0.0 kB,false,@7495 @15037
+"EventTarget",2,0.0 kB,0.0 kB,false,@25089 @26185
+"v8/LoadTimes",2,0.0 kB,0.0 kB,false,@25159 @26365
+"Document",2,0.0 kB,0.0 kB,false,@25969 @26603
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNativeContextSizes > formats native context sizes from fixture 1`] = `
+nodeId,nodeName,selfSize,retainedSize,attributedSize
+7249,system / NativeContext / https://example.com,1.2 kB,350 kB,350 kB
+7195,system / NativeContext / https://example.com,1.2 kB,60.1 kB,215 kB
+7307,system / NativeContext,1.2 kB,84.4 kB,84.6 kB
+7199,system / NativeContext,1.2 kB,84.4 kB,84.4 kB
+Shared Size: 22.9 kB
+Unattributed Size: 44.8 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with default options 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+25307,Array,object,2,0.2 kB,2.1 kB
+33187,Array,object,2,0.2 kB,1.7 kB
+36255,Array,object,2,0.2 kB,1.7 kB
+45899,Array,object,5,0.1 kB,0.1 kB
+45901,Array,object,5,0.1 kB,0.1 kB
+46149,Array,object,5,0.1 kB,0.1 kB
+46151,Array,object,5,0.1 kB,0.1 kB
+46355,Array,object,2,0.2 kB,2.1 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with objectsRetainedByContexts filterName 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+45893,Apply,closure,5,0.0 kB,0.0 kB
+45895,Save,closure,5,0.0 kB,0.0 kB
+45897,makeCallable,closure,5,0.0 kB,0.2 kB
+46143,Apply,closure,5,0.0 kB,0.0 kB
+46145,Save,closure,5,0.0 kB,0.0 kB
+46147,makeCallable,closure,5,0.0 kB,0.2 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges for a valid nodeId 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+anchor,property,29295,anchor,0.0 kB,0.0 kB
+at,property,29297,at,0.0 kB,0.0 kB
+big,property,29299,big,0.0 kB,0.0 kB
+blink,property,29301,blink,0.0 kB,0.0 kB
+bold,property,29303,bold,0.0 kB,0.0 kB
+charAt,property,29305,charAt,0.0 kB,0.0 kB
+charCodeAt,property,29307,charCodeAt,0.0 kB,0.0 kB
+codePointAt,property,29309,codePointAt,0.0 kB,0.0 kB
+concat,property,29311,concat,0.0 kB,0.0 kB
+endsWith,property,29313,endsWith,0.0 kB,0.0 kB
+fontcolor,property,29315,fontcolor,0.0 kB,0.0 kB
+fontsize,property,29317,fontsize,0.0 kB,0.0 kB
+fixed,property,29319,fixed,0.0 kB,0.0 kB
+includes,property,29321,includes,0.0 kB,0.0 kB
+indexOf,property,29323,indexOf,0.0 kB,0.0 kB
+isWellFormed,property,29325,isWellFormed,0.0 kB,0.0 kB
+italics,property,29327,italics,0.0 kB,0.0 kB
+lastIndexOf,property,29329,lastIndexOf,0.0 kB,0.0 kB
+link,property,29331,link,0.0 kB,0.0 kB
+localeCompare,property,29333,localeCompare,0.0 kB,0.0 kB
+match,property,29335,match,0.0 kB,0.0 kB
+matchAll,property,29337,matchAll,0.0 kB,0.0 kB
+normalize,property,29339,normalize,0.0 kB,0.0 kB
+padEnd,property,29341,padEnd,0.0 kB,0.0 kB
+padStart,property,29343,padStart,0.0 kB,0.0 kB
+repeat,property,29345,repeat,0.0 kB,0.0 kB
+replace,property,29347,replace,0.0 kB,0.0 kB
+replaceAll,property,29349,replaceAll,0.0 kB,0.0 kB
+search,property,29351,search,0.0 kB,0.0 kB
+slice,property,29353,slice,0.0 kB,0.0 kB
+small,property,29355,small,0.0 kB,0.0 kB
+split,property,29357,split,0.0 kB,0.0 kB
+strike,property,29359,strike,0.0 kB,0.0 kB
+sub,property,29361,sub,0.0 kB,0.0 kB
+substr,property,29363,substr,0.0 kB,0.0 kB
+substring,property,29365,substring,0.0 kB,0.0 kB
+sup,property,29367,sup,0.0 kB,0.0 kB
+startsWith,property,29369,startsWith,0.0 kB,0.0 kB
+toString,property,29371,toString,0.0 kB,0.0 kB
+toWellFormed,property,29373,toWellFormed,0.0 kB,0.0 kB
+trim,property,29375,trim,0.0 kB,0.0 kB
+trimStart,property,29377,trimStart,0.0 kB,0.0 kB
+trimLeft,property,29377,trimStart,0.0 kB,0.0 kB
+trimEnd,property,29379,trimEnd,0.0 kB,0.0 kB
+trimRight,property,29379,trimEnd,0.0 kB,0.0 kB
+toLocaleLowerCase,property,29381,toLocaleLowerCase,0.0 kB,0.0 kB
+toLocaleUpperCase,property,29383,toLocaleUpperCase,0.0 kB,0.0 kB
+toLowerCase,property,29385,toLowerCase,0.0 kB,0.0 kB
+toUpperCase,property,29387,toUpperCase,0.0 kB,0.0 kB
+valueOf,property,29389,valueOf,0.0 kB,0.0 kB
+<symbol Symbol.iterator>,property,29391,[Symbol.iterator],0.0 kB,0.0 kB
+__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
+properties,internal,29393,system / PropertyArray,0.0 kB,0.0 kB
+map,internal,25577,system / Map,0.0 kB,0.7 kB
+1,hidden,71,,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with pagination 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+anchor,property,29295,anchor,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with retainedSize range 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
+map,internal,25577,system / Map,0.0 kB,0.7 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with an unbounded retainedSize filter 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+1,,synthetic,100000000,0.0 kB,802 kB
+7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
+7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
+49547,,array,2,4.1 kB,41.0 kB
+36241,,array,2,4.1 kB,41.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with className filter 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+32995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
+41995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
+16321,Window / https://example.com,native,2,0.9 kB,1.9 kB
+16329,Window,closure,3,0.1 kB,0.4 kB
+16341,Window,closure,3,0.1 kB,0.4 kB
+30975,Window (prototype) / https://example.com,object,3,0.0 kB,0.2 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with default options 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+1,,synthetic,100000000,0.0 kB,802 kB
+7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
+7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
+49547,,array,2,4.1 kB,41.0 kB
+36241,,array,2,4.1 kB,41.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with sortBy selfSize and pagination 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+32657,system / DescriptorArray,object shape,5,9.8 kB,9.8 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with retainers > formats retainers for a valid nodeId 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+prototype,internal,29287,system / Map,0.0 kB,0.1 kB
+prototype,property,25575,String,0.1 kB,0.4 kB
+initial_string_prototype,internal,7199,system / NativeContext,1.2 kB,84.4 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatObjectInfo > formats object details for a valid nodeId 1`] = `
+id: @25341
+name: String
+type: object
+detachedness: unknown
+selfSize: 0.2 kB
+retainedSize: 1.6 kB
+distance: 2
+edgeCount: 56
+retainerCount: 3
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatRetainedByContextSummary > formats retained by context summary from fixture 1`] = `
+Context count: 116
+Retained by context size: 3.5 kB (148 objects)
+Not retained by context size: 798 kB (11792 objects)
+Total size: 802 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatRetainingPaths > formats retaining paths for a valid nodeId 1`] = `
+<- @45891 system / Context via context builtinToJSONs (distance: 4)
+ <- @34237 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Promise> (distance: 2)
+ <- @34235 system / PropertyCell via internal value (distance: 4)
+ <- @50423 (object properties) via internal 1912 (distance: 3)
+ <- @27635 Window (global*) / https://example.com via internal properties (distance: 2)
+ <- @34213 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Error> (distance: 2)
+ <- @34197 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::RegExp> (distance: 2)
+ <- @34185 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::String> (distance: 2)
+ <- @34145 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Array> (distance: 2)
+ <- @34069 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Function> (distance: 2)
+ <- @34047 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Object> (distance: 2)
+ <- @46063 stringify via internal context (distance: 4)
+ <- @34247 {parse, stringify} via property stringify (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::JSON> (distance: 2)
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with attributedToSpecificNativeContext filterName and objectId 1`] = `
+id,name,count,selfSize,retainedSize
+2,(system),1739,115 kB,350 kB
+11,Function,1095,34.9 kB,72.2 kB
+16,(object shape),769,52.6 kB,53.3 kB
+42,Window (global*) / https://example.com,1,40.5 kB,51.0 kB
+3,(array),6,9.1 kB,46.0 kB
+94,Window (prototype) / https://example.com,2,26.7 kB,26.9 kB
+1,(compiled code),323,19.3 kB,19.4 kB
+6,(string),376,10.5 kB,10.5 kB
+96,Window (internal cache) / https://example.com,2,0.2 kB,10.1 kB
+109,Document,1,8.4 kB,8.7 kB
+10,HTMLDocument,1,3.3 kB,6.2 kB
+105,HTMLElement,1,4.7 kB,4.8 kB
+104,Element,1,4.2 kB,4.5 kB
+55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, setDate, getDay},1,0.2 kB,2.2 kB
+49,TypedArray,12,0.4 kB,2.2 kB
+50,Error,12,0.3 kB,2.0 kB
+47,Math,1,0.2 kB,1.9 kB
+9,Window / https://example.com,1,0.9 kB,1.9 kB
+44,console,1,0.1 kB,1.8 kB
+19,Array,3,0.3 kB,1.8 kB
+103,Node,1,1.8 kB,1.8 kB
+126,Performance,1,1.0 kB,1.8 kB
+39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, get length},1,0.2 kB,1.8 kB
+89,system / Context,57,1.3 kB,1.7 kB
+32,String,1,0.2 kB,1.4 kB
+68,DataView,1,0.1 kB,1.4 kB
+106,HTMLBodyElement (prototype) / https://example.com,1,1.2 kB,1.2 kB
+62,Intl.Locale,1,0.1 kB,1.2 kB
+76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getFileName, getFunction},1,0.1 kB,1.1 kB
+130,StyleEngine,1,0.9 kB,1.1 kB
+45,Intl,1,0.1 kB,1.0 kB
+118,CSSStyleRule,8,0.6 kB,1.0 kB
+119,CSSStyleSheet,3,0.5 kB,1.0 kB
+25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, some, every, find},1,0.1 kB,0.9 kB
+43,Atomics,1,0.1 kB,0.8 kB
+91,DisposableStack,1,0.1 kB,0.8 kB
+92,AsyncDisposableStack,1,0.1 kB,0.8 kB
+54,Object,11,0.6 kB,0.7 kB
+46,Reflect,1,0.1 kB,0.6 kB
+72,ArrayBuffer,1,0.0 kB,0.5 kB
+110,Text,6,0.5 kB,0.5 kB
+37,WebAssembly,1,0.1 kB,0.5 kB
+58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get first, next, get next},1,0.0 kB,0.5 kB
+40,{constructor},4,0.1 kB,0.4 kB
+30,Set,1,0.1 kB,0.4 kB
+135,EventListener,10,0.4 kB,0.4 kB
+90,SharedArrayBuffer,1,0.0 kB,0.4 kB
+56,Intl.NumberFormat,1,0.0 kB,0.4 kB
+66,Intl.DateTimeFormat,1,0.0 kB,0.4 kB
+127,Navigation,1,0.2 kB,0.4 kB
+27,Map,1,0.1 kB,0.4 kB
+48,Number,1,0.1 kB,0.4 kB
+70,Symbol,1,0.0 kB,0.3 kB
+67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, keys, toReversed},1,0.1 kB,0.3 kB
+134,FontFaceSet,1,0.3 kB,0.3 kB
+133,StylePropertyMap,8,0.3 kB,0.3 kB
+139,MutationObserver,2,0.3 kB,0.3 kB
+100,{loadTimes, csi},1,0.0 kB,0.3 kB
+69,BigInt,1,0.0 kB,0.3 kB
+59,Intl.PluralRules,1,0.0 kB,0.3 kB
+60,Intl.RelativeTimeFormat,1,0.0 kB,0.3 kB
+61,Intl.ListFormat,1,0.0 kB,0.3 kB
+65,Intl.DurationFormat,1,0.0 kB,0.3 kB
+17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedderData, console},1,0.0 kB,0.3 kB
+28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__, isPrototypeOf},1,0.1 kB,0.3 kB
+115,<style>,1,0.1 kB,0.3 kB
+21,Generator,1,0.0 kB,0.3 kB
+23,AsyncGenerator,1,0.0 kB,0.3 kB
+57,Intl.Collator,1,0.0 kB,0.2 kB
+33,WeakMap,1,0.1 kB,0.2 kB
+123,IntersectionObserver,1,0.2 kB,0.2 kB
+35,Promise,1,0.0 kB,0.2 kB
+52,FinalizationRegistry,1,0.0 kB,0.2 kB
+63,Intl.DisplayNames,1,0.0 kB,0.2 kB
+64,Intl.Segmenter,1,0.0 kB,0.2 kB
+34,JSON,1,0.0 kB,0.2 kB
+132,MutationObserver::Delegate,2,0.1 kB,0.2 kB
+73,Async-from-Sync Iterator,1,0.0 kB,0.2 kB
+101,EventTarget,1,0.0 kB,0.2 kB
+22,{<symbol Symbol.asyncIterator>, <symbol Symbol.asyncDispose>},1,0.0 kB,0.2 kB
+85,{containing, <symbol Symbol.iterator>},1,0.0 kB,0.2 kB
+131,ScriptedAnimationController,1,0.2 kB,0.2 kB
+95,MutationObserver (prototype) / https://example.com,1,0.2 kB,0.2 kB
+80,WebAssembly.Memory,1,0.0 kB,0.2 kB
+99,{parse, stringify},1,0.0 kB,0.2 kB
+51,WeakRef,1,0.0 kB,0.2 kB
+79,WebAssembly.Table,1,0.0 kB,0.2 kB
+120,NavigationHistoryEntry,1,0.2 kB,0.2 kB
+129,StyleSheetCollection,1,0.2 kB,0.2 kB
+147,<a>,1,0.1 kB,0.2 kB
+71,Boolean,1,0.0 kB,0.2 kB
+146,DocumentTimeline,1,0.2 kB,0.2 kB
+18,Array Iterator,1,0.0 kB,0.2 kB
+24,Iterator Helper,1,0.0 kB,0.2 kB
+26,Map Iterator,1,0.0 kB,0.2 kB
+29,Set Iterator,1,0.0 kB,0.2 kB
+31,String Iterator,1,0.0 kB,0.2 kB
+86,Segmenter String Iterator,1,0.0 kB,0.2 kB
+88,RegExp String Iterator,1,0.0 kB,0.2 kB
+4,{<symbol handler_function>, <symbol feature_name>},4,0.1 kB,0.2 kB
+20,{constructor, name, message, toString},1,0.0 kB,0.2 kB
+114,<title>,1,0.1 kB,0.2 kB
+116,PerformancePaintTiming,2,0.2 kB,0.2 kB
+145,<p>,2,0.2 kB,0.2 kB
+87,{next, return},1,0.0 kB,0.2 kB
+111,<div>,1,0.1 kB,0.2 kB
+122,ServiceWorkerContainer,1,0.2 kB,0.2 kB
+125,Navigator,1,0.2 kB,0.2 kB
+155,PerformanceNavigationTiming,1,0.2 kB,0.2 kB
+84,GeneratorFunction,1,0.0 kB,0.2 kB
+75,AsyncGeneratorFunction,1,0.0 kB,0.2 kB
+74,AsyncFunction,1,0.0 kB,0.2 kB
+113,<head>,1,0.1 kB,0.2 kB
+81,WebAssembly.Global,1,0.0 kB,0.1 kB
+98,HTMLDocument (prototype) / https://example.com,1,0.1 kB,0.1 kB
+93,WebAssembly.Suspending,1,0.0 kB,0.1 kB
+36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasIndices, ignoreCase},1,0.1 kB,0.1 kB
+102,WindowProperties,1,0.0 kB,0.1 kB
+83,WebAssembly.Exception,1,0.0 kB,0.1 kB
+78,WebAssembly.Instance,1,0.0 kB,0.1 kB
+117,PerformanceResourceTiming,1,0.1 kB,0.1 kB
+152,LargestContentfulPaint,1,0.1 kB,0.1 kB
+136,CustomElementRegistry,1,0.1 kB,0.1 kB
+138,CSSRuleList,4,0.1 kB,0.1 kB
+141,Storage,2,0.1 kB,0.1 kB
+13,<body>,1,0.1 kB,0.1 kB
+82,WebAssembly.Tag,1,0.0 kB,0.1 kB
+77,WebAssembly.Module,1,0.0 kB,0.1 kB
+121,DOMTokenList,2,0.1 kB,0.1 kB
+53,WeakSet,1,0.0 kB,0.1 kB
+148,HTMLCollection,1,0.1 kB,0.1 kB
+150,ScriptRunner,1,0.1 kB,0.1 kB
+112,<meta>,1,0.1 kB,0.1 kB
+140,<html>,1,0.1 kB,0.1 kB
+144,<h1>,1,0.1 kB,0.1 kB
+149,Screen,1,0.1 kB,0.1 kB
+153,DocumentType,1,0.1 kB,0.1 kB
+156,VisibilityStateEntry,1,0.1 kB,0.1 kB
+137,MutationObserverRegistration,1,0.1 kB,0.1 kB
+151,FragmentDirective,1,0.1 kB,0.1 kB
+124,IntersectionObserverDelegate,1,0.0 kB,0.0 kB
+128,NavigationActivation,1,0.0 kB,0.0 kB
+154,PerformanceTiming,1,0.0 kB,0.0 kB
+38,Tag,1,0.0 kB,0.0 kB
+142,VisualViewport,1,0.0 kB,0.0 kB
+143,Viewport,1,0.0 kB,0.0 kB
+12,HTMLBodyElement,1,0.0 kB,0.0 kB
+97,HTMLDocument (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+107,MutationObserver (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+108,HTMLBodyElement (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with default options 1`] = `
+id,name,count,selfSize,retainedSize
+2,(system),3205,199 kB,655 kB
+11,Function,3581,111 kB,237 kB
+16,(object shape),2878,181 kB,184 kB
+3,(array),34,41.4 kB,117 kB
+42,Window (global*) / https://example.com,2,81.1 kB,102 kB
+94,Window (prototype) / https://example.com,4,53.3 kB,53.7 kB
+1,(compiled code),713,42.8 kB,47.0 kB
+6,(string),846,27.9 kB,27.9 kB
+96,Window (internal cache) / https://example.com,4,0.4 kB,20.3 kB
+15,Object (global*),2,3.9 kB,13.5 kB
+55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, setDate, getDay},4,0.8 kB,8.8 kB
+49,TypedArray,48,1.4 kB,8.8 kB
+109,Document,1,8.4 kB,8.7 kB
+50,Error,48,1.3 kB,7.9 kB
+47,Math,4,0.8 kB,7.8 kB
+19,Array,8,1.1 kB,7.7 kB
+39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, get length},4,0.6 kB,7.0 kB
+10,HTMLDocument,1,3.3 kB,6.2 kB
+44,console,4,0.5 kB,6.2 kB
+32,String,4,1.0 kB,6.1 kB
+68,DataView,4,0.5 kB,5.5 kB
+105,HTMLElement,1,4.7 kB,4.8 kB
+62,Intl.Locale,4,0.3 kB,4.7 kB
+104,Element,1,4.2 kB,4.5 kB
+76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getFileName, getFunction},4,0.5 kB,4.4 kB
+45,Intl,4,0.3 kB,4.2 kB
+25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, some, every, find},4,0.3 kB,3.6 kB
+89,system / Context,116,2.5 kB,3.5 kB
+43,Atomics,4,0.3 kB,3.1 kB
+91,DisposableStack,4,0.2 kB,3.0 kB
+92,AsyncDisposableStack,4,0.2 kB,3.0 kB
+46,Reflect,4,0.3 kB,2.5 kB
+72,ArrayBuffer,4,0.2 kB,2.2 kB
+9,Window / https://example.com,1,0.9 kB,1.9 kB
+37,WebAssembly,4,0.4 kB,1.9 kB
+58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get first, next, get next},4,0.1 kB,1.8 kB
+103,Node,1,1.8 kB,1.8 kB
+126,Performance,1,1.0 kB,1.8 kB
+30,Set,4,0.4 kB,1.6 kB
+40,{constructor},14,0.4 kB,1.6 kB
+90,SharedArrayBuffer,4,0.1 kB,1.6 kB
+56,Intl.NumberFormat,4,0.2 kB,1.5 kB
+66,Intl.DateTimeFormat,4,0.2 kB,1.5 kB
+27,Map,4,0.3 kB,1.5 kB
+48,Number,4,0.2 kB,1.5 kB
+70,Symbol,4,0.2 kB,1.4 kB
+67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, keys, toReversed},4,0.3 kB,1.3 kB
+106,HTMLBodyElement (prototype) / https://example.com,1,1.2 kB,1.2 kB
+54,Object,22,0.9 kB,1.2 kB
+59,Intl.PluralRules,4,0.2 kB,1.2 kB
+60,Intl.RelativeTimeFormat,4,0.2 kB,1.2 kB
+61,Intl.ListFormat,4,0.2 kB,1.2 kB
+65,Intl.DurationFormat,4,0.2 kB,1.2 kB
+69,BigInt,4,0.2 kB,1.2 kB
+28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__, isPrototypeOf},4,0.3 kB,1.1 kB
+17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedderData, console},4,0.2 kB,1.1 kB
+130,StyleEngine,1,0.9 kB,1.1 kB
+118,CSSStyleRule,8,0.6 kB,1.0 kB
+21,Generator,4,0.2 kB,1.0 kB
+23,AsyncGenerator,4,0.2 kB,1.0 kB
+34,JSON,4,0.2 kB,1.0 kB
+35,Promise,4,0.2 kB,1.0 kB
+57,Intl.Collator,4,0.1 kB,1.0 kB
+119,CSSStyleSheet,3,0.5 kB,1.0 kB
+33,WeakMap,4,0.2 kB,1.0 kB
+52,FinalizationRegistry,4,0.1 kB,0.9 kB
+63,Intl.DisplayNames,4,0.1 kB,0.9 kB
+64,Intl.Segmenter,4,0.1 kB,0.9 kB
+73,Async-from-Sync Iterator,4,0.1 kB,0.9 kB
+22,{<symbol Symbol.asyncIterator>, <symbol Symbol.asyncDispose>},4,0.1 kB,0.9 kB
+85,{containing, <symbol Symbol.iterator>},4,0.1 kB,0.8 kB
+51,WeakRef,4,0.1 kB,0.8 kB
+79,WebAssembly.Table,4,0.2 kB,0.8 kB
+80,WebAssembly.Memory,4,0.2 kB,0.8 kB
+71,Boolean,4,0.1 kB,0.8 kB
+18,Array Iterator,4,0.1 kB,0.7 kB
+24,Iterator Helper,4,0.1 kB,0.7 kB
+26,Map Iterator,4,0.1 kB,0.7 kB
+29,Set Iterator,4,0.1 kB,0.7 kB
+31,String Iterator,4,0.1 kB,0.7 kB
+86,Segmenter String Iterator,4,0.1 kB,0.7 kB
+88,RegExp String Iterator,4,0.1 kB,0.7 kB
+20,{constructor, name, message, toString},4,0.1 kB,0.7 kB
+87,{next, return},4,0.1 kB,0.7 kB
+75,AsyncGeneratorFunction,4,0.1 kB,0.7 kB
+84,GeneratorFunction,4,0.1 kB,0.7 kB
+74,AsyncFunction,4,0.1 kB,0.6 kB
+81,WebAssembly.Global,4,0.1 kB,0.6 kB
+93,WebAssembly.Suspending,4,0.1 kB,0.6 kB
+100,{loadTimes, csi},2,0.1 kB,0.6 kB
+36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasIndices, ignoreCase},4,0.2 kB,0.6 kB
+78,WebAssembly.Instance,4,0.1 kB,0.5 kB
+83,WebAssembly.Exception,4,0.1 kB,0.5 kB
+110,Text,6,0.5 kB,0.5 kB
+77,WebAssembly.Module,4,0.1 kB,0.4 kB
+82,WebAssembly.Tag,4,0.1 kB,0.4 kB
+101,EventTarget,2,0.1 kB,0.4 kB
+53,WeakSet,4,0.2 kB,0.4 kB
+135,EventListener,10,0.4 kB,0.4 kB
+99,{parse, stringify},2,0.0 kB,0.4 kB
+127,Navigation,1,0.2 kB,0.4 kB
+4,{<symbol handler_function>, <symbol feature_name>},8,0.2 kB,0.4 kB
+134,FontFaceSet,1,0.3 kB,0.3 kB
+133,StylePropertyMap,8,0.3 kB,0.3 kB
+139,MutationObserver,2,0.3 kB,0.3 kB
+102,WindowProperties,2,0.1 kB,0.3 kB
+115,<style>,1,0.1 kB,0.3 kB
+123,IntersectionObserver,1,0.2 kB,0.2 kB
+132,MutationObserver::Delegate,2,0.1 kB,0.2 kB
+131,ScriptedAnimationController,1,0.2 kB,0.2 kB
+95,MutationObserver (prototype) / https://example.com,1,0.2 kB,0.2 kB
+7,(number),16,0.2 kB,0.2 kB
+120,NavigationHistoryEntry,1,0.2 kB,0.2 kB
+129,StyleSheetCollection,1,0.2 kB,0.2 kB
+147,<a>,1,0.1 kB,0.2 kB
+146,DocumentTimeline,1,0.2 kB,0.2 kB
+5,RegExp,1,0.1 kB,0.2 kB
+114,<title>,1,0.1 kB,0.2 kB
+116,PerformancePaintTiming,2,0.2 kB,0.2 kB
+145,<p>,2,0.2 kB,0.2 kB
+111,<div>,1,0.1 kB,0.2 kB
+122,ServiceWorkerContainer,1,0.2 kB,0.2 kB
+125,Navigator,1,0.2 kB,0.2 kB
+155,PerformanceNavigationTiming,1,0.2 kB,0.2 kB
+113,<head>,1,0.1 kB,0.2 kB
+98,HTMLDocument (prototype) / https://example.com,1,0.1 kB,0.1 kB
+117,PerformanceResourceTiming,1,0.1 kB,0.1 kB
+152,LargestContentfulPaint,1,0.1 kB,0.1 kB
+38,Tag,4,0.1 kB,0.1 kB
+136,CustomElementRegistry,1,0.1 kB,0.1 kB
+138,CSSRuleList,4,0.1 kB,0.1 kB
+141,Storage,2,0.1 kB,0.1 kB
+13,<body>,1,0.1 kB,0.1 kB
+14,Object (global),2,0.0 kB,0.1 kB
+121,DOMTokenList,2,0.1 kB,0.1 kB
+148,HTMLCollection,1,0.1 kB,0.1 kB
+150,ScriptRunner,1,0.1 kB,0.1 kB
+112,<meta>,1,0.1 kB,0.1 kB
+41,(concatenated string),2,0.0 kB,0.1 kB
+140,<html>,1,0.1 kB,0.1 kB
+144,<h1>,1,0.1 kB,0.1 kB
+149,Screen,1,0.1 kB,0.1 kB
+153,DocumentType,1,0.1 kB,0.1 kB
+156,VisibilityStateEntry,1,0.1 kB,0.1 kB
+137,MutationObserverRegistration,1,0.1 kB,0.1 kB
+8,Window (global) / https://example.com,1,0.0 kB,0.1 kB
+151,FragmentDirective,1,0.1 kB,0.1 kB
+124,IntersectionObserverDelegate,1,0.0 kB,0.0 kB
+128,NavigationActivation,1,0.0 kB,0.0 kB
+154,PerformanceTiming,1,0.0 kB,0.0 kB
+157,Pending activities,1,0.0 kB,0.0 kB
+142,VisualViewport,1,0.0 kB,0.0 kB
+143,Viewport,1,0.0 kB,0.0 kB
+12,HTMLBodyElement,1,0.0 kB,0.0 kB
+97,HTMLDocument (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+107,MutationObserver (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+108,HTMLBodyElement (internal cache) / https://example.com,1,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with objectsRetainedByContexts filterName 1`] = `
+id,name,count,selfSize,retainedSize
+89,system / Context,116,2.5 kB,3.5 kB
+11,Function,6,0.2 kB,0.7 kB
+1,(compiled code),22,0.5 kB,0.5 kB
+19,Array,4,0.3 kB,0.3 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with sharedNativeContext filterName 1`] = `
+id,name,count,selfSize,retainedSize
+6,(string),443,16.6 kB,16.6 kB
+1,(compiled code),85,5.9 kB,9.8 kB
+2,(system),12,0.2 kB,0.6 kB
+7,(number),16,0.2 kB,0.2 kB
+41,(concatenated string),2,0.0 kB,0.1 kB
+`;
diff --git a/tests/formatters/HeapSnapshotFormatter.test.ts b/tests/formatters/HeapSnapshotFormatter.test.ts
index 625212b1..65e52a5e 100644
--- a/tests/formatters/HeapSnapshotFormatter.test.ts
+++ b/tests/formatters/HeapSnapshotFormatter.test.ts
@@ -5,10 +5,13 @@
*/
import assert from 'node:assert';
-import {describe, it} from 'node:test';
+import {join} from 'node:path';
+import {describe, it, before, after} from 'node:test';
import {HeapSnapshotFormatter} from '../../src/formatters/HeapSnapshotFormatter.js';
+import {HeapSnapshotManager} from '../../src/processors/HeapSnapshotManager.js';
import {DevTools} from '../../src/third_party/index.js';
+import {parseByteSizeRange} from '../../src/utils/bytes.js';
import {stableIdSymbol} from '../../src/utils/id.js';
const {formatBytesToKb} = DevTools.I18n.ByteUtilities;
@@ -358,4 +361,240 @@ describe('HeapSnapshotFormatter', () => {
assert.strictEqual(result, expected);
});
});
+
+ describe('with real fixtures', () => {
+ let manager: HeapSnapshotManager;
+ const examplePath = join(
+ process.cwd(),
+ 'tests/fixtures/example.heapsnapshot',
+ );
+ const heap1Path = join(process.cwd(), 'tests/fixtures/heap-1.heapsnapshot');
+ const heap2Path = join(process.cwd(), 'tests/fixtures/heap-2.heapsnapshot');
+ const heap3Path = join(process.cwd(), 'tests/fixtures/heap-3.heapsnapshot');
+
+ before(() => {
+ manager = new HeapSnapshotManager();
+ });
+
+ after(() => {
+ manager.dispose();
+ });
+
+ describe('toString with aggregates', () => {
+ it('formats aggregates with default options', async t => {
+ const data = await manager.getAggregates(examplePath);
+ const formatter = new HeapSnapshotFormatter(data.aggregates);
+ t.assert.snapshot(formatter.toString());
+ });
+
+ it('formats aggregates with objectsRetainedByContexts filterName', async t => {
+ const data = await manager.getAggregates(
+ examplePath,
+ 'objectsRetainedByContexts',
+ );
+ const formatter = new HeapSnapshotFormatter(data.aggregates);
+ t.assert.snapshot(formatter.toString());
+ });
+
+ it('formats aggregates with sharedNativeContext filterName', async t => {
+ const data = await manager.getAggregates(
+ examplePath,
+ 'sharedNativeContext',
+ );
+ const formatter = new HeapSnapshotFormatter(data.aggregates);
+ t.assert.snapshot(formatter.toString());
+ });
+
+ it('formats aggregates with attributedToSpecificNativeContext filterName and objectId', async t => {
+ const data = await manager.getAggregates(
+ examplePath,
+ 'attributedToSpecificNativeContext',
+ 7249,
+ );
+ const formatter = new HeapSnapshotFormatter(data.aggregates);
+ t.assert.snapshot(formatter.toString());
+ });
+ });
+
+ describe('formatNativeContextSizes', () => {
+ it('formats native context sizes from fixture', async t => {
+ const sizes = await manager.getNativeContextSizes(examplePath);
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNativeContextSizes(sizes),
+ );
+ });
+ });
+
+ describe('formatRetainedByContextSummary', () => {
+ it('formats retained by context summary from fixture', async t => {
+ const summary = await manager.getRetainedByContextSummary(examplePath);
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatRetainedByContextSummary(summary),
+ );
+ });
+ });
+
+ describe('formatNodes with class nodes', () => {
+ it('formats class nodes with default options', async t => {
+ await manager.getAggregates(examplePath);
+ const nodes = await manager.getNodesById(examplePath, 19);
+ t.assert.snapshot(HeapSnapshotFormatter.formatNodes(nodes.items));
+ });
+
+ it('formats class nodes with objectsRetainedByContexts filterName', async t => {
+ const aggregateData = await manager.getAggregates(
+ examplePath,
+ 'objectsRetainedByContexts',
+ );
+ const aggregate = Object.values(aggregateData.aggregates).find(
+ a => a.name === 'Function',
+ );
+ assert.ok(aggregate);
+ const id = aggregate[stableIdSymbol];
+ if (id === undefined) {
+ assert.fail('Expected class ID to be defined');
+ }
+ const nodes = await manager.getNodesById(
+ examplePath,
+ id,
+ 'objectsRetainedByContexts',
+ );
+ t.assert.snapshot(HeapSnapshotFormatter.formatNodes(nodes.items));
+ });
+ });
+
+ describe('formatNodes with retainers', () => {
+ it('formats retainers for a valid nodeId', async t => {
+ const retainers = await manager.getRetainers(examplePath, 25341);
+ t.assert.snapshot(HeapSnapshotFormatter.formatNodes(retainers.items));
+ });
+ });
+
+ describe('formatObjectInfo', () => {
+ it('formats object details for a valid nodeId', async t => {
+ const objectInfo = await manager.getObjectInfo(examplePath, 25341);
+ t.assert.snapshot(HeapSnapshotFormatter.formatObjectInfo(objectInfo));
+ });
+ });
+
+ describe('formatRetainingPaths', () => {
+ it('formats retaining paths for a valid nodeId', async t => {
+ const retainingPaths = await manager.getRetainingPaths(
+ examplePath,
+ 45901,
+ );
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatRetainingPaths(retainingPaths.paths),
+ );
+ });
+
+ it('reports when limits are reached', async () => {
+ const retainingPaths = await manager.getRetainingPaths(
+ examplePath,
+ 45901,
+ 1,
+ );
+ assert.strictEqual(retainingPaths.paths.length, 0);
+ assert.strictEqual(retainingPaths.limitsReached.depth, true);
+ });
+ });
+
+ describe('formatNodes with edges', () => {
+ it('formats outgoing edges for a valid nodeId', async t => {
+ const edges = await manager.getEdges(examplePath, 25341);
+ t.assert.snapshot(HeapSnapshotFormatter.formatNodes(edges.items));
+ });
+
+ it('formats outgoing edges with pagination', async t => {
+ const edges = await manager.getEdges(examplePath, 25341);
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNodes(edges.items.slice(0, 2)),
+ );
+ });
+
+ it('formats outgoing edges with retainedSize range', async t => {
+ const range = parseByteSizeRange('100B-100B');
+ const edges = await manager.getEdges(examplePath, 25341, {
+ minRetainedSize: range?.min,
+ });
+ t.assert.snapshot(HeapSnapshotFormatter.formatNodes(edges.items));
+ });
+ });
+
+ describe('formatDominators', () => {
+ it('formats dominator chain for a valid nodeId', async t => {
+ const dominators = await manager.getDominatorsOf(examplePath, 25341);
+ t.assert.snapshot(HeapSnapshotFormatter.formatDominators(dominators));
+ });
+ });
+
+ describe('formatDiffSummary and formatDiffDetails', () => {
+ it('formats diff summary comparing heap-1 to heap-2', async t => {
+ const diffs = await manager.getClassDiffs(heap1Path, heap2Path);
+ t.assert.snapshot(HeapSnapshotFormatter.formatDiffSummary(diffs));
+ });
+
+ it('formats diff summary comparing heap-2 to heap-3', async t => {
+ const diffs = await manager.getClassDiffs(heap2Path, heap3Path);
+ t.assert.snapshot(HeapSnapshotFormatter.formatDiffSummary(diffs));
+ });
+
+ it('formats detailed diff comparing heap-1 to heap-2 with classIndex filter', async t => {
+ const detailedDiff = await manager.getDetailedClassDiff(
+ heap1Path,
+ heap2Path,
+ 2,
+ );
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatDiffDetails(detailedDiff),
+ );
+ });
+ });
+
+ describe('formatDuplicateStrings', () => {
+ it('formats duplicate strings with default options', async t => {
+ const duplicateStrings = await manager.getDuplicateStrings(examplePath);
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatDuplicateStrings(duplicateStrings),
+ );
+ });
+ });
+
+ describe('formatNodes with queryObjects', () => {
+ it('formats queried objects with default options', async t => {
+ const objects = await manager.queryObjects(examplePath, {});
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNodes(objects.items.slice(0, 10)),
+ );
+ });
+
+ it('formats queried objects with className filter', async t => {
+ const objects = await manager.queryObjects(examplePath, {
+ className: 'Window',
+ });
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNodes(objects.items.slice(0, 10)),
+ );
+ });
+
+ it('formats queried objects with an unbounded retainedSize filter', async t => {
+ const range = parseByteSizeRange('1KB');
+ const objects = await manager.queryObjects(examplePath, {
+ minRetainedSize: range?.min,
+ });
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNodes(objects.items.slice(0, 10)),
+ );
+ });
+
+ it('formats queried objects with sortBy selfSize and pagination', async t => {
+ const objects = await manager.queryObjects(examplePath, {
+ sortBy: 'selfSize',
+ });
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatNodes(objects.items.slice(0, 5)),
+ );
+ });
+ });
+ });
});
diff --git a/tests/mocks.ts b/tests/mocks.ts
index 98c747d7..cbca6c19 100644
--- a/tests/mocks.ts
+++ b/tests/mocks.ts
@@ -25,9 +25,18 @@
import type {Frame} from 'puppeteer-core';
import sinon from 'sinon';
+import {type ParsedArguments, parser} from '../src/config/mcp-options.js';
import {McpContext} from '../src/McpContext.js';
import {McpPage} from '../src/McpPage.js';
import {McpResponse} from '../src/McpResponse.js';
+import type {
+ AggregatedInfoWithId,
+ DuplicateStringGroup,
+ HeapSnapshotAggregateData,
+ HeapSnapshotClassDiff,
+ HeapSnapshotDetailedClassDiff,
+} from '../src/processors/HeapSnapshotManager.js';
+import {stableIdSymbol} from '../src/utils/id.js';
import {
CdpExtension,
CdpFrame,
@@ -680,3 +689,178 @@ export function createMockExtension(
sinon.stub(extension, 'enabled').value(options.enabled ?? true);
return extension as unknown as Extension;
}
+
+export function createMockHeapSnapshotStats(): DevTools.HeapSnapshotModel.HeapSnapshotModel.Statistics {
+ return {
+ total: 1000,
+ native: {total: 200, typedArrays: 50},
+ v8heap: {
+ total: 800,
+ code: 50,
+ jsArrays: 150,
+ strings: 200,
+ system: 400,
+ },
+ };
+}
+
+export function createMockHeapSnapshotStaticData(): DevTools.HeapSnapshotModel.HeapSnapshotModel.StaticData {
+ return new DevTools.HeapSnapshotModel.HeapSnapshotModel.StaticData(
+ 10,
+ 0,
+ 1000,
+ 100,
+ );
+}
+
+export function createMockNativeContextSizes(): DevTools.HeapSnapshotModel.HeapSnapshotModel.NativeContextSizes {
+ return {
+ nativeContexts: [],
+ sharedSize: 0,
+ noAttributionSize: 0,
+ };
+}
+
+export function createMockRetainedByContextSummary(): DevTools.HeapSnapshotModel.HeapSnapshotModel.RetainedByContextSummary {
+ return {
+ contextCount: 0,
+ retainedByContextSize: 0,
+ retainedByContextCount: 0,
+ notRetainedByContextSize: 0,
+ notRetainedByContextCount: 0,
+ totalSize: 0,
+ };
+}
+
+export function createMockHeapSnapshotAggregateData(): HeapSnapshotAggregateData {
+ return {
+ aggregates: {},
+ objectCount: 0,
+ totalSelfSize: 0,
+ };
+}
+
+export function createMockItemsRange(): DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange {
+ return new DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange(
+ 0,
+ 0,
+ 0,
+ [],
+ );
+}
+
+export function createMockRetainingPaths(): DevTools.HeapSnapshotModel.HeapSnapshotModel.RetainingPaths {
+ return {
+ paths: [],
+ limitsReached: {
+ depth: false,
+ nodes: false,
+ siblings: false,
+ },
+ };
+}
+
+export function createMockDominatorChain(): DevTools.HeapSnapshotModel.HeapSnapshotModel.DominatorChain {
+ return [];
+}
+
+export function createMockClassDiffs(): HeapSnapshotClassDiff[] {
+ return [
+ {
+ className: 'TestClass',
+ addedCount: 1,
+ removedCount: 0,
+ countDelta: 1,
+ addedSize: 10,
+ removedSize: 0,
+ sizeDelta: 10,
+ },
+ ];
+}
+
+export function createMockDetailedClassDiff(): HeapSnapshotDetailedClassDiff {
+ return {
+ className: 'TestClass',
+ addedCount: 1,
+ removedCount: 0,
+ countDelta: 1,
+ addedSize: 10,
+ removedSize: 0,
+ sizeDelta: 10,
+ addedIds: [1],
+ addedSelfSizes: [10],
+ deletedIds: [],
+ deletedSelfSizes: [],
+ };
+}
+
+export function createMockDuplicateStrings(): DuplicateStringGroup[] {
+ return [];
+}
+
+export function createMockObjectInfo(): DevTools.HeapSnapshotModel.HeapSnapshotModel.ObjectInfo {
+ return {
+ id: 1,
+ nodeIndex: 0,
+ name: 'Object',
+ type: 'object',
+ selfSize: 100,
+ retainedSize: 200,
+ distance: 1,
+ edgeCount: 2,
+ retainerCount: 1,
+ detachedness:
+ DevTools.HeapSnapshotModel.HeapSnapshotModel.DOMLinkState.ATTACHED,
+ };
+}
+
+export function createMockParsedArguments(
+ options: Partial<ParsedArguments> = {},
+): ParsedArguments {
+ const defaultArgs = parser('0.0.0', ['node', 'main.js']).parseSync();
+ return {...defaultArgs, ...options};
+}
+
+export function createMockHeapSnapshotNode(
+ options: Partial<DevTools.HeapSnapshotModel.HeapSnapshotModel.Node> = {},
+): DevTools.HeapSnapshotModel.HeapSnapshotModel.Node {
+ return {
+ id: options.id ?? 1,
+ name: options.name ?? 'Node',
+ distance: options.distance ?? 1,
+ nodeIndex: options.nodeIndex ?? 0,
+ retainedSize: options.retainedSize ?? 100,
+ selfSize: options.selfSize ?? 10,
+ type: options.type ?? 'object',
+ canBeQueried: options.canBeQueried ?? false,
+ detachedDOMTreeNode: options.detachedDOMTreeNode ?? false,
+ ignored: options.ignored ?? false,
+ isAddedNotRemoved: options.isAddedNotRemoved ?? null,
+ };
+}
+
+export function createMockHeapSnapshotEdge(
+ options: Partial<DevTools.HeapSnapshotModel.HeapSnapshotModel.Edge> = {},
+): DevTools.HeapSnapshotModel.HeapSnapshotModel.Edge {
+ return {
+ name: options.name ?? 'edge',
+ type: options.type ?? 'property',
+ edgeIndex: options.edgeIndex ?? 0,
+ isAddedNotRemoved: options.isAddedNotRemoved ?? null,
+ node: options.node ?? createMockHeapSnapshotNode(),
+ };
+}
+
+export function createMockAggregatedInfo(
+ options: Partial<AggregatedInfoWithId> = {},
+): AggregatedInfoWithId {
+ return {
+ count: options.count ?? 1,
+ distance: options.distance ?? 1,
+ self: options.self ?? 10,
+ maxRet: options.maxRet ?? 100,
+ name: options.name ?? 'Object',
+ idxs: options.idxs ?? [],
+ [stableIdSymbol]: options[stableIdSymbol] ?? 1,
+ };
+}
diff --git a/tests/processors/HeapSnapshotManager.test.ts b/tests/processors/HeapSnapshotManager.test.ts
index f86e76a4..ee730488 100644
--- a/tests/processors/HeapSnapshotManager.test.ts
+++ b/tests/processors/HeapSnapshotManager.test.ts
@@ -45,4 +45,83 @@ describe('HeapSnapshotManager', () => {
sinon.assert.calledOnce(disposeSpy);
});
+
+ // Verifies that the caching mechanism in HeapSnapshotManager correctly
+ // distinguishes comparisons when the same "current" snapshot is compared
+ // against different "base" snapshots. If the cache key (diffCacheKey) is
+ // not unique per base snapshot, the second comparison might incorrectly
+ // return cached results from the first comparison.
+ it('compares the same current snapshot against different bases', async () => {
+ const manager = new HeapSnapshotManager();
+ try {
+ const filePathA = 'tests/fixtures/heap-1.heapsnapshot';
+ const filePathB = 'tests/fixtures/heap-2.heapsnapshot';
+ const filePathC = 'tests/fixtures/heap-3.heapsnapshot';
+
+ const firstDiff = await manager.getClassDiffs(filePathA, filePathC);
+ const secondDiff = await manager.getClassDiffs(filePathB, filePathC);
+ const firstNewObjectDiff = firstDiff.find(
+ entry => entry.className === 'NewObject',
+ );
+ const secondNewObjectDiff = secondDiff.find(
+ entry => entry.className === 'NewObject',
+ );
+ assert.ok(firstNewObjectDiff);
+ assert.ok(secondNewObjectDiff);
+ assert.equal(firstNewObjectDiff.addedCount, 7);
+ assert.equal(secondNewObjectDiff.addedCount, 5);
+ } finally {
+ manager.dispose();
+ }
+ });
+
+ it('throws when getNodesById is called with a non-existent class ID', async () => {
+ const manager = new HeapSnapshotManager();
+ try {
+ const filePath = 'tests/fixtures/example.heapsnapshot';
+ await manager.getAggregates(filePath);
+
+ await assert.rejects(manager.getNodesById(filePath, 999999), {
+ message: 'Class with ID 999999 not found in heap snapshot',
+ });
+ } finally {
+ manager.dispose();
+ }
+ });
+
+ it('throws when getDetailedClassDiff is called with an invalid classIndex', async () => {
+ const manager = new HeapSnapshotManager();
+ try {
+ const filePathA = 'tests/fixtures/heap-1.heapsnapshot';
+ const filePathB = 'tests/fixtures/heap-2.heapsnapshot';
+
+ await assert.rejects(
+ manager.getDetailedClassDiff(filePathA, filePathB, 99),
+ /Invalid classIndex: 99. Total classes with changes: 10/,
+ );
+ } finally {
+ manager.dispose();
+ }
+ });
+
+ it('gets stats and staticData, and disposes snapshot', async () => {
+ const manager = new HeapSnapshotManager();
+ try {
+ const filePath = 'tests/fixtures/example.heapsnapshot';
+ const stats = await manager.getStats(filePath);
+ assert.ok(stats.total > 0);
+ assert.ok(stats.v8heap.total > 0);
+
+ const staticData = await manager.getStaticData(filePath);
+ assert.ok(staticData);
+ assert.ok(staticData.nodeCount > 0);
+
+ assert.strictEqual(manager.hasSnapshots(), true);
+ assert.strictEqual(manager.disposeSnapshot(filePath), true);
+ assert.strictEqual(manager.disposeSnapshot(filePath), false);
+ assert.strictEqual(manager.hasSnapshots(), false);
+ } finally {
+ manager.dispose();
+ }
+ });
});
diff --git a/tests/tools/memory.test.js.snapshot b/tests/tools/memory.test.js.snapshot
deleted file mode 100644
index dd9295e4..00000000
--- a/tests/tools/memory.test.js.snapshot
+++ /dev/null
@@ -1,523 +0,0 @@
-exports[`memory > compare_heapsnapshots > compare heap-1 to heap-2 1`] = `
-## Heap Snapshot Data
-### Heap Snapshot Diff
-index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
-0,(object shape),11,1,10,0.4 kB,0.0 kB,0.4 kB
-1,(compiled code),7,1,6,0.3 kB,0.0 kB,0.2 kB
-2,NewObject,2,0,2,0.1 kB,0.0 kB,0.1 kB
-3,(concatenated string),45,43,2,0.9 kB,0.9 kB,0.0 kB
-4,Array,2,0,2,0.0 kB,0.0 kB,0.0 kB
-5,{constructor},1,0,1,0.0 kB,0.0 kB,0.0 kB
-6,(string),4,4,0,0.1 kB,0.1 kB,0.0 kB
-7,(number),0,2,-2,0.0 kB,0.0 kB,-0.0 kB
-8,Object,0,2,-2,0.0 kB,0.0 kB,-0.0 kB
-9,InitialObject,0,2,-2,0.0 kB,0.1 kB,-0.1 kB
-`;
-
-exports[`memory > compare_heapsnapshots > compare heap-1 to heap-2 with classIndex filter 1`] = `
-## Heap Snapshot Data
-### Heap Snapshot Detailed Diff
-NewObject: # new: 2, # deleted: 0, # delta: +2, alloc size: +0.1 kB, freed size: 0.0 kB, size delta: +0.1 kB
-Objects:
- + @35179 (self_size: 0.1 kB)
- + @35181 (self_size: 0.1 kB)
-`;
-
-exports[`memory > compare_heapsnapshots > compare heap-2 to heap-3 1`] = `
-## Heap Snapshot Data
-### Heap Snapshot Diff
-index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
-0,(concatenated string),105,0,105,2.1 kB,0.0 kB,2.1 kB
-1,(object shape),7,1,6,0.3 kB,0.1 kB,0.3 kB
-2,(string),10,0,10,0.2 kB,0.0 kB,0.2 kB
-3,NewObject,5,0,5,0.1 kB,0.0 kB,0.1 kB
-4,Array,5,0,5,0.1 kB,0.0 kB,0.1 kB
-5,system / PropertyArray,1,0,1,0.0 kB,0.0 kB,0.0 kB
-`;
-
-exports[`memory > get_heapsnapshot_class_nodes > with default options 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-25307,Array,object,2,0.2 kB,2.1 kB
-46355,Array,object,2,0.2 kB,2.1 kB
-33187,Array,object,2,0.2 kB,1.7 kB
-36255,Array,object,2,0.2 kB,1.7 kB
-45901,Array,object,5,0.1 kB,0.1 kB
-46151,Array,object,5,0.1 kB,0.1 kB
-45899,Array,object,5,0.1 kB,0.1 kB
-46149,Array,object,5,0.1 kB,0.1 kB
-Showing 1-8 of 8 (Page 1 of 1).
-`;
-
-exports[`memory > get_heapsnapshot_class_nodes > with objectsRetainedByContexts filterName 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-45897,makeCallable,closure,5,0.0 kB,0.2 kB
-46147,makeCallable,closure,5,0.0 kB,0.2 kB
-45893,Apply,closure,5,0.0 kB,0.0 kB
-45895,Save,closure,5,0.0 kB,0.0 kB
-46143,Apply,closure,5,0.0 kB,0.0 kB
-46145,Save,closure,5,0.0 kB,0.0 kB
-Showing 1-6 of 6 (Page 1 of 1).
-`;
-
-exports[`memory > get_heapsnapshot_details > with attributedToSpecificNativeContext filterName and objectId 1`] = `
-## Heap Snapshot Data
-Objects: 4589
-Total shallow size: 350 kB
-Showing 1-10 of 150 (Page 1 of 15).
-Next page: 1
-id,name,count,selfSize,retainedSize
-1,(system),1739,115 kB,350 kB
-7,Function,1095,34.9 kB,72.2 kB
-11,(object shape),769,52.6 kB,53.3 kB
-10,Window (global*) / https://example.com,1,40.5 kB,51.0 kB
-36,(array),6,9.1 kB,46.0 kB
-17,Window (prototype) / https://example.com,2,26.7 kB,26.9 kB
-4,(compiled code),323,19.3 kB,19.4 kB
-3,(string),376,10.5 kB,10.5 kB
-19,Window (internal cache) / https://example.com,2,0.2 kB,10.1 kB
-72,Document,1,8.4 kB,8.7 kB
-`;
-
-exports[`memory > get_heapsnapshot_details > with default options 1`] = `
-## Heap Snapshot Data
-Objects: 11940
-Total shallow size: 802 kB
-Showing 1-157 of 157 (Page 1 of 1).
-id,name,count,selfSize,retainedSize
-2,(system),3205,199 kB,655 kB
-11,Function,3581,111 kB,237 kB
-16,(object shape),2878,181 kB,184 kB
-3,(array),34,41.4 kB,117 kB
-42,Window (global*) / https://example.com,2,81.1 kB,102 kB
-94,Window (prototype) / https://example.com,4,53.3 kB,53.7 kB
-1,(compiled code),713,42.8 kB,47.0 kB
-6,(string),846,27.9 kB,27.9 kB
-96,Window (internal cache) / https://example.com,4,0.4 kB,20.3 kB
-15,Object (global*),2,3.9 kB,13.5 kB
-55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, setDate, getDay},4,0.8 kB,8.8 kB
-49,TypedArray,48,1.4 kB,8.8 kB
-109,Document,1,8.4 kB,8.7 kB
-50,Error,48,1.3 kB,7.9 kB
-47,Math,4,0.8 kB,7.8 kB
-19,Array,8,1.1 kB,7.7 kB
-39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, get length},4,0.6 kB,7.0 kB
-10,HTMLDocument,1,3.3 kB,6.2 kB
-44,console,4,0.5 kB,6.2 kB
-32,String,4,1.0 kB,6.1 kB
-68,DataView,4,0.5 kB,5.5 kB
-105,HTMLElement,1,4.7 kB,4.8 kB
-62,Intl.Locale,4,0.3 kB,4.7 kB
-104,Element,1,4.2 kB,4.5 kB
-76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getFileName, getFunction},4,0.5 kB,4.4 kB
-45,Intl,4,0.3 kB,4.2 kB
-25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, some, every, find},4,0.3 kB,3.6 kB
-89,system / Context,116,2.5 kB,3.5 kB
-43,Atomics,4,0.3 kB,3.1 kB
-91,DisposableStack,4,0.2 kB,3.0 kB
-92,AsyncDisposableStack,4,0.2 kB,3.0 kB
-46,Reflect,4,0.3 kB,2.5 kB
-72,ArrayBuffer,4,0.2 kB,2.2 kB
-9,Window / https://example.com,1,0.9 kB,1.9 kB
-37,WebAssembly,4,0.4 kB,1.9 kB
-58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get first, next, get next},4,0.1 kB,1.8 kB
-103,Node,1,1.8 kB,1.8 kB
-126,Performance,1,1.0 kB,1.8 kB
-30,Set,4,0.4 kB,1.6 kB
-40,{constructor},14,0.4 kB,1.6 kB
-90,SharedArrayBuffer,4,0.1 kB,1.6 kB
-56,Intl.NumberFormat,4,0.2 kB,1.5 kB
-66,Intl.DateTimeFormat,4,0.2 kB,1.5 kB
-27,Map,4,0.3 kB,1.5 kB
-48,Number,4,0.2 kB,1.5 kB
-70,Symbol,4,0.2 kB,1.4 kB
-67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, keys, toReversed},4,0.3 kB,1.3 kB
-106,HTMLBodyElement (prototype) / https://example.com,1,1.2 kB,1.2 kB
-54,Object,22,0.9 kB,1.2 kB
-59,Intl.PluralRules,4,0.2 kB,1.2 kB
-60,Intl.RelativeTimeFormat,4,0.2 kB,1.2 kB
-61,Intl.ListFormat,4,0.2 kB,1.2 kB
-65,Intl.DurationFormat,4,0.2 kB,1.2 kB
-69,BigInt,4,0.2 kB,1.2 kB
-28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__, isPrototypeOf},4,0.3 kB,1.1 kB
-17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedderData, console},4,0.2 kB,1.1 kB
-130,StyleEngine,1,0.9 kB,1.1 kB
-118,CSSStyleRule,8,0.6 kB,1.0 kB
-21,Generator,4,0.2 kB,1.0 kB
-23,AsyncGenerator,4,0.2 kB,1.0 kB
-34,JSON,4,0.2 kB,1.0 kB
-35,Promise,4,0.2 kB,1.0 kB
-57,Intl.Collator,4,0.1 kB,1.0 kB
-119,CSSStyleSheet,3,0.5 kB,1.0 kB
-33,WeakMap,4,0.2 kB,1.0 kB
-52,FinalizationRegistry,4,0.1 kB,0.9 kB
-63,Intl.DisplayNames,4,0.1 kB,0.9 kB
-64,Intl.Segmenter,4,0.1 kB,0.9 kB
-73,Async-from-Sync Iterator,4,0.1 kB,0.9 kB
-22,{<symbol Symbol.asyncIterator>, <symbol Symbol.asyncDispose>},4,0.1 kB,0.9 kB
-85,{containing, <symbol Symbol.iterator>},4,0.1 kB,0.8 kB
-51,WeakRef,4,0.1 kB,0.8 kB
-79,WebAssembly.Table,4,0.2 kB,0.8 kB
-80,WebAssembly.Memory,4,0.2 kB,0.8 kB
-71,Boolean,4,0.1 kB,0.8 kB
-18,Array Iterator,4,0.1 kB,0.7 kB
-24,Iterator Helper,4,0.1 kB,0.7 kB
-26,Map Iterator,4,0.1 kB,0.7 kB
-29,Set Iterator,4,0.1 kB,0.7 kB
-31,String Iterator,4,0.1 kB,0.7 kB
-86,Segmenter String Iterator,4,0.1 kB,0.7 kB
-88,RegExp String Iterator,4,0.1 kB,0.7 kB
-20,{constructor, name, message, toString},4,0.1 kB,0.7 kB
-87,{next, return},4,0.1 kB,0.7 kB
-75,AsyncGeneratorFunction,4,0.1 kB,0.7 kB
-84,GeneratorFunction,4,0.1 kB,0.7 kB
-74,AsyncFunction,4,0.1 kB,0.6 kB
-81,WebAssembly.Global,4,0.1 kB,0.6 kB
-93,WebAssembly.Suspending,4,0.1 kB,0.6 kB
-100,{loadTimes, csi},2,0.1 kB,0.6 kB
-36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasIndices, ignoreCase},4,0.2 kB,0.6 kB
-78,WebAssembly.Instance,4,0.1 kB,0.5 kB
-83,WebAssembly.Exception,4,0.1 kB,0.5 kB
-110,Text,6,0.5 kB,0.5 kB
-77,WebAssembly.Module,4,0.1 kB,0.4 kB
-82,WebAssembly.Tag,4,0.1 kB,0.4 kB
-101,EventTarget,2,0.1 kB,0.4 kB
-53,WeakSet,4,0.2 kB,0.4 kB
-135,EventListener,10,0.4 kB,0.4 kB
-99,{parse, stringify},2,0.0 kB,0.4 kB
-127,Navigation,1,0.2 kB,0.4 kB
-4,{<symbol handler_function>, <symbol feature_name>},8,0.2 kB,0.4 kB
-134,FontFaceSet,1,0.3 kB,0.3 kB
-133,StylePropertyMap,8,0.3 kB,0.3 kB
-139,MutationObserver,2,0.3 kB,0.3 kB
-102,WindowProperties,2,0.1 kB,0.3 kB
-115,<style>,1,0.1 kB,0.3 kB
-123,IntersectionObserver,1,0.2 kB,0.2 kB
-132,MutationObserver::Delegate,2,0.1 kB,0.2 kB
-131,ScriptedAnimationController,1,0.2 kB,0.2 kB
-95,MutationObserver (prototype) / https://example.com,1,0.2 kB,0.2 kB
-7,(number),16,0.2 kB,0.2 kB
-120,NavigationHistoryEntry,1,0.2 kB,0.2 kB
-129,StyleSheetCollection,1,0.2 kB,0.2 kB
-147,<a>,1,0.1 kB,0.2 kB
-146,DocumentTimeline,1,0.2 kB,0.2 kB
-5,RegExp,1,0.1 kB,0.2 kB
-114,<title>,1,0.1 kB,0.2 kB
-116,PerformancePaintTiming,2,0.2 kB,0.2 kB
-145,<p>,2,0.2 kB,0.2 kB
-111,<div>,1,0.1 kB,0.2 kB
-122,ServiceWorkerContainer,1,0.2 kB,0.2 kB
-125,Navigator,1,0.2 kB,0.2 kB
-155,PerformanceNavigationTiming,1,0.2 kB,0.2 kB
-113,<head>,1,0.1 kB,0.2 kB
-98,HTMLDocument (prototype) / https://example.com,1,0.1 kB,0.1 kB
-117,PerformanceResourceTiming,1,0.1 kB,0.1 kB
-152,LargestContentfulPaint,1,0.1 kB,0.1 kB
-38,Tag,4,0.1 kB,0.1 kB
-136,CustomElementRegistry,1,0.1 kB,0.1 kB
-138,CSSRuleList,4,0.1 kB,0.1 kB
-141,Storage,2,0.1 kB,0.1 kB
-13,<body>,1,0.1 kB,0.1 kB
-14,Object (global),2,0.0 kB,0.1 kB
-121,DOMTokenList,2,0.1 kB,0.1 kB
-148,HTMLCollection,1,0.1 kB,0.1 kB
-150,ScriptRunner,1,0.1 kB,0.1 kB
-112,<meta>,1,0.1 kB,0.1 kB
-41,(concatenated string),2,0.0 kB,0.1 kB
-140,<html>,1,0.1 kB,0.1 kB
-144,<h1>,1,0.1 kB,0.1 kB
-149,Screen,1,0.1 kB,0.1 kB
-153,DocumentType,1,0.1 kB,0.1 kB
-156,VisibilityStateEntry,1,0.1 kB,0.1 kB
-137,MutationObserverRegistration,1,0.1 kB,0.1 kB
-8,Window (global) / https://example.com,1,0.0 kB,0.1 kB
-151,FragmentDirective,1,0.1 kB,0.1 kB
-124,IntersectionObserverDelegate,1,0.0 kB,0.0 kB
-128,NavigationActivation,1,0.0 kB,0.0 kB
-154,PerformanceTiming,1,0.0 kB,0.0 kB
-157,Pending activities,1,0.0 kB,0.0 kB
-142,VisualViewport,1,0.0 kB,0.0 kB
-143,Viewport,1,0.0 kB,0.0 kB
-12,HTMLBodyElement,1,0.0 kB,0.0 kB
-97,HTMLDocument (internal cache) / https://example.com,1,0.0 kB,0.0 kB
-107,MutationObserver (internal cache) / https://example.com,1,0.0 kB,0.0 kB
-108,HTMLBodyElement (internal cache) / https://example.com,1,0.0 kB,0.0 kB
-`;
-
-exports[`memory > get_heapsnapshot_details > with objectsRetainedByContexts filterName 1`] = `
-## Heap Snapshot Data
-Objects: 148
-Total shallow size: 3.5 kB
-Showing 1-4 of 4 (Page 1 of 1).
-id,name,count,selfSize,retainedSize
-1,system / Context,116,2.5 kB,3.5 kB
-3,Function,6,0.2 kB,0.7 kB
-2,(compiled code),22,0.5 kB,0.5 kB
-4,Array,4,0.3 kB,0.3 kB
-`;
-
-exports[`memory > get_heapsnapshot_details > with sharedNativeContext filterName 1`] = `
-## Heap Snapshot Data
-Objects: 558
-Total shallow size: 22.9 kB
-Showing 1-5 of 5 (Page 1 of 1).
-id,name,count,selfSize,retainedSize
-3,(string),443,16.6 kB,16.6 kB
-1,(compiled code),85,5.9 kB,9.8 kB
-4,(system),12,0.2 kB,0.6 kB
-2,(number),16,0.2 kB,0.2 kB
-5,(concatenated string),2,0.0 kB,0.1 kB
-`;
-
-exports[`memory > get_heapsnapshot_dominators > with valid nodeId 1`] = `
-## Heap Snapshot Data
-### Dominator Chain
-nodeId,nodeName,selfSize,retainedSize
-25341,String,0.2 kB,1.6 kB
-7199,system / NativeContext,1.2 kB,84.4 kB
-1,,0.0 kB,802 kB
-`;
-
-exports[`memory > get_heapsnapshot_duplicate_strings > with default options 1`] = `
-## Heap Snapshot Data
-### Duplicate Strings
-Showing 1-7 of 7 (Page 1 of 1).
-value,count,totalSelfSize,totalRetainedSize,truncated,nodeIds
-"get disposed",8,0.2 kB,0.2 kB,false,@30685 @30731 @33713 @33781 @42891 @42947 @45203 @45233
-"WebAssembly.Suspending",4,0.1 kB,0.1 kB,false,@44967 @45473 @46069 @46195
-"extensions::SafeBuiltins",2,0.1 kB,0.1 kB,false,@25155 @26209
-"WebAssembly",2,0.0 kB,0.0 kB,false,@7495 @15037
-"EventTarget",2,0.0 kB,0.0 kB,false,@25089 @26185
-"v8/LoadTimes",2,0.0 kB,0.0 kB,false,@25159 @26365
-"Document",2,0.0 kB,0.0 kB,false,@25969 @26603
-`;
-
-exports[`memory > get_heapsnapshot_edges > with pagination 1`] = `
-## Heap Snapshot Data
-name,type,nodeId,nodeName,selfSize,retainedSize
-map,internal,25577,system / Map,0.0 kB,0.7 kB
-constructor,property,25575,String,0.1 kB,0.4 kB
-Showing 1-2 of 56 (Page 1 of 28).
-Next page: 1
-`;
-
-exports[`memory > get_heapsnapshot_edges > with retainedSize range 1`] = `
-## Heap Snapshot Data
-name,type,nodeId,nodeName,selfSize,retainedSize
-map,internal,25577,system / Map,0.0 kB,0.7 kB
-constructor,property,25575,String,0.1 kB,0.4 kB
-__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
-Showing 1-3 of 3 (Page 1 of 1).
-`;
-
-exports[`memory > get_heapsnapshot_edges > with valid nodeId 1`] = `
-## Heap Snapshot Data
-name,type,nodeId,nodeName,selfSize,retainedSize
-map,internal,25577,system / Map,0.0 kB,0.7 kB
-constructor,property,25575,String,0.1 kB,0.4 kB
-__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
-<symbol Symbol.iterator>,property,29391,[Symbol.iterator],0.0 kB,0.0 kB
-anchor,property,29295,anchor,0.0 kB,0.0 kB
-at,property,29297,at,0.0 kB,0.0 kB
-big,property,29299,big,0.0 kB,0.0 kB
-blink,property,29301,blink,0.0 kB,0.0 kB
-bold,property,29303,bold,0.0 kB,0.0 kB
-charAt,property,29305,charAt,0.0 kB,0.0 kB
-charCodeAt,property,29307,charCodeAt,0.0 kB,0.0 kB
-codePointAt,property,29309,codePointAt,0.0 kB,0.0 kB
-concat,property,29311,concat,0.0 kB,0.0 kB
-endsWith,property,29313,endsWith,0.0 kB,0.0 kB
-fixed,property,29319,fixed,0.0 kB,0.0 kB
-fontcolor,property,29315,fontcolor,0.0 kB,0.0 kB
-fontsize,property,29317,fontsize,0.0 kB,0.0 kB
-includes,property,29321,includes,0.0 kB,0.0 kB
-indexOf,property,29323,indexOf,0.0 kB,0.0 kB
-isWellFormed,property,29325,isWellFormed,0.0 kB,0.0 kB
-italics,property,29327,italics,0.0 kB,0.0 kB
-lastIndexOf,property,29329,lastIndexOf,0.0 kB,0.0 kB
-link,property,29331,link,0.0 kB,0.0 kB
-localeCompare,property,29333,localeCompare,0.0 kB,0.0 kB
-match,property,29335,match,0.0 kB,0.0 kB
-matchAll,property,29337,matchAll,0.0 kB,0.0 kB
-normalize,property,29339,normalize,0.0 kB,0.0 kB
-padEnd,property,29341,padEnd,0.0 kB,0.0 kB
-padStart,property,29343,padStart,0.0 kB,0.0 kB
-repeat,property,29345,repeat,0.0 kB,0.0 kB
-replace,property,29347,replace,0.0 kB,0.0 kB
-replaceAll,property,29349,replaceAll,0.0 kB,0.0 kB
-search,property,29351,search,0.0 kB,0.0 kB
-slice,property,29353,slice,0.0 kB,0.0 kB
-small,property,29355,small,0.0 kB,0.0 kB
-split,property,29357,split,0.0 kB,0.0 kB
-startsWith,property,29369,startsWith,0.0 kB,0.0 kB
-strike,property,29359,strike,0.0 kB,0.0 kB
-sub,property,29361,sub,0.0 kB,0.0 kB
-substr,property,29363,substr,0.0 kB,0.0 kB
-substring,property,29365,substring,0.0 kB,0.0 kB
-sup,property,29367,sup,0.0 kB,0.0 kB
-toLocaleLowerCase,property,29381,toLocaleLowerCase,0.0 kB,0.0 kB
-toLocaleUpperCase,property,29383,toLocaleUpperCase,0.0 kB,0.0 kB
-toLowerCase,property,29385,toLowerCase,0.0 kB,0.0 kB
-toString,property,29371,toString,0.0 kB,0.0 kB
-toUpperCase,property,29387,toUpperCase,0.0 kB,0.0 kB
-toWellFormed,property,29373,toWellFormed,0.0 kB,0.0 kB
-trim,property,29375,trim,0.0 kB,0.0 kB
-trimEnd,property,29379,trimEnd,0.0 kB,0.0 kB
-trimLeft,property,29377,trimStart,0.0 kB,0.0 kB
-trimRight,property,29379,trimEnd,0.0 kB,0.0 kB
-trimStart,property,29377,trimStart,0.0 kB,0.0 kB
-valueOf,property,29389,valueOf,0.0 kB,0.0 kB
-properties,internal,29393,system / PropertyArray,0.0 kB,0.0 kB
-1,hidden,71,,0.0 kB,0.0 kB
-Showing 1-56 of 56 (Page 1 of 1).
-`;
-
-exports[`memory > get_heapsnapshot_object_details > with valid nodeId 1`] = `
-## Heap Snapshot Data
-### Object Details
-id: @25341
-name: String
-type: object
-detachedness: unknown
-selfSize: 0.2 kB
-retainedSize: 1.6 kB
-distance: 2
-edgeCount: 56
-retainerCount: 3
-`;
-
-exports[`memory > get_heapsnapshot_retainers > with valid nodeId 1`] = `
-## Heap Snapshot Data
-name,type,nodeId,nodeName,selfSize,retainedSize
-prototype,internal,29287,system / Map,0.0 kB,0.1 kB
-prototype,property,25575,String,0.1 kB,0.4 kB
-initial_string_prototype,internal,7199,system / NativeContext,1.2 kB,84.4 kB
-Showing 1-3 of 3 (Page 1 of 1).
-`;
-
-exports[`memory > get_heapsnapshot_retaining_paths > with valid nodeId 1`] = `
-## Heap Snapshot Data
-### Retaining Paths
-<- @45891 system / Context via context builtinToJSONs (distance: 4)
- <- @34237 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Promise> (distance: 2)
- <- @34235 system / PropertyCell via internal value (distance: 4)
- <- @50423 (object properties) via internal 1912 (distance: 3)
- <- @27635 Window (global*) / https://example.com via internal properties (distance: 2)
- <- @34213 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Error> (distance: 2)
- <- @34197 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::RegExp> (distance: 2)
- <- @34185 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::String> (distance: 2)
- <- @34145 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Array> (distance: 2)
- <- @34069 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Function> (distance: 2)
- <- @34047 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Object> (distance: 2)
- <- @46063 stringify via internal context (distance: 4)
- <- @34247 {parse, stringify} via property stringify (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::JSON> (distance: 2)
-`;
-
-exports[`memory > get_heapsnapshot_summary > with default options 1`] = `
-## Heap Snapshot Data
-Statistics: {
- "total": 1121496,
- "native": {
- "total": 333392,
- "typedArrays": 0
- },
- "v8heap": {
- "total": 788104,
- "code": 42812,
- "jsArrays": 1312,
- "strings": 27920,
- "system": 199264
- }
-}
-Static Data: {
- "nodeCount": 27466,
- "rootNodeIndex": 0,
- "totalSize": 1121496,
- "maxJSObjectId": 54005
-}
-### Native Contexts
-nodeId,nodeName,selfSize,retainedSize,attributedSize
-7249,system / NativeContext / https://example.com,1.2 kB,350 kB,350 kB
-7195,system / NativeContext / https://example.com,1.2 kB,60.1 kB,215 kB
-7307,system / NativeContext,1.2 kB,84.4 kB,84.6 kB
-7199,system / NativeContext,1.2 kB,84.4 kB,84.4 kB
-Shared Size: 22.9 kB
-Unattributed Size: 44.8 kB
-### Retained by Context Summary
-Context count: 116
-Retained by context size: 3.5 kB (148 objects)
-Not retained by context size: 798 kB (11792 objects)
-Total size: 802 kB
-`;
-
-exports[`memory > query_heapsnapshot_objects > with an unbounded retainedSize filter 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-1,,synthetic,100000000,0.0 kB,802 kB
-7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
-7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
-49547,,array,2,4.1 kB,41.0 kB
-36241,,array,2,4.1 kB,41.0 kB
-Showing 1-10 of 148 (Page 1 of 15).
-Next page: 1
-`;
-
-exports[`memory > query_heapsnapshot_objects > with className filter 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-32995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
-41995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
-16321,Window / https://example.com,native,2,0.9 kB,1.9 kB
-16329,Window,closure,3,0.1 kB,0.4 kB
-16341,Window,closure,3,0.1 kB,0.4 kB
-30975,Window (prototype) / https://example.com,object,3,0.0 kB,0.2 kB
-Showing 1-10 of 34 (Page 1 of 4).
-Next page: 1
-`;
-
-exports[`memory > query_heapsnapshot_objects > with default options 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-1,,synthetic,100000000,0.0 kB,802 kB
-7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
-7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
-49547,,array,2,4.1 kB,41.0 kB
-36241,,array,2,4.1 kB,41.0 kB
-Showing 1-10 of 27466 (Page 1 of 2747).
-Next page: 1
-`;
-
-exports[`memory > query_heapsnapshot_objects > with sortBy selfSize and pagination 1`] = `
-## Heap Snapshot Data
-nodeId,nodeName,type,distance,selfSize,retainedSize
-1,,synthetic,100000000,0.0 kB,802 kB
-7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
-7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
-Showing 1-5 of 27466 (Page 1 of 5494).
-Next page: 1
-`;
diff --git a/tests/tools/memory.test.ts b/tests/tools/memory.test.ts
index 0c226f77..299b32e8 100644
--- a/tests/tools/memory.test.ts
+++ b/tests/tools/memory.test.ts
@@ -9,7 +9,9 @@ import {existsSync} from 'node:fs';
import {rm} from 'node:fs/promises';
import {tmpdir} from 'node:os';
import {join} from 'node:path';
-import {describe, it} from 'node:test';
+import {describe, it, afterEach} from 'node:test';
+
+import sinon from 'sinon';
import {
takeHeapSnapshot,
@@ -27,11 +29,29 @@ import {
queryHeapSnapshotObjects,
} from '../../src/tools/memory.js';
import {parseByteSizeRange} from '../../src/utils/bytes.js';
-import {stableIdSymbol} from '../../src/utils/id.js';
import {resolveCanonicalPath} from '../../src/utils/files.js';
+import {
+ createHandlerMocks,
+ createMockClassDiffs,
+ createMockDetailedClassDiff,
+ createMockDominatorChain,
+ createMockDuplicateStrings,
+ createMockHeapSnapshotAggregateData,
+ createMockHeapSnapshotStats,
+ createMockHeapSnapshotStaticData,
+ createMockItemsRange,
+ createMockNativeContextSizes,
+ createMockObjectInfo,
+ createMockRetainedByContextSummary,
+ createMockRetainingPaths,
+} from '../mocks.js';
import {withMcpContext} from '../utils.js';
describe('memory', () => {
+ afterEach(() => {
+ sinon.restore();
+ });
+
describe('take_heapsnapshot', () => {
it('with default options', async () => {
await withMcpContext(async (response, context) => {
@@ -53,726 +73,650 @@ describe('memory', () => {
}
});
});
- });
-
- describe('get_heapsnapshot_summary', () => {
- it('with default options', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
- assert.ok(existsSync(filePath), `Fixture not found at ${filePath}`);
+ it('delegates to ensureExtension, captureHeapSnapshot, and appends response line', async () => {
+ const {page, context, response} = createHandlerMocks();
+ context.ensureExtension.resolves('/canonical/test.heapsnapshot');
+ page.pptrPage.captureHeapSnapshot.resolves();
- await getHeapSnapshotSummary.handler(
- {params: {filePath}},
- response,
- context,
- );
-
- // Call handle to trigger formatting (similar to network tests)
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ await takeHeapSnapshot.handler(
+ {params: {filePath: 'test.heapsnapshot'}, page},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.ensureExtension,
+ 'test.heapsnapshot',
+ '.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(page.pptrPage.captureHeapSnapshot, {
+ path: '/canonical/test.heapsnapshot',
});
+ sinon.assert.calledOnceWithExactly(
+ response.appendResponseLine,
+ 'Heap snapshot saved to /canonical/test.heapsnapshot',
+ );
});
});
- describe('get_heapsnapshot_details', () => {
- it('with default options', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotDetails.handler(
- {params: {filePath}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('with objectsRetainedByContexts filterName', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotDetails.handler(
- {params: {filePath, filterName: 'objectsRetainedByContexts'}},
- response,
- context,
- );
+ describe('get_heapsnapshot_summary', () => {
+ it('fetches stats, static data, native context sizes, and retained summary', async () => {
+ const {context, response} = createHandlerMocks();
+ const stats = createMockHeapSnapshotStats();
+ const staticData = createMockHeapSnapshotStaticData();
+ const nativeContextSizes = createMockNativeContextSizes();
+ const retainedByContextSummary = createMockRetainedByContextSummary();
+
+ context.getHeapSnapshotStats.resolves(stats);
+ context.getHeapSnapshotStaticData.resolves(staticData);
+ context.getHeapSnapshotNativeContextSizes.resolves(nativeContextSizes);
+ context.getHeapSnapshotRetainedByContextSummary.resolves(
+ retainedByContextSummary,
+ );
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ await getHeapSnapshotSummary.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotStats,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotStaticData,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotNativeContextSizes,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotRetainedByContextSummary,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotStats,
+ stats,
+ staticData,
+ nativeContextSizes,
+ retainedByContextSummary,
+ );
});
+ });
- it('with sharedNativeContext filterName', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotDetails.handler(
- {params: {filePath, filterName: 'sharedNativeContext'}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ describe('get_heapsnapshot_details', () => {
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const aggregates = createMockHeapSnapshotAggregateData();
+ context.getHeapSnapshotAggregates.resolves(aggregates);
+
+ await getHeapSnapshotDetails.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotAggregates,
+ 'test.heapsnapshot',
+ undefined,
+ undefined,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotAggregates,
+ aggregates,
+ {pageIdx: undefined, pageSize: undefined},
+ );
});
- it('with attributedToSpecificNativeContext filterName and objectId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotDetails.handler(
- {
- params: {
- filePath,
- filterName: 'attributedToSpecificNativeContext',
- objectId: 7249,
- pageSize: 10,
- },
+ it('with filters and pagination', async () => {
+ const {context, response} = createHandlerMocks();
+ const aggregates = createMockHeapSnapshotAggregateData();
+ context.getHeapSnapshotAggregates.resolves(aggregates);
+
+ await getHeapSnapshotDetails.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ filterName: 'attributedToSpecificNativeContext',
+ objectId: 123,
+ pageIdx: 1,
+ pageSize: 10,
},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ },
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotAggregates,
+ 'test.heapsnapshot',
+ 'attributedToSpecificNativeContext',
+ 123,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotAggregates,
+ aggregates,
+ {pageIdx: 1, pageSize: 10},
+ );
});
});
describe('get_heapsnapshot_class_nodes', () => {
- it('with default options', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await context.getHeapSnapshotAggregates(filePath);
-
- await getHeapSnapshotClassNodes.handler(
- {params: {filePath, id: 19}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
-
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('with objectsRetainedByContexts filterName', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- const aggregateData = await context.getHeapSnapshotAggregates(
- filePath,
- 'objectsRetainedByContexts',
- );
- const aggregate = Object.values(aggregateData.aggregates).find(
- a => a.name === 'Function',
- );
- assert.ok(aggregate);
- const id = aggregate[stableIdSymbol];
- assert.ok(id);
-
- await getHeapSnapshotClassNodes.handler(
- {params: {filePath, id, filterName: 'objectsRetainedByContexts'}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
-
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const nodes = createMockItemsRange();
+ context.getHeapSnapshotNodesById.resolves(nodes);
+
+ await getHeapSnapshotClassNodes.handler(
+ {params: {filePath: 'test.heapsnapshot', id: 19}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotNodesById,
+ 'test.heapsnapshot',
+ 19,
+ undefined,
+ undefined,
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, nodes, {
+ pageIdx: undefined,
+ pageSize: undefined,
});
});
- it('with non-existent class name', async () => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await context.getHeapSnapshotAggregates(filePath);
+ it('with filters and pagination', async () => {
+ const {context, response} = createHandlerMocks();
+ const nodes = createMockItemsRange();
+ context.getHeapSnapshotNodesById.resolves(nodes);
+
+ await getHeapSnapshotClassNodes.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ id: 19,
+ filterName: 'objectsRetainedByContexts',
+ objectId: 456,
+ pageIdx: 2,
+ pageSize: 20,
+ },
+ },
+ response,
+ context,
+ );
- await assert.rejects(
- getHeapSnapshotClassNodes.handler(
- {params: {filePath, id: 999999}},
- response,
- context,
- ),
- {message: 'Class with ID 999999 not found in heap snapshot'},
- );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotNodesById,
+ 'test.heapsnapshot',
+ 19,
+ 'objectsRetainedByContexts',
+ 456,
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, nodes, {
+ pageIdx: 2,
+ pageSize: 20,
});
});
});
describe('get_heapsnapshot_retainers', () => {
- it('with valid nodeId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const retainers = createMockItemsRange();
+ context.getHeapSnapshotRetainers.resolves(retainers);
+
+ await getHeapSnapshotRetainers.handler(
+ {params: {filePath: 'test.heapsnapshot', nodeId: 25341}},
+ response,
+ context,
+ );
- await getHeapSnapshotRetainers.handler(
- {params: {filePath, nodeId: 25341}},
- response,
- context,
- );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotRetainers,
+ 'test.heapsnapshot',
+ 25341,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotNodes,
+ retainers,
+ {pageIdx: undefined, pageSize: undefined},
+ );
+ });
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with pagination', async () => {
+ const {context, response} = createHandlerMocks();
+ const retainers = createMockItemsRange();
+ context.getHeapSnapshotRetainers.resolves(retainers);
+
+ await getHeapSnapshotRetainers.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ nodeId: 25341,
+ pageIdx: 1,
+ pageSize: 5,
+ },
+ },
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotRetainers,
+ 'test.heapsnapshot',
+ 25341,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotNodes,
+ retainers,
+ {pageIdx: 1, pageSize: 5},
+ );
});
});
describe('get_heapsnapshot_object_details', () => {
- it('with valid nodeId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotObjectDetails.handler(
- {params: {filePath, nodeId: 25341}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with valid nodeId', async () => {
+ const {context, response} = createHandlerMocks();
+ const objectInfo = createMockObjectInfo();
+ context.getHeapSnapshotObjectDetails.resolves(objectInfo);
+
+ await getHeapSnapshotObjectDetails.handler(
+ {params: {filePath: 'test.heapsnapshot', nodeId: 25341}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotObjectDetails,
+ 'test.heapsnapshot',
+ 25341,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotObjectDetails,
+ objectInfo,
+ );
});
});
describe('close_heapsnapshot', () => {
- it('with default options', async () => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
+ it('closes loaded snapshot', async () => {
+ const {context, response} = createHandlerMocks();
+ context.closeHeapSnapshot.resolves(true);
+
+ await closeHeapSnapshot.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
+ response,
+ context,
+ );
- await getHeapSnapshotSummary.handler(
- {params: {filePath}},
- response,
- context,
- );
+ sinon.assert.calledOnceWithExactly(
+ context.closeHeapSnapshot,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.appendResponseLine,
+ 'Closed heap snapshot: test.heapsnapshot',
+ );
+ });
- assert.ok(context.hasHeapSnapshots());
+ it('throws error when snapshot was not loaded', async () => {
+ const {context, response} = createHandlerMocks();
+ context.closeHeapSnapshot.resolves(false);
- await closeHeapSnapshot.handler(
- {params: {filePath}},
+ await assert.rejects(
+ closeHeapSnapshot.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
response,
context,
- );
-
- assert.ok(
- response.responseLines.includes(`Closed heap snapshot: ${filePath}`),
- );
- assert.ok(!context.hasHeapSnapshots());
- });
- });
-
- it('with non-existent snapshot', async () => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await assert.rejects(
- closeHeapSnapshot.handler({params: {filePath}}, response, context),
- {
- message: `Failed to close heap snapshot: ${filePath} was not loaded.`,
- },
- );
- });
+ ),
+ {
+ message:
+ 'Failed to close heap snapshot: test.heapsnapshot was not loaded.',
+ },
+ );
});
});
describe('get_heapsnapshot_retaining_paths', () => {
- it('with valid nodeId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotRetainingPaths.handler(
- {params: {filePath, nodeId: 45901}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const retainingPaths = createMockRetainingPaths();
+ context.getHeapSnapshotRetainingPaths.resolves(retainingPaths);
+
+ await getHeapSnapshotRetainingPaths.handler(
+ {params: {filePath: 'test.heapsnapshot', nodeId: 45901}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotRetainingPaths,
+ 'test.heapsnapshot',
+ 45901,
+ undefined,
+ undefined,
+ undefined,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotRetainingPaths,
+ retainingPaths,
+ );
});
- it('reports when limits are reached', async () => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
+ it('with search limits', async () => {
+ const {context, response} = createHandlerMocks();
+ const retainingPaths = createMockRetainingPaths();
+ context.getHeapSnapshotRetainingPaths.resolves(retainingPaths);
+
+ await getHeapSnapshotRetainingPaths.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ nodeId: 45901,
+ maxDepth: 5,
+ maxNodes: 10,
+ maxSiblings: 2,
+ },
+ },
+ response,
+ context,
+ );
- await getHeapSnapshotRetainingPaths.handler(
- {params: {filePath, nodeId: 45901, maxDepth: 1}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- assert.match(output, /No retaining paths found\./);
- assert.match(
- output,
- /Note: results are truncated, the following limits were reached: depth\./,
- );
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotRetainingPaths,
+ 'test.heapsnapshot',
+ 45901,
+ 5,
+ 10,
+ 2,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotRetainingPaths,
+ retainingPaths,
+ );
});
});
describe('get_heapsnapshot_edges', () => {
- it('with valid nodeId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotEdges.handler(
- {params: {filePath, nodeId: 25341}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('with pagination', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotEdges.handler(
- {params: {filePath, nodeId: 25341, pageSize: 2}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const edges = createMockItemsRange();
+ context.getHeapSnapshotEdges.resolves(edges);
+
+ await getHeapSnapshotEdges.handler(
+ {params: {filePath: 'test.heapsnapshot', nodeId: 25341}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotEdges,
+ 'test.heapsnapshot',
+ 25341,
+ {
+ sortBy: 'retainedSize',
+ minRetainedSize: undefined,
+ excludePrimitives: true,
+ },
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, edges, {
+ pageIdx: undefined,
+ pageSize: undefined,
});
});
- it('with retainedSize range', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotEdges.handler(
- {
- params: {
- filePath,
- nodeId: 25341,
- retainedSize: parseByteSizeRange('100B-100B'),
- },
+ it('with retainedSize range, sortBy, and excludePrimitives', async () => {
+ const {context, response} = createHandlerMocks();
+ const edges = createMockItemsRange();
+ context.getHeapSnapshotEdges.resolves(edges);
+
+ await getHeapSnapshotEdges.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ nodeId: 25341,
+ sortBy: 'selfSize',
+ retainedSize: parseByteSizeRange('100B-200B'),
+ excludePrimitives: false,
+ pageIdx: 0,
+ pageSize: 2,
},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ },
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotEdges,
+ 'test.heapsnapshot',
+ 25341,
+ {
+ sortBy: 'selfSize',
+ minRetainedSize: 100,
+ excludePrimitives: false,
+ },
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, edges, {
+ pageIdx: 0,
+ pageSize: 2,
});
});
});
describe('get_heapsnapshot_dominators', () => {
- it('with valid nodeId', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await getHeapSnapshotDominators.handler(
- {params: {filePath, nodeId: 25341}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with valid nodeId', async () => {
+ const {context, response} = createHandlerMocks();
+ const dominators = createMockDominatorChain();
+ context.getHeapSnapshotDominators.resolves(dominators);
+
+ await getHeapSnapshotDominators.handler(
+ {params: {filePath: 'test.heapsnapshot', nodeId: 25341}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotDominators,
+ 'test.heapsnapshot',
+ 25341,
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotDominators,
+ dominators,
+ );
});
});
describe('compare_heapsnapshots', () => {
- it('compare heap-1 to heap-2', async t => {
- await withMcpContext(async (response, context) => {
- const filePathA = join(
- process.cwd(),
- 'tests/fixtures/heap-1.heapsnapshot',
- );
- const filePathB = join(
- process.cwd(),
- 'tests/fixtures/heap-2.heapsnapshot',
- );
-
- await compareHeapSnapshots.handler(
- {params: {baseFilePath: filePathA, currentFilePath: filePathB}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('compare heap-2 to heap-3', async t => {
- await withMcpContext(async (response, context) => {
- const filePathA = join(
- process.cwd(),
- 'tests/fixtures/heap-2.heapsnapshot',
- );
- const filePathB = join(
- process.cwd(),
- 'tests/fixtures/heap-3.heapsnapshot',
- );
-
- await compareHeapSnapshots.handler(
- {params: {baseFilePath: filePathA, currentFilePath: filePathB}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('compare heap-1 to heap-2 with classIndex filter', async t => {
- await withMcpContext(async (response, context) => {
- const filePathA = join(
- process.cwd(),
- 'tests/fixtures/heap-1.heapsnapshot',
- );
- const filePathB = join(
- process.cwd(),
- 'tests/fixtures/heap-2.heapsnapshot',
- );
-
- await compareHeapSnapshots.handler(
- {
- params: {
- baseFilePath: filePathA,
- currentFilePath: filePathB,
- classIndex: 2, // NewObject
- },
+ it('returns summary diff when classIndex is omitted', async () => {
+ const {context, response} = createHandlerMocks();
+ const diffs = createMockClassDiffs();
+ context.getHeapSnapshotClassDiffs.resolves(diffs);
+
+ await compareHeapSnapshots.handler(
+ {
+ params: {
+ baseFilePath: 'heap1.heapsnapshot',
+ currentFilePath: 'heap2.heapsnapshot',
},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('compare heap-1 to heap-2 with invalid classIndex throws error', async () => {
- await withMcpContext(async (response, context) => {
- const filePathA = join(
- process.cwd(),
- 'tests/fixtures/heap-1.heapsnapshot',
- );
- const filePathB = join(
- process.cwd(),
- 'tests/fixtures/heap-2.heapsnapshot',
- );
-
- await assert.rejects(
- compareHeapSnapshots.handler(
- {
- params: {
- baseFilePath: filePathA,
- currentFilePath: filePathB,
- classIndex: 99,
- },
- },
- response,
- context,
- ),
- /Invalid classIndex: 99. Total classes with changes: 10/,
- );
- });
- });
- });
-
- // Verifies that the caching mechanism in HeapSnapshotManager correctly
- // distinguishes comparisons when the same "current" snapshot is compared
- // against different "base" snapshots. If the cache key (diffCacheKey) is
- // not unique per base snapshot, the second comparison might incorrectly
- // return cached results from the first comparison.
- it('compares the same current snapshot against different bases', async () => {
- await withMcpContext(async (_response, context) => {
- const filePathA = join(
- process.cwd(),
- 'tests/fixtures/heap-1.heapsnapshot',
+ },
+ response,
+ context,
);
- const filePathB = join(
- process.cwd(),
- 'tests/fixtures/heap-2.heapsnapshot',
+
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotClassDiffs,
+ 'heap1.heapsnapshot',
+ 'heap2.heapsnapshot',
);
- const filePathC = join(
- process.cwd(),
- 'tests/fixtures/heap-3.heapsnapshot',
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotClassDiffs,
+ diffs,
);
+ });
- const firstDiff = await context.getHeapSnapshotClassDiffs(
- filePathA,
- filePathC,
- );
- const secondDiff = await context.getHeapSnapshotClassDiffs(
- filePathB,
- filePathC,
+ it('returns detailed diff when classIndex is provided', async () => {
+ const {context, response} = createHandlerMocks();
+ const detailedDiff = createMockDetailedClassDiff();
+ context.getHeapSnapshotDetailedClassDiff.resolves(detailedDiff);
+
+ await compareHeapSnapshots.handler(
+ {
+ params: {
+ baseFilePath: 'heap1.heapsnapshot',
+ currentFilePath: 'heap2.heapsnapshot',
+ classIndex: 2,
+ },
+ },
+ response,
+ context,
);
- const firstNewObjectDiff = firstDiff.find(
- entry => entry.className === 'NewObject',
+
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotDetailedClassDiff,
+ 'heap1.heapsnapshot',
+ 'heap2.heapsnapshot',
+ 2,
);
- const secondNewObjectDiff = secondDiff.find(
- entry => entry.className === 'NewObject',
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotDetailedClassDiff,
+ detailedDiff,
);
- assert.ok(firstNewObjectDiff);
- assert.ok(secondNewObjectDiff);
- assert.equal(firstNewObjectDiff.addedCount, 7);
- assert.equal(secondNewObjectDiff.addedCount, 5);
});
});
describe('get_heapsnapshot_duplicate_strings', () => {
- it('with default options', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const duplicateStrings = createMockDuplicateStrings();
+ context.getHeapSnapshotDuplicateStrings.resolves(duplicateStrings);
+
+ await getHeapSnapshotDuplicateStrings.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
+ response,
+ context,
+ );
- await getHeapSnapshotDuplicateStrings.handler(
- {params: {filePath}},
- response,
- context,
- );
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotDuplicateStrings,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotDuplicateStrings,
+ duplicateStrings,
+ {pageIdx: undefined, pageSize: undefined},
+ );
+ });
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with pagination', async () => {
+ const {context, response} = createHandlerMocks();
+ const duplicateStrings = createMockDuplicateStrings();
+ context.getHeapSnapshotDuplicateStrings.resolves(duplicateStrings);
+
+ await getHeapSnapshotDuplicateStrings.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ pageIdx: 2,
+ pageSize: 10,
+ },
+ },
+ response,
+ context,
+ );
- t.assert.snapshot(output);
- });
+ sinon.assert.calledOnceWithExactly(
+ context.getHeapSnapshotDuplicateStrings,
+ 'test.heapsnapshot',
+ );
+ sinon.assert.calledOnceWithExactly(
+ response.setHeapSnapshotDuplicateStrings,
+ duplicateStrings,
+ {pageIdx: 2, pageSize: 10},
+ );
});
});
describe('query_heapsnapshot_objects', () => {
- it('with default options', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await queryHeapSnapshotObjects.handler(
- {params: {filePath, pageSize: 10}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('with className filter', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await queryHeapSnapshotObjects.handler(
- {params: {filePath, className: 'Window', pageSize: 10}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ it('with default options', async () => {
+ const {context, response} = createHandlerMocks();
+ const range = createMockItemsRange();
+ context.queryHeapSnapshotObjects.resolves(range);
+
+ await queryHeapSnapshotObjects.handler(
+ {params: {filePath: 'test.heapsnapshot'}},
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.queryHeapSnapshotObjects,
+ 'test.heapsnapshot',
+ {
+ className: undefined,
+ propertyName: undefined,
+ nodeType: undefined,
+ minRetainedSize: undefined,
+ maxRetainedSize: undefined,
+ minSelfSize: undefined,
+ maxSelfSize: undefined,
+ isDetached: undefined,
+ sortBy: undefined,
+ },
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, range, {
+ pageIdx: undefined,
+ pageSize: undefined,
});
});
- it('with an unbounded retainedSize filter', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await queryHeapSnapshotObjects.handler(
- {
- params: {
- filePath,
- retainedSize: parseByteSizeRange('1KB'),
- pageSize: 10,
- },
+ it('with all query filters and pagination', async () => {
+ const {context, response} = createHandlerMocks();
+ const range = createMockItemsRange();
+ context.queryHeapSnapshotObjects.resolves(range);
+
+ await queryHeapSnapshotObjects.handler(
+ {
+ params: {
+ filePath: 'test.heapsnapshot',
+ className: 'Window',
+ propertyName: 'prop',
+ nodeType: 'object',
+ retainedSize: parseByteSizeRange('1KB-2KB'),
+ selfSize: parseByteSizeRange('100B-200B'),
+ isDetached: true,
+ sortBy: 'selfSize',
+ pageIdx: 1,
+ pageSize: 10,
},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
-
- t.assert.snapshot(output);
- });
- });
-
- it('with sortBy selfSize and pagination', async t => {
- await withMcpContext(async (response, context) => {
- const filePath = join(
- process.cwd(),
- 'tests/fixtures/example.heapsnapshot',
- );
-
- await queryHeapSnapshotObjects.handler(
- {params: {filePath, sortBy: 'selfSize', pageSize: 5, pageIdx: 0}},
- response,
- context,
- );
-
- const responseData = await response.handle(context);
- const output = responseData.content
- .map(c => (c.type === 'text' ? c.text : ''))
- .join('\n');
+ },
+ response,
+ context,
+ );
- t.assert.snapshot(output);
+ sinon.assert.calledOnceWithExactly(
+ context.queryHeapSnapshotObjects,
+ 'test.heapsnapshot',
+ {
+ className: 'Window',
+ propertyName: 'prop',
+ nodeType: 'object',
+ minRetainedSize: 1000,
+ maxRetainedSize: 2000,
+ minSelfSize: 100,
+ maxSelfSize: 200,
+ isDetached: true,
+ sortBy: 'selfSize',
+ },
+ );
+ sinon.assert.calledOnceWithExactly(response.setHeapSnapshotNodes, range, {
+ pageIdx: 1,
+ pageSize: 10,
});
});
});