Skip to content

Commit

Permalink
Function.prototype.bind fix for PhantomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdeandrade committed Nov 20, 2014
1 parent b02ad13 commit f5d5192
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bin/cli.js
Expand Up @@ -14,6 +14,7 @@ var port = Number(args.p || args.port) || 3000;
var help = args.help || args.h || args._.length === 0; var help = args.help || args.h || args._.length === 0;
var phantom = args.b || args.phantom || args.phantomjs; var phantom = args.b || args.phantom || args.phantomjs;
var report = args.p || args.report || args.istanbul; var report = args.p || args.report || args.istanbul;
var debug = args.d || args.debug;


if (help) { if (help) {
var helpText = [ var helpText = [
Expand All @@ -25,6 +26,7 @@ if (help) {
' -p --port <number> The port number to run the server on (default: 3000)', ' -p --port <number> The port number to run the server on (default: 3000)',
' -b --phantom Use the phantom headless browser to run tests and then exit with the correct status code (if tests output TAP)', ' -b --phantom Use the phantom headless browser to run tests and then exit with the correct status code (if tests output TAP)',
' -r --report Generate coverage Istanbul report. Repeat for each type of coverage report desired. (default: text only)', ' -r --report Generate coverage Istanbul report. Repeat for each type of coverage report desired. (default: text only)',
' -d --debug Debug PhantomJS by printing subprocess stdout and stderr.'
'', '',
'Example:', 'Example:',
' run-browser test-file.js --port 3030 --report text --report html --report=cobertura', ' run-browser test-file.js --port 3030 --report text --report html --report=cobertura',
Expand All @@ -40,5 +42,9 @@ server.listen(port);
if (!phantom) { if (!phantom) {
console.log('Open a browser and navigate to "http://localhost:' + port + '"'); console.log('Open a browser and navigate to "http://localhost:' + port + '"');
} else { } else {
runbrowser.runPhantom('http://localhost:' + port + '/'); var proc = runbrowser.runPhantom('http://localhost:' + port + '/');
if (debug) {
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
}
} }
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -65,6 +65,10 @@ function createHandler(filename, reports, phantom) {
files = files.map(normalizePath); files = files.map(normalizePath);
files.unshift(path.join(__dirname, '/lib/override-log.js')); files.unshift(path.join(__dirname, '/lib/override-log.js'));


if (phantom) {
files.unshift(path.join(__dirname, '/lib/phantom-function-bind-shim.js'));
}

var b = browserify(files); var b = browserify(files);
if (reports) b.transform(instrumentTransform()); if (reports) b.transform(instrumentTransform());
return b.bundle({debug: true}, onBrowserifySrc) return b.bundle({debug: true}, onBrowserifySrc)
Expand Down
2 changes: 2 additions & 0 deletions lib/phantom-function-bind-shim.js
@@ -0,0 +1,2 @@
'use strict';
Function.prototype.bind = require("function-bind");
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
"dependencies": { "dependencies": {
"browserify": "^3.28.0", "browserify": "^3.28.0",
"browserify-istanbul": "^0.1.2", "browserify-istanbul": "^0.1.2",
"function-bind": "^1.0.2",
"glob": "~3.2.7", "glob": "~3.2.7",
"global": "^4.3.0", "global": "^4.3.0",
"istanbul": "^0.3.2", "istanbul": "^0.3.2",
Expand Down

0 comments on commit f5d5192

Please sign in to comment.