{"name":"mocha-phantomjs-core","description":"Run mocha tests in phantomjs","keywords":["phantomjs","mocha","test","runner","command line","browser"],"version":"0.0.1","author":{"name":"Nathan Black","email":"nathan@nathanblack.org","url":"https://github.com/nathanboktae"},"licenses":[{"type":"MIT","url":"http://github.com/metaskills/mocha-phantomjs-core/blob/master/MIT-LICENSE"}],"contributors":[{"name":"Ken Collins","email":"ken@metaskills.net","url":"http://metaskills.net/"}],"repository":{"type":"git","url":"http://github.com/metaskills/mocha-phantomjs-core.git"},"bugs":{"url":"http://github.com/metaskills/mocha-phantomjs-core/issues"},"main":"./lib/mocha-phantomjs.coffee","scripts":{"test":"mocha --compilers coffee:coffee-script test/mocha-phantomjs.coffee -t 20000 -R spec"},"peerDependencies":{"phantomjs":"~1.9.1"},"dependencies":{"mocha":"~1.20.1","commander":"~2.0.0"},"devDependencies":{"phantomjs":"~1.9.1","chai":"1.8.x","coffee-script":"1.6.x","requirejs":"2.1.x"},"gitHead":"251edff040ec4207f896c7eb10c479094ba31e3a","homepage":"https://github.com/metaskills/mocha-phantomjs-core","_id":"mocha-phantomjs-core@0.0.1","_shasum":"810f902f0187789371f301775951b41113c5a7d8","_from":".","_npmVersion":"2.7.4","_nodeVersion":"0.12.2","_npmUser":{"name":"nathanboktae","email":"nathan@nathanblack.org"},"maintainers":[{"name":"nathanboktae","email":"nathan@nathanblack.org"}],"dist":{"shasum":"810f902f0187789371f301775951b41113c5a7d8","tarball":"http://registry-npm.ywwl.com/mocha-phantomjs-core/download/mocha-phantomjs-core-0.0.1.tgz","integrity":"sha512-9JyPn0PMyHFVrgiRaicbkZjNc+fI+G2LtkxrXgOxEA8dH4Q64ckknxWvn9xvA6QKLwgSIhc1RqvEET1qo17n0Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG2Ne7rR27Uf/e7r+AxozzEuv/720C1gsfUC99y+lMwtAiEAia38qIyEt/f0RzKokNWXWh5PxOFv1mIFhpNXixjq3/Q="}],"size":10754,"noattachment":false,"key":"/mocha-phantomjs-core/-/mocha-phantomjs-core-0.0.1.tgz"},"directories":{},"readme":"# Run client-side Mocha tests in PhantomJS or SlimerJS\n\n[![Join the chat at https://gitter.im/nathanboktae/mocha-phantomjs-core](https://badges.gitter.im/nathanboktae/mocha-phantomjs-core.svg)](https://gitter.im/nathanboktae/mocha-phantomjs-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n[![Build Status](https://secure.travis-ci.org/nathanboktae/mocha-phantomjs-core.png)](http://travis-ci.org/nathanboktae/mocha-phantomjs-core)\n\nSo now that you got your tests [Mocha](http://mochajs.org/) running on a simple flat HTML file, now how do you run them in your CI environment? [Karma](http://karma-runner.github.io/)? what is this `karma.conf.js` file I have to write? and some background runner task? how do I grep over just a few tests? wait I need a to also install a launcher for phantomjs or slimerjs too? bleck.\n\nRather than force you to redo your test harness and local development testing, simply run `phantomjs mocha-phantomjs-core.js spec tests/mytests.html` and be done with it. `mocha-phantomjs-core` builds on top of what you already have, with no high barrier to entry like Karma.\n\nNew in 2.0 is [SlimerJS](https://slimerjs.org) support! There are [some bugs](https://github.com/laurentj/slimerjs/issues/created_by/nathanboktae) still to be worked out, but now you can run your tests headless on the latest firefox version instead of an old QtWebKit!\n\n## Installation\n\n```\nnpm install mocha-phantomjs-core\n```\n\n## Usage\n\n```\n<phantomjs|slimerjs> mocha-phantomjs-core.js <TESTS> <REPORTER> <CONFIG as JSON>\n\nExamples:\nphantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js tests.html\nphantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js tests/runner.html xunit > results.xml\n/usr/local/bin/phantomjs /path/to/mocha-phantomjs-core.js tests.html spec \"{\\\"useColors\\\":true}\"\n```\n\nDue to resource loading timing issues with external sources, you may need to call `initMochaPhantomJS` before calling any mocha setup functions like `setup()`, `ui()`, etc. `mocha-phantomjs-core` will notify you if you need this, and if so, add a check for it before your mocha setup code:\n\n```\nif (typeof initMochaPhantomJS === 'function') {\n  initMochaPhantomJS()\n}\n```\n\nThis can be avoided by removing unnessecary external resources like fonts, CSS, etc. from your tests, or simply having `mocha.js` as the first script loaded.\n\n### Config\n\nIt's best to always refer to [the tests](https://github.com/nathanboktae/mocha-phantomjs-core/blob/master/test/core.tests.coffee) for full usage and examples.\n\n#### `reporter`\n\nOne of mocha's built in reporters, or a full path to a file for a 3rd party reporter (see below on how to write one).\n\n#### `grep`\n\na string to pass to `mocha.grep()` to filter tests. also provide `invert: true` if you want to invert the grep and filter out tests.\n\n#### `useColors`\n\nBoolean. Force or suppress color usage. Defaults to what your terminal supports.\n\n#### `bail`\n\nBoolean. Stop the test run at the first failure if true. Defaults to false.\n\n#### `ignoreResourceErrors`\n\nBoolean. Suppress the resource failure output that `mocha-phantomjs-core` will output by default.\n\n#### `loadTimeout`\n\nTime in milliseconds after the page loads that `mocha.run` needs to be called. Defaults to 10 seconds. \n\n#### `timeout`\n\nSets mocha's root suite timeout. Defers to mocha's default if omitted. \n\n#### `viewportSize`\n\nSets the viewport size. Specify `height` and `width`, like below:\n\n#### `settings`\n\nIf you need to pass [additional settings](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#webpage-settings) to the phantomjs webpage, you can specify an object of settings here, including common ones like `userAgent` and `loadImages`.\n\n```\nphantomjs mocha-phantomjs-core.js dot tests/mytests.html \"{\\\"viewportSize\\\":{\\\"width\\\":720,\\\"height\\\":480}}\"\n```\n\nPreviously `mocha-phantomjs` required you to look for `mochaPhantomJS` and then use `mochaPhantomJS.run()`. That is no longer required. Call `mocha.run()` as you normally would.\n\n## Screenshots\n\n`mocha-phantomjs-core` supports creating screenshots from your test code. For example, you could write a function like below into your test code.\n\n```javascript\nfunction takeScreenshot() {\n  if (window.callPhantom) {\n    var date = new Date()\n    var filename = \"screenshots/\" + date.getTime()\n    console.log(\"Taking screenshot \" + filename)\n    callPhantom({'screenshot': filename})\n  }\n}\n```\n\nIf you want to generate a screenshot for each test failure you could add the following into your test code.\n\n```javascript\n  afterEach(function () {\n    if (this.currentTest.state == 'failed') {\n      takeScreenshot()\n    }\n  })\n```\n\n## Send event\n\n`mocha-phantomjs-core` supports [sending events](http://phantomjs.org/api/webpage/method/send-event.html)\nfrom your test code to allow for more ouside testing. For example, to trigger an external `click` event:\n\n```javascript\nif (window.callPhantom) {\n  window.callPhantom({\n    sendEvent: ['click', 10, 10] // array of arguments\n  });\n}\n```\n\n## Changing `viewportSize`\n\n`mocha-phantomjs-core` now also supports changing of viewportSize (the simulated `window` size for the headless browser) - while running tests.\n\n```javascript\nif (window.callPhantom) {\n  window.callPhantom({\n    viewportSize : {\n      width : 100,\n      height : 100\n    }\n  });\n}\n```\n\nThis comes on particlarly handy when testing for responsiveness.\n\n## Environment variables\n\n`mocha-phantomjs-core` will expose environment variables at `mocha.env`\n\n## Third Party Reporters\n\nMocha has support for custom [3rd party reporters](https://github.com/mochajs/mocha/wiki/Third-party-reporters), and mocha-phantomjs does support 3rd party reporters, but keep in mind - *the reporter does not run in Node.js, but in the browser, and node modules can't be required.* You need to only use basic, vanilla JavaScript when using third party reporters. However, some things are available:\n\n- `require`: You can only require other reporters, like `require('./base')` to build off of the BaseReporter\n- `exports`, `module`: Export your reporter class as normal\n- `process`: use `process.stdout.write` preferrably to support the `--file` option over `console.log` (see #114)\n\nAlso, no compilers are supported currently, so please provide plain ECMAScript 5 for your reporters.\n\n## Testing\n\n```\nnpm install\nnpm test\n```\n\nTravis CI does a matrix build against phantomjs 1.9.7 and 2.0.0, currently. See `.travis.yml` for the latest.\n\nTo debug an individual test, since they are just process forks, you may want to run them directly, like\n\n```\nphantomjs mocha-phantomjs-core.js test/timeout.html spec \"{\\\"timeout\\\":500}\"\n```\n\n## License\n\nReleased under the MIT license. Copyright (c) 2015 Ken Collins and Nathan Black.\n\n","publish_time":1428986551645,"_cnpm_publish_time":1428986551645,"dist-tags":{"latest":"2.1.2"}}