nathanboktae / mocha-phantomjs-core

Easiest way to run client-side Mocha tests in PhantomJS or SlimerJS :ghost:
MIT License
34 stars 11 forks source link

Feature: give options as a path to a JSON file #23

Open axelpale opened 8 years ago

axelpale commented 8 years ago

First of all, thanks for @nathanboktae for all the work on mocha-phantomjs. A big thing for devs like me.

But to the subject, I guess you have already thought about this. Currently the options are given in a quite grubby way:

$ phantomjs mocha-phantomjs-core.js tests/testrunner.html spec '{\"viewportSize\": {\"width\":512, \"height\":512}, \"ignoreResourceErrors\": true}'

The quoted/escaped JSON is hard to write and read. The number of quotes increases if the line is to be included in package.json script. In my case, the tests are run by $ npm run test so in the package.json I have something similar to the one above.

What if we give a path to a JSON file? Like this:

$ phantomjs mocha-phantomjs-core.js tests/testrunner.html spec .mocha-phantomjs-core.json

or

$ phantomjs mocha-phantomjs-core.js tests/testrunner.html spec --config=.mocha-phantomjs-core.json

and have a nice and readable .mocha-phantomjs-core.json:

{
  viewportSize: {
    width: 512,
    height: 512
  },
  ignoreResourceErrors: true
}

Would that be easy to implement?

nathanboktae commented 8 years ago

Actually I want to move CLI parsing of mocha-phantomjs into the core. I started work on it just since I saw this issue (thanks for prompting me more) - https://github.com/nathanboktae/mocha-phantomjs-core/tree/cli-parsing

So in the future your example will be:

mocha-phantomjs tests/testrunner.html -v 512x512 --ignore-resource-errors

I'll add in a little shell wrapper for this to phantomjs and slimerjs too as mocha-phantomjs and mocha-slimerjs respectively

axelpale commented 8 years ago

Great :) As long as we are not dependent on the version of phantomjs, this seems good to me. Although the command phantomjs mocha-phantomjs-core.js tests/testrunner.html ... is nicely transparent, I can agree it is a bit tedious to point directly to the file mocha-phantomjs-core.js. In practise I ended doing it like this: phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js tests/testrunner.html ....

nathanboktae commented 8 years ago

As long as we are not dependent on the version of phantomjs

Absolutely not. The shell wrapper would only work if you got things in your path. and I might not do it in the end if it's a pain :) but it should help out the common case of phantomjs in your path and using npm scripts so you can just do

{
  "scripts": {
     "test": "mocha-phantomjs tests/testrunner.html"
  }
}
DanielRuf commented 6 years ago

So far this does not work in npm scripts in package.json.