iamchrismiller / grunt-casper

Run CasperJS Scripts/Functional Tests
Other
69 stars 38 forks source link

Path to casper and phantom #4

Closed drorma closed 11 years ago

drorma commented 11 years ago

Be nice to be able to specify the paths to casper and phantom as options in the grunt file, rather than having to add them to the environment variable

drorma commented 11 years ago

Never mind.

process.env.PATH = process.env.PATH + ":" + __dirname +
    '/tools/phantomjs/bin:' + __dirname + '/tools/casperjs/bin';

Before the grunt config seems to do the trick.

ivanoats commented 10 years ago

Did you put the above code in your Gruntfile.js ?

drorma commented 10 years ago

Yeah:

process.env.PATH = process.env.PATH + ':' + __dirname +
        '/tools/phantomjs/bin:' + __dirname + '/tools/casperjs/bin';

module.exports = function(grunt) {

        // Project configuration.
        grunt.initConfig({
...
iamchrismiller commented 10 years ago

Phantom already supports Environment Variables.

You can override PhantomJS like so: process.env["PHANTOMJS_EXECUTABLE"] = /path/to/binary

As of v0.3.3 - Casper is now managed through a local dependency (npm install)

I can also expose another environment variable for casper but am curious as to why you need this?

ivanoats commented 10 years ago

I'm trying to create a test case project for this but haven't had time yet.

This issue arose when I had at one point installed phantomjs via homebrew, thus the original path was /usr/local/bin/phantomjs. I removed that install, because I wanted npm to manage casperjs and phantomjs. So then I did npm install -g phantomjs casperjs.

Somehow my project and the grunt-casper npm package was still looking for phantomjs in /usr/local/bin/phantomjs, but it wasn't there anymore.

I made a temporary work-around by making a symbolic link ln -s /usr/local/opt/nvm/v0.10.26/bin/phantomjs /usr/local/bin/phantomjs but I'd love to dig in to why it's not working with setting the environment variable, or @drorma 's code above.

iamchrismiller commented 10 years ago

I just uninstalled phantomjs npm install phantomjs -g

which phantomjs - /usr/local/bin/phantomjs

So it installs correctly for me from scratch.

It may have something to do with NVM and the pathing around that.

ivanoats commented 10 years ago

Yes, thanks. I'd love to figure out how to make this work with NVM, because without NVM my npm is frequently out of date. I brew install nvm instead of brew install node now. Because, I want npm to manage my node packages instead of homebrew. Package managers managing package managers... :warning:

It looks like I should write a check around line 49 of grunt-casper/tasks/lib/casper.js to see if phantomjs.path is pointing at a file that is actually executable, and at least raise an error if it's not. https://github.com/iamchrismiller/grunt-casper/blob/master/tasks/lib/casper.js#L49

Do you think this is the right approach?

ivanoats commented 10 years ago

Sent a PR https://github.com/iamchrismiller/grunt-casper/pull/36