Skip to content

Commit

Permalink
Merge pull request #64 from alexeykuzmin/patch-1
Browse files Browse the repository at this point in the history
Add ability to use specific PhantomJS binary via "path" argument
  • Loading branch information
metaskills committed May 19, 2013
2 parents 659e162 + c6ec5fc commit f30affe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ Usage: mocha-phantomjs [options] page
-s, --setting <key>=<value> specify phantomjs WebPage settings
-v, --view <width>x<height> specify phantomjs viewport size
-C, --no-color disable color escape codes
-p, --path <path> path to PhantomJS binary
Examples:
$ mocha-phantomjs -R dot /test/file.html
$ mocha-phantomjs http://testserver.com/file.html
$ mocha-phantomjs -s localToRemoteUrlAccessEnabled=true -s webSecurityEnabled=false http://testserver.com/file.html
$ mocha-phantomjs -p ~/bin/phantomjs /test/file.html
```

Now as an node package, using `mocha-phantomjs` has never been easier. The page argument can be either a local or fully qualified path or a http or file URL. See the list of reporters below for acceptable options to the `--reporter` argument. See [phantomjs WebPage settings](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-settings) for options that may be supplied to the `--setting` argument.
Expand Down
25 changes: 16 additions & 9 deletions bin/mocha-phantomjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ program
.option('-h, --header <name>=<value>', 'specify custom header', header)
.option('-s, --setting <key>=<value>', 'specify specific phantom settings', setting)
.option('-v, --view <width>x<height>', 'specify phantom viewport size', viewport)
.option('-C, --no-color', 'disable color escape codes');
.option('-C, --no-color', 'disable color escape codes')
.option('-p, --path <path>', 'path to PhantomJS binary');

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(' $ mocha-phantomjs -p ~/bin/phantomjs /test/file.html');
console.log('');
});

Expand Down Expand Up @@ -87,14 +89,19 @@ var config = JSON.stringify({
var spawnArgs = [script, page, reporter, config];

var phantomjs;
for (var i=0; i < module.paths.length; i++) {
var bin = path.join(module.paths[i], '.bin/phantomjs');
if (process.platform === 'win32') {
bin += '.cmd';
}
if (exists(bin)) {
phantomjs = spawn(bin, spawnArgs);
break;
if (program.path !== undefined) {
phantomjs = spawn(program.path, spawnArgs);
}
if (phantomjs === undefined) {
for (var i=0; i < module.paths.length; i++) {
var bin = path.join(module.paths[i], '.bin/phantomjs');
if (process.platform === 'win32') {
bin += '.cmd';
}
if (exists(bin)) {
phantomjs = spawn(bin, spawnArgs);
break;
}
}
}
if (phantomjs === undefined) { phantomjs = spawn('phantomjs', spawnArgs); }
Expand Down

0 comments on commit f30affe

Please sign in to comment.