Skip to content

Commit 9fed801

Browse files
committed
Merge v4 into master
2 parents 11cb35a + 7f614b3 commit 9fed801

30 files changed

+281
-872
lines changed

README.md

+12-26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# PhantomJS Runners for Mocha
22

3-
[Mocha](http://mochajs.org/) is a feature-rich JavaScript test framework running on node and the browser. Along with the [Chai](http://chaijs.com) assertion library they make an impressive combo. [PhantomJS](http://phantomjs.org) is a headless WebKit with a JavaScript/CoffeeScript API. It has fast and native support for various web standards like DOM handling, CSS selectors, JSON, Canvas, and SVG.
3+
[Mocha](http://mochajs.org/) is a feature-rich JavaScript test framework running on node and the browser. Along with the [Chai](http://chaijs.com) assertion library they make an impressive combo. [PhantomJS](http://phantomjs.org) is a headless WebKit with a JavaScript API.
44

5-
The mocha-phantomjs project provides a `mocha-phantomjs.coffee` script file and extensions to drive PhantomJS while testing your HTML pages with Mocha from the console. The preferred usage is to install `mocha-phantomjs` via node's packaged modules and use the `mocha-phantomjs` binary wrapper. Tested with Mocha 1.12.x, Chai 1.7.x, and PhantomJS 1.9.1.
6-
7-
* **Since version 3.0 of mocha-phantomjs, you must use PhantomJS 1.9.1 or higher.**
5+
Since 4.0, the phantomjs code now is in [mocha-phantomjs-core](https://github.com/nathanboktae/mocha-phantomjs-core). If you need full control over which phantomjs version to use and where to get it, or want to use it more programatically like a build system plugin, please use that package directly. This project is a node.js CLI around it.
86

97
[![Build Status](https://secure.travis-ci.org/nathanboktae/mocha-phantomjs.png)](http://travis-ci.org/nathanboktae/mocha-phantomjs)
108

11-
129
# Key Features
1310

1411
### Standard Out
@@ -21,21 +18,16 @@ Proper exit status codes from PhantomJS using Mocha's failures count. So in stan
2118

2219
### Mixed Mode Runs
2320

24-
You can use your existing Mocha HTML file reporters side by side with mocha-phantomjs. This gives you the option to run your tests both in a browser or with PhantomJS. Since mocha-phantomjs needs to control when the `run()` command is sent to the mocha object, we accomplish this by setting the `mochaPhantomJS` on the `window` object to `true`. Below, in the usage section, is an example of a HTML structure that can be used both by opening the file in your browser or choice or using mocha-phantomjs.
25-
21+
You can use your existing Mocha HTML file reporters side by side with mocha-phantomjs. This gives you the option to run your tests both in a browser or with PhantomJS, with no changes needed to your existing test setup.
2622

2723
# Installation
2824

29-
We distribute [mocha-phantomjs as an npm](https://npmjs.org/package/mocha-phantomjs) that is easy to install. Once done, you will have a `mocha-phantomjs` binary. See the next usage section for docs or use the `-h` flag.
30-
31-
Since 3.4, we now declare phantomjs as a peer dependency, and it will be installed adjacent to `mocha-phantomjs` automatically. You may use `-p` to provide an explicit path to phantomjs, or call phantomjs directly yourself via `phantomjs lib/mocha-phantomjs.coffee <page> <reporter> <config-as-JSON>`. The later approach is recommended for build system plugins to avoid another process fork.
32-
33-
Due to [a bug in phantomjs 1.9.8+](https://github.com/nathanboktae/mocha-phantomjs/issues/167), mocha-phantomjs currnently caps its peer depedency to `1.9.7-15`. If you are having install errors due to peer depdendency resolution conflics, expliclity declare your dependency as `"phantomjs": "1.9.7-15"`, or expliclity install 1.9.7, like `npm install [email protected]`.
25+
We distribute [mocha-phantomjs as an npm package](https://npmjs.org/package/mocha-phantomjs) that is easy to install. Once done, you will have a `mocha-phantomjs` binary. See the next usage section for docs or use the `-h` flag.
3426

3527
# Usage
3628

3729
```
38-
Usage: mocha-phantomjs [options] page
30+
Usage: mocha-phantomjs [options] page
3931
4032
Options:
4133
@@ -56,6 +48,7 @@ Usage: mocha-phantomjs [options] page
5648
-C, --no-color disable color escape codes
5749
-p, --path <path> path to PhantomJS binary
5850
51+
Any other options are passed to phantomjs (see `phantomjs --help`)
5952
6053
Examples:
6154
@@ -67,7 +60,7 @@ Usage: mocha-phantomjs [options] page
6760

6861
Now as an node package, using `mocha-phantomjs` has never been easier. The page argument can be either a local or fully qualified path or a http or file URL. `--reporter` may be a built-in reporter or a path to your own reporter (see below). See [phantomjs WebPage settings](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-settings) for options that may be supplied to the `--setting` argument.
6962

70-
Your HTML file's structure should look something like this. The reporter set below to `html` is only needed for viewing the HTML page in your browser. The `mocha-phantomjs.coffee` script overrides that reporter value. The conditional run at the bottom allows the mixed mode feature described above.
63+
Since 4.0, you need no modifications to your test harness markup file to run. Here is an example `test.html`:
7164

7265
```html
7366
<html>
@@ -81,14 +74,13 @@ Your HTML file's structure should look something like this. The reporter set bel
8174
<script src="mocha.js"></script>
8275
<script src="chai.js"></script>
8376
<script>
84-
mocha.ui('bdd');
85-
mocha.reporter('html');
86-
expect = chai.expect;
77+
mocha.ui('bdd')
78+
expect = chai.expect
8779
</script>
80+
<script src="src/mycode.js"></script>
8881
<script src="test/mycode.js"></script>
8982
<script>
90-
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
91-
else { mocha.run(); }
83+
mocha.run()
9284
</script>
9385
</body>
9486
</html>
@@ -186,13 +178,7 @@ We also use Travis CI to run our tests too. The current build status:
186178
[![Build Status](https://secure.travis-ci.org/nathanboktae/mocha-phantomjs.png)](http://travis-ci.org/nathanboktae/mocha-phantomjs)
187179

188180

189-
# Alternatives
190-
191-
* OpenPhantomScripts - https://github.com/mark-rushakoff/OpenPhantomScripts
192-
* Front Tests - https://github.com/Backbonist/front-tests
193-
194-
195181
# License
196182

197-
Released under the MIT license. Copyright (c) 2012 Ken Collins.
183+
Released under the MIT license. Copyright (c) 2015 Ken Collins, Nathan Black, and many generous GitHub Contributors.
198184

bin/mocha-phantomjs

+11-4
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ function resolveHooks(val) {
5858
}
5959

6060
program
61+
.allowUnknownOption()
6162
.version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
6263
.usage('[options] page')
6364
.option('-R, --reporter <name>', 'specify the reporter to use', 'spec')
6465
.option('-f, --file <filename>', 'specify the file to dump reporter output')
65-
.option('-t, --timeout <timeout>', 'specify the test startup timeout to use', parseInt, 6000)
66+
.option('-t, --timeout <timeout>', 'specify the test startup timeout to use', parseInt)
6667
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
6768
.option('-i, --invert', 'invert --grep matches')
6869
.option('-b, --bail', 'exit on the first test failure')
@@ -77,6 +78,8 @@ program
7778
.option('--ignore-resource-errors', 'ignore resource errors');
7879

7980
program.on('--help', function(){
81+
console.log(' Any other options are passed to phantomjs (see `phantomjs --help`)');
82+
console.log('');
8083
console.log(' Examples:');
8184
console.log('');
8285
console.log(' $ mocha-phantomjs -R dot /test/file.html');
@@ -90,7 +93,7 @@ program.parse(process.argv);
9093
if (!program.args.length) { program.outputHelp(); process.exit(1); };
9194
if (program.agent) { settings.userAgent = program.agent; }
9295

93-
var script = fs.realpathSync(__dirname + '/../lib/mocha-phantomjs.coffee');
96+
var script = fs.realpathSync(__dirname + '/../node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js');
9497
var reporter = program.reporter;
9598
var page = function(){
9699
var arg = program.args[0];
@@ -103,7 +106,7 @@ var page = function(){
103106
}();
104107
var config = JSON.stringify({
105108
hooks: program.hooks,
106-
timeout: program.timeout,
109+
timeout: program.timeout || 6000,
107110
cookies: cookies,
108111
headers: headers,
109112
settings: settings,
@@ -148,8 +151,12 @@ function launchFailure(e) {
148151
process.exit(-2);
149152
}
150153

154+
var unknown = program.parseOptions(process.argv).unknown.filter(function(u) {
155+
return u !== program.args[0]
156+
})
157+
151158
try {
152-
var phantomjs = spawn(phantomPath, [script, page, reporter, config]);
159+
var phantomjs = spawn(phantomPath, unknown.concat([script, page, reporter, config]))
153160
phantomjs.stdout.pipe(process.stdout);
154161
phantomjs.stderr.pipe(process.stderr);
155162
phantomjs.on('exit', function(code){

lib/mocha-phantomjs.coffee

-191
This file was deleted.

0 commit comments

Comments
 (0)