@ -3,14 +3,26 @@
const areArraysEqual = require ( "./are-arrays-equal" ) ;
const areArraysEqual = require ( "./are-arrays-equal" ) ;
module . exports = function areErrorsFromSameOrigin ( errors ) {
module . exports = function areErrorsFromSameOrigin ( errors ) {
let seen Path = null ;
let reference Path = null ;
function checkErrors ( errors , basePath = [ ] ) {
return errors . every ( ( error ) => {
return errors . every ( ( error ) => {
if ( seenPath == null ) {
let absolutePath = basePath . concat ( error . path ) ;
seenPath = error . path ;
return true ;
if ( referencePath == null ) {
} else {
// Whatever we encounter first is the reference path. However, we don't return `true` here; even if we assume the error's own path to be correct (since it's the reference path...), the error may still have subErrors with a different path!
return areArraysEqual ( seenPath , error . path ) ;
referencePath = absolutePath ;
}
}
let subErrorsEqual = ( error . subErrors != null )
? checkErrors ( error . subErrors , absolutePath )
: true ;
let selfEqual = areArraysEqual ( referencePath , absolutePath ) ;
return ( selfEqual && subErrorsEqual ) ;
} ) ;
} ) ;
}
return checkErrors ( errors ) ;
} ;
} ;