MCPcopy Index your code
hub / github.com/nodejs/node / validateSnapshot

Method validateSnapshot

test/common/heap.js:120–169  ·  view source on GitHub ↗
(rootName, expected, { loose = false } = {})

Source from the content-addressed store, hash-verified

118
119 // Validate the v8 heap snapshot
120 validateSnapshot(rootName, expected, { loose = false } = {}) {
121 const rootNodes = this.snapshot.filter(
122 (node) => node.name === rootName && node.type !== 'string');
123 if (loose) {
124 assert(rootNodes.length >= expected.length,
125 `Expect to find at least ${expected.length} '${rootName}', ` +
126 `found ${rootNodes.length}`);
127 } else {
128 assert.strictEqual(
129 rootNodes.length, expected.length,
130 `Expect to find ${expected.length} '${rootName}', ` +
131 `found ${rootNodes.length}`);
132 }
133
134 for (const expectation of expected) {
135 if (expectation.children) {
136 for (const expectedEdge of expectation.children) {
137 const check = typeof expectedEdge === 'function' ? expectedEdge :
138 (edge) => (isEdge(edge, expectedEdge));
139 const hasChild = rootNodes.some(
140 (node) => node.outgoingEdges.some(check),
141 );
142 // Don't use assert with a custom message here. Otherwise the
143 // inspection in the message is done eagerly and wastes a lot of CPU
144 // time.
145 if (!hasChild) {
146 throw new Error(
147 'expected to find child ' +
148 `${util.inspect(expectedEdge)} in ${inspectNode(rootNodes)}`);
149 }
150 }
151 }
152
153 if (expectation.detachedness !== undefined) {
154 const matchedNodes = rootNodes.filter(
155 (node) => node.detachedness === expectation.detachedness);
156 if (loose) {
157 assert(matchedNodes.length >= rootNodes.length,
158 `Expect to find at least ${rootNodes.length} with ` +
159 `detachedness ${expectation.detachedness}, ` +
160 `found ${matchedNodes.length}`);
161 } else {
162 assert.strictEqual(
163 matchedNodes.length, rootNodes.length,
164 `Expect to find ${rootNodes.length} with detachedness ` +
165 `${expectation.detachedness}, found ${matchedNodes.length}`);
166 }
167 }
168 }
169 }
170
171 // Validate our internal embedded graph representation
172 validateGraph(rootName, expected, { loose = false } = {}) {

Callers 3

validateSnapshotNodesMethod · 0.95
checkFunction · 0.80

Calls 6

isEdgeFunction · 0.85
inspectNodeFunction · 0.85
someMethod · 0.80
inspectMethod · 0.80
filterMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected