Skip to content
Browse files

Add '--console' flag to display messages from web pages.

This flag redirects console messages from web pages to the terminal so
they are shown while running the tests.

The default value for the new flag is 'off' to keep existing tests
working without any output changes.
  • Loading branch information...
1 parent f1dcc99 commit 79f764938b4bfeba157c0f0eb099c152fbca3178 @StanAngeloff committed Sep 7, 2012
Showing with 19 additions and 4 deletions.
  1. +5 −0 bin/cli.js
  2. +9 −0 lib/inject/main.js
  3. +5 −4 lib/lotte.js
View
5 bin/cli.js
@@ -59,6 +59,11 @@ var defaults = optimist.
default: ( ! process.env['LOTTE_NO_SERVER']),
description: 'start a HTTP server for IPC'
}).
+ option('console', {
+ type: 'boolean',
+ default: ( !! process.env['LOTTE_CONSOLE']),
+ description: 'display console messages from web pages'
+ }).
option('address', {
alias: 'a',
default: '127.0.0.1',
View
9 lib/inject/main.js
@@ -72,6 +72,15 @@ this.open = function open(uri, message, options, block) {
});
phantom.exit(4);
};
+ if (${CONSOLE}) {
+ webpage.onConsoleMessage = function(message, line, file) {
+ console.log(
+ message +
+ (typeof (line) === 'undefined' ? '' : (" on line '" + line + "'")) +
+ (typeof (file) === 'undefined' ? '' : (" in file '" + file + "'"))
+ )
+ };
+ }
webpage.open(uri, function(status) {
if (page) {
page._onLoad();
View
9 lib/lotte.js
@@ -140,10 +140,11 @@ function queue(take, template, options, resume) {
function substitute(template, file, code, options) {
var variables = {
- 'file': file,
- 'code': code,
- 'events': ( !! options.server),
- 'server': 'http://' + options.address + ':' + options.port
+ 'file': file,
+ 'code': code,
+ 'events': ( !! options.server),
+ 'console': ( !! options.console),
+ 'server': 'http://' + options.address + ':' + options.port
};
var transforms = {
'none': null,

0 comments on commit 79f7649

Please sign in to comment.
Something went wrong with that request. Please try again.