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

Method validateGraph

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

Source from the content-addressed store, hash-verified

170
171 // Validate our internal embedded graph representation
172 validateGraph(rootName, expected, { loose = false } = {}) {
173 const rootNodes = this.embedderGraph.filter(
174 (node) => node.name === rootName,
175 );
176 if (loose) {
177 assert(rootNodes.length >= expected.length,
178 `Expect to find at least ${expected.length} '${rootName}', ` +
179 `found ${rootNodes.length}`);
180 } else {
181 assert.strictEqual(
182 rootNodes.length, expected.length,
183 `Expect to find ${expected.length} '${rootName}', ` +
184 `found ${rootNodes.length}`);
185 }
186 for (const expectation of expected) {
187 if (expectation.children) {
188 for (const expectedEdge of expectation.children) {
189 const check = typeof expectedEdge === 'function' ? expectedEdge :
190 (edge) => (isEdge(edge, expectedEdge));
191 // Don't use assert with a custom message here. Otherwise the
192 // inspection in the message is done eagerly and wastes a lot of CPU
193 // time.
194 const hasChild = rootNodes.some(
195 (node) => node.edges.some(check),
196 );
197 if (!hasChild) {
198 throw new Error(
199 'expected to find child ' +
200 `${util.inspect(expectedEdge)} in ${inspectNode(rootNodes)}`);
201 }
202 }
203 }
204 }
205 }
206
207 validateSnapshotNodes(rootName, expected, { loose = false } = {}) {
208 this.validateSnapshot(rootName, expected, { loose });

Callers 1

validateSnapshotNodesMethod · 0.95

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