flotwig / cypress-log-to-output

A Cypress plugin that sends all logs that occur in the browser to stdout in the terminal.
146 stars 19 forks source link

How to filter out some errors? #6

Closed oflorko closed 4 years ago

oflorko commented 4 years ago

Dear developers,

Thank you for a useful plugin that allows us to catch more errors during CI runs! To make it more readable is it possible to filter out error logs that we are not interested in like:

⚠ error (network): Failed to load resource: the server responded with a status of 503 (Service Unavailable) URL: https://www.google-analytics.com/analytics.js

This code doesn't work for me:

 require('cypress-log-to-output').install(on, (type, event) => {
        if (event.level === 'error' || event.type === 'error') {
            if ( !event.body.contains('google-analytics.com') ) 
                 return true
        }

        return false
    })

Could you please suggest something?

flotwig commented 4 years ago

@oflorko The filtering function should return true if the log is to be visible, false otherwise. The code you have here seems to only return true if it's an "error" and the "body" does not contain "google-analytics.com".

event.body does not exist either, so I doubt this will work. Check the DevTools documentation for the types:

oflorko commented 4 years ago

@flotwig Thank you for your fast reply it actually helped us. Here is the solution:

module.exports = (on, config) => { 
     require('cypress-log-to-output').install(on, (type, event) => { 
          if (event.level === 'error' || event.type === 'error') {
               if (event.url !== undefined && event.url.indexOf('google-analytics.com') > 0) return false
               else return true
          }
          return false
})
flotwig commented 4 years ago

Great! Glad to hear you got it working.