Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 52 lines (41 sloc) 1.584 kb
#!/usr/bin/env node
var program = require('commander'),
spawn = require('child_process').spawn,
print = require('util').print,
fs = require('fs'),
path = require('path'),
exists = fs.existsSync || path.existsSync,
cwd = process.cwd();
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('-A, --agent <userAgent>', 'specify the user agent to use', '');
program.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ mocha-phantomjs -R dot /test/file.html');
console.log(' $ mocha-phantomjs http://testserver.com/file.html');
console.log('');
});
program.parse(process.argv);
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; };
if (arg.match(/http:\/\//)) { return arg; };
if (arg.match(/https:\/\//)) { return arg; };
if (exists(arg)) { return arg; };
if (exists(cwd+'/'+arg)) { return fs.realpathSync(cwd+'/'+arg); };
return arg;
}();
var phantomjs = spawn('phantomjs', [script, page, reporter, agent]);
phantomjs.stdout.on('data', function(data){
print(data.toString());
})
phantomjs.on('exit', function(code){
process.exit(code);
})
Jump to Line
Something went wrong with that request. Please try again.