Unable to quiet js console.log #94

Closed
lucassus opened this Issue Jul 2, 2012 · 15 comments

Comments

Projects
None yet

lucassus commented Jul 2, 2012

Currently there is no option to quiet javascript console.log calls. Sometimes it leads to pretty noisy tests output:

..........................................................................MOCK GET: https://api.recurly.com/jsonp/my_site/plans/monthly?currency=USD
MOCK GET: https://api.recurly.com/jsonp/my_site/location
MOCK GET: https://api.recurly.com/jsonp/my_site/subscribe
.MOCK GET: https://api.recurly.com/jsonp/my_site/accounts/4ff0d003fd11085661000045@recurly/billing_info/update
.MOCK GET: https://api.recurly.com/jsonp/my_site/location
........

It would be great if there were a tag (in RSpec, for example) we could use to silence console.log output for tests that are expected to generate output. For example, if I'm testing that a particular AJAX call results in a 4xx error, then I don't want to see that error from console.log in the test output every time (though I might want to see the output if the test fails).

What if there were a runtime option like :js_silent (and corresponding RSpec tag) that would suppress console.log as long as the test passes? I can implement it if the idea seems sound.

lucassus commented Jul 3, 2012

+1, it sounds good

eirc commented Aug 1, 2012

+1!

+1!

👍

carlesso commented Nov 9, 2012

+1

Codas commented Nov 12, 2012

+1

I don't know much about the internals of Poltergeist or PhantomJS, but a possible implementation would be injecting some JavaScript like this:

(function () {
  var emptyFunction = function () {};

  // List from http://frugalcoder.us/post/2009/07/22/firebug_console_stub.aspx
  window.console = {
    log: emptyFunction,
    debug: emptyFunction,
    info: emptyFunction,
    warn: emptyFunction,
    error: emptyFunction,
    assert: emptyFunction,
    dir: emptyFunction,
    dirxml: emptyFunction,
    trace: emptyFunction,
    group: emptyFunction,
    groupCollapsed: emptyFunction,
    groupEnd: emptyFunction,
    time: emptyFunction,
    timeEnd: emptyFunction,
    profile: emptyFunction,
    profileEnd: emptyFunction,
    count: emptyFunction
  };
}());

Because JavaScript functions are variadic, emptyFunction will just ignore whatever's passed in.

This works in a pinch now if you're being affected by this issue.

+100500

Contributor

christiangeek commented Jan 4, 2013

+1

Another solution would be to allow you to set the IO object it was written to. You could output to a log or capture it to test it's contents.

Contributor

christiangeek commented Jan 8, 2013

building off of @tjsingleton suggestion: jonleighton#230

boblail commented May 31, 2013

+1 (Also, thanks for poltergeist! 😄)

Owner

route commented Jul 18, 2013

Closing this because of merged #230 and phantomjs_logger option.

route closed this Jul 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment