diff --git a/phantom.go b/phantom.go index 0506146..572b956 100644 --- a/phantom.go +++ b/phantom.go @@ -27,13 +27,13 @@ Create a new `Phantomjs` instance and return it as a pointer. If an error occurs during command start, return it instead. */ -func Start(args ...string) (*Phantom, error) { +func Start(cmdPath string, args ...string) (*Phantom, error) { if nbInstance == 0 { wrapperFileName, _ = createWrapperFile() } nbInstance += 1 args = append(args, wrapperFileName) - cmd := exec.Command("phantomjs", args...) + cmd := exec.Command(cmdPath, args...) inPipe, err := cmd.StdinPipe() if err != nil { diff --git a/phantom_example_test.go b/phantom_example_test.go index a077d6d..60fd3c0 100644 --- a/phantom_example_test.go +++ b/phantom_example_test.go @@ -5,7 +5,7 @@ import ( ) func ExampleWithResult() { - p, err := Start() + p, err := Start("phantomjs") if err != nil { panic(err) } @@ -24,7 +24,7 @@ func ExampleWithResult() { } func ExampleWithError() { - p, err := Start() + p, err := Start("phantomjs") if err != nil { panic(err) } diff --git a/phantom_test.go b/phantom_test.go index 6cf8452..33bfd77 100644 --- a/phantom_test.go +++ b/phantom_test.go @@ -5,53 +5,53 @@ import ( ) func TestStartStop(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) err = p.Exit() failOnError(err, t) } func TestStartStopWithArgs(t *testing.T) { - p, err := Start("--web-security=no") + p, err := Start("phantomjs", "--web-security=no") failOnError(err, t) err = p.Exit() failOnError(err, t) } func TestRunACommand(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") defer p.Exit() failOnError(err, t) assertFloatResult("function(){ return 2 + 1; }\n", 3, p, t) } func TestRunACommandWithoutLineBreak(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") defer p.Exit() failOnError(err, t) assertFloatResult("function(){ return 2 + 2; }", 4, p, t) } func TestRunAnAsyncCommand(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() assertFloatResult("function(done){ done(2 + 3) ; }\n", 5, p, t) - p1, err := Start() + p1, err := Start("phantomjs") failOnError(err, t) defer p1.Exit() assertFloatResult("function(done){ setTimeout(function() { done(3 + 3) ; }, 0); }\n", 6, p1, t) } func TestRunMultilineCommand(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() assertFloatResult("function() {\n\t return 3+4;\n}\n", 7, p, t) } func TestRunMultipleCommands(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() assertFloatResult("function() {return 1}", 1, p, t) @@ -60,7 +60,7 @@ func TestRunMultipleCommands(t *testing.T) { } func TestLoadGlobal(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() p.Load("function result(result) { return result; }\nvar a = 2") @@ -68,14 +68,14 @@ func TestLoadGlobal(t *testing.T) { } func TestMessageSentAfterAnErrorDontCrash(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() p.Run("function(done) {done(null, 'manual'); done('should not panic');}", nil) } func TestDoubleErrorSendDontCrash(t *testing.T) { - p, err := Start() + p, err := Start("phantomjs") failOnError(err, t) defer p.Exit() p.Run("function(done) {done(null, 'manual'); done(null, 'should not panic');}", nil)