(rootName, expected, { loose = false } = {})
| 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 }); |
no test coverage detected