nathanboktae / mocha-casperjs

Write CasperJS tests using Mocha
MIT License
120 stars 29 forks source link

Other exports from casper module #16

Closed charandas closed 10 years ago

charandas commented 10 years ago

casper module provides an XPath selector helper called selectXPath in casperjs.

I think it would be handy to expose selectXPath in cli.js like thus:

// Load xPath helper
this.selectXPath = require('casper').selectXPath;

// Load casper
this.casper = require('casper').create({
...

Are you cool with that - or do you have other ideas around structuring the this instance? Shall I make a PR?

nathanboktae commented 10 years ago

Maybe, is it that you just don't want to include that 1-liner in all your tests?

That module is really boring :P s -> { type: 'xpath', path: s }

charandas commented 10 years ago

I guess, it goes back to reducing code-duplication. Depending on casperjs definition would be philosophically closer to good development for me.

nathanboktae commented 10 years ago

Yeah true, the CLI is intended to wire up the common use cases, leaving the core more pure for programmatic usage. Being that it already looks for chai and casper-chai, I can see it pulling up this module too. Yup send a PR.

charandas commented 10 years ago

Ok. Will send it soon. @nathanboktae

I do have one more related question: why are the casperjs options different between all.coffee test spec and bin/mocha-casperjs (excepting the obvious reason of variable arguments for the deliverable), specifically the missing mocha-casperjs-path option?

  1. all.coffee:

    './bin/cli.js',
    '--mocha-path=node_modules/mocha',
    '--chai-path=node_modules/chai',
    '--casper-chai-path=node_modules/casper-chai'
  2. bin/mocha-casperjs:

    $mcPath/cli.js --mocha-casperjs-path=$mcPath/..

I am finding something rather strange about the XPath helper once I expose it as mentioned in the first comment. I can access it while using mocha-casperjs but cannot in the tests.

charandas commented 10 years ago

My test is dumb and I am not sure if it satisfies any purpose in this case, but just so you know, how I am trying to access the helper in all.coffee:

it 'should select by XPath using casper XPath helper', (done) ->
      thisShouldPass
        test: ->
          casper.waitForSelector 'h1', ->
            selectXPath.should.be.a.function

Once I can understand what's going under-the-hood, I can make the PR with/without this test, as you prefer.

nathanboktae commented 10 years ago

why are the casperjs options different between all.coffee test spec and bin/mocha-casperjs

The dependencies for mocha-casperjs are peer dependencies, so for testing locally I have to point them to the developer dependencies, so that's why they have extra paths. as for the missing mocha-casperjs-path, it's abusing the fact that the working directory is what mocha-casperjs-path is supposed to be. I am not happy with all the funky path specifications and require dances needed... it's complex due to global vs local, require.paths not being supported for a while and capserj's wrapped require, but it's another issue.

As for the test, that looks fine. You don't need to do a waitForSelector so you can remove line 4.

charandas commented 10 years ago

@nathanboktae thanks. Yes, with the waitForSelector removed, the test is still failing though. Any reason the function would be undefined?

nathanboktae commented 10 years ago

It should be there.... Push your feature branch to your repository and I can take a look.

charandas commented 10 years ago

@nathanboktae Thanks much. Commit made. I am running test using npm test.

charandas commented 10 years ago

I gave you full permissions to my fork in case you decide to make additional changes.

nathanboktae commented 10 years ago

Your test needed to pass in the done to thisShouldPass, and also call the right chai assertion:

it 'should select by XPath using casper XPath helper', (done) ->
     thisShouldPass
        test: ->
            selectXPath.should.be.a('function')
     , done

Yeah CoffeeScript can be hard to read sometimes, ironically. I have a love-hate relationship to it.

charandas commented 10 years ago

Thanks for the direction and merge. Shorter name looks good. :thumbsup: