iamchrismiller / grunt-casper

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

CasperJS Binary Not Found #34

Closed rbonvall closed 10 years ago

rbonvall commented 10 years ago

I'm trying to use grunt-casper in a project. I installed it the common way: npm install grunt-casper --save-dev.

I have the following configuration in my Gruntfile.coffee:

casper:
  functional:
    options:
      test: true
    files:
      'f.xml': ['.../tests']

When I run grunt functional, I get the following output:

Running "casper:functional" (casper) task
>> CasperJS Binary Not Found, try `npm install`
Casper Task 'casper:functional' took ~1ms to run
Warning: Task "casper:functional" failed. Use --force to continue.

Aborted due to warnings.

I added a line manually in tasks/lib/casper.js to print path.resolve(casperBin), and the path I got is just wrong. It prints:

$PROJECT_ROOT/node_modules/.bin/casperjs

while the binary can be found in the following paths:

> find $PROJECT_ROOT -name casperjs -type f -follow
$PROJECT_ROOT/node_modules/grunt-casper/node_modules/.bin/casperjs
$PROJECT_ROOT/node_modules/grunt-casper/node_modules/casperjs
$PROJECT_ROOT/node_modules/grunt-casper/node_modules/casperjs/rubybin/casperjs

The binary is searched in a path relative to the project root. It works when the project is grunt-casper, but not when the latter is just a dependency for another project.

Is this like this by design? Was it working correctly for all of you?

iamchrismiller commented 10 years ago

Try version 0.3.1. This should be resolved. I still had a global version sitting around, removed that and was able to reproduce. Fixed in 0.3.1 exported casperjs bin at the top level

rbonvall commented 10 years ago

I upgraded from 0.3.0 to 0.3.1 and it worked. Thanks!

timjacobi commented 10 years ago

If casperjs is already installed locally the installation of this package will not pull casperjs into the packages node_modules folder so you'll still get the error.

abeadam commented 10 years ago

@timjacobi I hit that same issue, fixed by checking for installed casper in the outer node_modules if it's not inside grunt-casper https://github.com/iamchrismiller/grunt-casper/blob/master/tasks/lib/casper.js#L63 changed to

        if (!fs.existsSync(casperBin)) {
              //swap to the location outside and check if it's installed locally there
              localModulesPath = path.resolve(__dirname, '../../..');
              casperBin = localModulesPath + casperBinaryPath;
              if (!fs.existsSync(casperBin)) {
                              grunt.log.error("CasperJS Binary Not Found, try `npm install`");
                              return next(true);
              }
        }
timjacobi commented 10 years ago

How about a pull request? :)

ebourmalo commented 10 years ago

I encountered the same issue with last version (0.3.8).

Here is the pull request to fix it @iamchrismiller : https://github.com/iamchrismiller/grunt-casper/pull/44

It just try to find the casperjs bin in the project local modules if not found locally in grunt-casper. Thanks to @abeadam for the fix :)