Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Unable to quiet js console.log #94

Closed
lucassus opened this Issue · 15 comments
@lucassus

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
........
@cap10morgan

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

+1, it sounds good

@eirc

+1!

@arandaio

+1!

@carlesso

+1

@Codas

+1

@benjaminoakes

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.

@roblander

+100500

@tjsingleton

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.

@christiangeek

building off of @tjsingleton suggestion: #230

@boblail

+1 (Also, thanks for poltergeist! :smile:)

@route
Owner

Closing this because of merged #230 and phantomjs_logger option.

@route route closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.