Permalink
Browse files

Merge pull request #20 from kpdecker/user-agent-string

Allow for explicit user agents
  • Loading branch information...
2 parents df8376f + 94828ad commit 0102c6365f20747ee9a5b5d59bc77b2c66d531b2 @metaskills metaskills committed Nov 22, 2012
Showing with 13 additions and 4 deletions.
  1. +4 −2 bin/mocha-phantomjs
  2. +9 −2 lib/mocha-phantomjs.coffee
View
@@ -11,7 +11,8 @@ var program = require('commander'),
program
.version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
.usage('[options] page')
- .option('-R, --reporter <name>', 'specify the reporter to use', 'spec');
+ .option('-R, --reporter <name>', 'specify the reporter to use', 'spec')
+ .option('-A, --agent <userAgent>', 'specify the user agent to use', '');
program.on('--help', function(){
console.log(' Examples:');
@@ -27,6 +28,7 @@ if (!program.args.length) { program.outputHelp(); process.exit(1); };
var script = fs.realpathSync(__dirname + '/../lib/mocha-phantomjs.coffee');
var reporter = program.reporter;
+var agent = program.agent;
var page = function(){
var arg = program.args[0];
if (arg.match(/file:\/\//)) { return arg; };
@@ -37,7 +39,7 @@ var page = function(){
return arg;
}();
-var phantomjs = spawn('phantomjs', [script, page, reporter]);
+var phantomjs = spawn('phantomjs', [script, page, reporter, agent]);
phantomjs.stdout.on('data', function(data){
print(data.toString());
@@ -2,7 +2,7 @@ system = require 'system'
webpage = require 'webpage'
USAGE = """
- Usage: phantomjs mocha-phantomjs.coffee URL REPORTER
+ Usage: phantomjs mocha-phantomjs.coffee URL REPORTER [USER-AGENT]
"""
class Reporter
@@ -42,7 +42,12 @@ class Reporter
phantom.exit @page.evaluate -> mochaPhantomJS.failures
initPage: ->
- @page = webpage.create()
+ if userAgent
+ settings =
+ userAgent: userAgent
+
+ @page = webpage.create
+ settings: settings
@page.onConsoleMessage = (msg) -> console.log msg
@page.onInitialized = =>
@page.evaluate ->
@@ -214,6 +219,8 @@ class HtmlCov extends Reporter
constructor: -> super 'html-cov'
+userAgent = system.args[3]
+
reporterString = system.args[2] || 'spec'
reporterString = ("#{s.charAt(0).toUpperCase()}#{s.slice(1)}" for s in reporterString.split('-')).join('')
reporterKlass = try

0 comments on commit 0102c63

Please sign in to comment.