HuddleEng / PhantomFlow

Describe and visualise user flows through tests with PhantomJS
MIT License
682 stars 60 forks source link

Make debug event listeners removable #49

Closed alexthewilde closed 7 years ago

alexthewilde commented 8 years ago

Factor debug event listener closure functions into named functions so they can be removed using casper.removeListener() if needed.

In my case I want to suppress "Resource Error" debug logs which occur every time a page location changes while image resource haven't finished loading yet.

jamescryer commented 8 years ago

I would rather not expose those methods, I can easily see someone else (or myself) refactoring that code without realising why it's like that.

Perhaps a more explicit way to achieve this would be to provide a config option like

  var flow = require('../phantomflow').init({
       debug: 1,
       ignoreResourceErrors: true
    });
alexthewilde commented 8 years ago

Thanks @jamescryer for looking into this. I don't really want to ignore errors per se, but rather filter them the way I need it. Thus to me an exposed method that I can override makes more sense.

jamescryer commented 7 years ago

Closing as this solution would add a maintenance cost to the project. Makes perfect sense in a OSS environment to keep this on fork/branch.

eskitek commented 7 years ago

@alexthewilde, you might look into using casper's removeAllListeners function in your test setup. We do something like this to replace the default onResourceError handling in test setup:

casper.clear().
    removeAllListeners('resource.error').
    on('resource.error', function (resourceError) {
        console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
        console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
    });

See also this post.

alexthewilde commented 7 years ago

@eskitek thanks a bunch!