MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / scanForErrorMessages

Function scanForErrorMessages

lib/html.js:189–221  ·  view source on GitHub ↗
(html, errorClasses = [])

Source from the content-addressed store, hash-verified

187}
188
189function scanForErrorMessages(html, errorClasses = []) {
190 // Parse the HTML into a document tree
191 const document = parse(html)
192
193 // Array to store error messages
194 const errorMessages = []
195
196 // Function to recursively scan for error classes and messages
197 function scanErrors(node) {
198 if (node.attrs) {
199 const classAttr = node.attrs.find(attr => attr.name === 'class')
200 if (classAttr && classAttr.value) {
201 const classNameChunks = classAttr.value.split(' ')
202 const errorClassFound = errorClasses.some(errorClass => classNameChunks.includes(errorClass))
203 if (errorClassFound && node.childNodes) {
204 const errorMessage = sanitizeTextContent(node)
205 errorMessages.push(errorMessage)
206 }
207 }
208 }
209
210 if (node.childNodes) {
211 for (const childNode of node.childNodes) {
212 scanErrors(childNode)
213 }
214 }
215 }
216
217 // Start scanning for error classes and messages from the root element
218 scanErrors(document)
219
220 return errorMessages
221}
222
223function sanitizeTextContent(node) {
224 if (node.nodeName === '#text') {

Callers 2

pageInfo.jsFile · 0.90
html_test.jsFile · 0.90

Calls 1

scanErrorsFunction · 0.85

Tested by

no test coverage detected