├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── app
├── console.js
├── frame.css
├── frame.html
├── grep.js
├── index.html
├── index.js
├── layout.js
├── options.js
├── run.js
├── socket.js
├── style.css
└── templates.js
├── bin
└── prova
├── docs
├── examples
└── man
├── example.js
├── index.js
├── lib
├── browser-command.js
├── browser-reporter.js
├── browser.js
├── browserify-transforms.js
├── cli.js
├── command.js
├── exec-first.js
├── launch.js
├── node-command.js
├── node-reporter.js
├── node-template.js
├── progress.js
├── refine.js
└── tests.js
├── package.json
├── templates
├── code.html
├── custom-frame.html
├── diff.html
├── error.html
├── frame.html
├── layout.html
├── node-browser-console.txt
├── node-browser-error-browser.txt
├── node-browser-error-no-stack.txt
├── node-browser-error.txt
├── node-browser-failed-result.txt
├── node-browser-instructions.txt
├── node-browser-launch.txt
├── node-browser-passed-result.txt
├── node-browser-test.txt
├── node-browser.txt
├── node-diff.txt
├── node-fail.txt
├── node-result-pass.txt
├── node-result.txt
├── overview.html
├── pass.html
├── stack-line.html
├── stack.html
├── test.html
└── waiting.html
└── test
├── altjs
├── test.coffee
└── test.gs
├── custom-frame.html
├── error.js
├── index.js
├── multiple.js
├── slow-errors.js
├── slow.js
└── test.coffee
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
3 | app/templates.js
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | test.js
3 | example
4 | examples
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | copyright (c) 2015, Azer Koçulu
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 | 2. Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
24 | The views and conclusions contained in the software and documentation are those
25 | of the authors and should not be interpreted as representing official policies,
26 | either expressed or implied, of the FreeBSD Project.
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## prova
2 |
3 | Node & Browser Test runner based on [Tape](http://github.com/substack/tape) and [Browserify](http://github.com/substack/node-browserify).
4 |
5 | Screencasts: [node.gif](https://dl.dropboxusercontent.com/s/8yyepixc0bbtby3/prova-node.gif), [browser.gif](https://dl.dropboxusercontent.com/s/wtzt78riv7vcp7n/prova.gif), [both.gif](https://i.cloudup.com/4jGix1WEDH.gif), [headless browser](https://i.cloudup.com/lWWplVaKta.png)
6 |
7 | Slides: [slides.com/azer/prova](http://slides.com/azer/prova)
8 |
9 | Features and screenshots:
10 |
11 | * Embeds [Tape](http://github.com/substack/tape)
12 | * Comes with a builtin web app to run tests on browser, sourcemaps are enabled.
13 | * Outputs less when tests pass ([Node](https://i.cloudup.com/ausJApnH1v.png), [Browser](https://i.cloudup.com/OKebjyRMfU.png))
14 | * Outputs more when tests fail ([Node](https://i.cloudup.com/R8KQ8Qwspz.png), [Browser](https://i.cloudup.com/nA08e0s60b.png))
15 | * Browser app runs tests inside of an iframe [Screenshot](https://i.cloudup.com/5n8H9AqMrf.png)
16 | * Uses [watchify](https://github.com/substack/watchify) to observe file changes and restart browser tests. [GIF Screenshot](https://dl.dropboxusercontent.com/s/wtzt78riv7vcp7n/prova.gif)
17 | * Lets filtering test cases (e.g node test.js -g foobar)
18 | * Comes with [browser-launcher](https://github.com/substack/browser-launcher) for [launching browsers automatically and headless testing](#launching-browsers-and-headless-testing). ([Screenshot](https://i.cloudup.com/lWWplVaKta.png))
19 | * Clickable error stacks on the browser: [Screenshot](https://i.cloudup.com/42iYw0WnPP.gif)
20 | * Optional progress bar for slow tests. GIFs: [Node](https://i.cloudup.com/PJR44iZStH.gif) / [Browser](https://cldup.com/n5miJIEN2G.gif)
21 |
22 | ## Install
23 |
24 | ```bash
25 | $ npm install -g azer/prova
26 | ```
27 |
28 | ## Usage
29 |
30 | Example test:
31 |
32 | ```js
33 | var test = require('prova')
34 |
35 | test('timing test', function (t) {
36 | t.plan(2)
37 |
38 | t.equal(typeof Date.now, 'function')
39 | var start = Date.now()
40 |
41 | setTimeout(function () {
42 | t.equal(Date.now() - start, 100)
43 | }, 100)
44 | })
45 | ```
46 |
47 | In Node, it will output:
48 |
49 | ```
50 | $ node test.js
51 | Passed 1 test.
52 | ```
53 |
54 | Or, in case it fails:
55 |
56 | 
57 |
58 | ### In Browser
59 |
60 | To run the tests in a web browser, just pass `-b` parameter:
61 |
62 | ```bash
63 | $ node test.js -b
64 | Visit localhost:7559 with a browser to start running the tests.
65 | ```
66 |
67 | Then visit `localhost:7559` in your web browser:
68 |
69 | 
70 |
71 | In case it fails, it'll show:
72 |
73 | 
74 |
75 | The web app uses [watchify](http://github.com/substack/watchify) to monitor file changes.
76 | So, you won't have to reload the page when you modify a source code.
77 |
78 | Prova runs the tests inside of an iframe. In case you test some UI stuff, you can open the iframe
79 | by clicking the `<` button on the right:
80 |
81 | 
82 |
83 | ### Multiple Tests
84 |
85 | Prova comes with a command-line script when you install it globally;
86 |
87 | ```bash
88 | $ npm install -g prova
89 | ```
90 |
91 | And it allows you running multiple tests on both Node and browser;
92 |
93 | ```bash
94 | $ prova test/foo.js test/bar.js
95 | ```
96 |
97 | ```bash
98 | $ prova test/**/*.js -b
99 | ```
100 |
101 | ### Launching Browsers and Headless Testing
102 |
103 | List the detected browsers;
104 |
105 | ```bash
106 | $ prova -l
107 | Available Browsers: safari v7.0.2, chrome v34.0.1847.116, phantom v1.9.7
108 | ```
109 |
110 | And launch after publishing the tests:
111 |
112 | ```bash
113 | $ prova -b -l safari
114 | ```
115 |
116 | If your system has Xvfb, you can pass `-e` parameter to open the browser headlessly:
117 |
118 | ```bash
119 | $ prova -b -l chrome -e
120 | ```
121 |
122 | Or you can just run the tests on PhantomJS:
123 |
124 | ```bash
125 | $ prova -b -l phantom
126 | ```
127 |
128 | If you get `no matches for` errors and you think that your system has that browser, try removing [browser-launcher](https://github.com/substack/browser-launcher)'s config:
129 |
130 | ```bash
131 | $ rm /Users/azer/.config/browser-launcher/config.json
132 | ```
133 |
134 | ### Browserify Transforms
135 |
136 | Prova automatically applies [bunch of transforms](https://github.com/azer/prova/blob/master/lib/browserify-transforms.js#L4) by looking at the file extension. If you'd like to use a transform that doesn't exist in Prova by default, you can choose it with a parameter;
137 |
138 | ```bash
139 | $ node test -b -t coffeeify
140 | ```
141 |
142 | Multiple transforms can be specified using comma;
143 |
144 | ```bash
145 | $ node test -b -t coffeeify,brfs,foo,bar
146 | ```
147 |
148 | ### Browserify Plugins
149 |
150 | Pass Browserify plugins passing `-u` or `--plugin` parameter;
151 |
152 | ```bash
153 | $ node test -b --plugin foo
154 | ```
155 |
156 | Use comma to separate multiple plugins;
157 |
158 | ```bash
159 | $ node test -b --plugin foo,bar
160 | ```
161 |
162 | ### Custom Frame Documents
163 |
164 | When you're running the tests on the browser, Prova has an empty HTML template that loads and runs the JavaScript tests.
165 | You can customize this HTML file with -f or --frame parameter:
166 |
167 | ```js
168 | $ node test -b -f test.html
169 | ```
170 |
171 | Click the arrow button on right middle to keep the frame open. You'll be seeing the HTML document and test results in the same screen.
172 |
173 | ### Manually Restarting Browser Tests
174 |
175 | Prova watches for changes and automatically restarts the browser tests (inside in an iframe) but in case you need, there is an endpoint for restarting all the tests by hitting an endpoint;
176 |
177 | ```
178 | $ curl localhost:7559/restart
179 | ```
180 |
181 | ### Loading Assets
182 |
183 | You may need to load your images, web workers etc. for testing. Prova allows you to load assets from your current directory via the `/assets/in` endpoint. Let's say you'd like to load a file called "foobar.png":
184 |
185 | ```
186 | $ curl http://localhost:7559/assets/in/foobar.png
187 | ```
188 |
189 | Should work for you.
190 |
191 | ### HTTP Proxy
192 |
193 | HTTP proxying is pretty useful to by-pass cross-domain issues (CORS) on the browser. You can easily point a URL to another host using `-y` / `--http-proxy` parameters:
194 |
195 | ```
196 | $ node test -b -y "/my-api=http://localhost:8080"
197 | ```
198 |
199 | Assuming that you'll be running your tests on `:7559`, any requests to `/my-api` will be streamed through `localhost:8080` in the above example.
200 |
201 | ## Command-line
202 |
203 | ```
204 | USAGE
205 |
206 | prova [filenames] [options]
207 |
208 | OPTIONS
209 |
210 | -g --grep Run tests matching with given pattern
211 |
212 | -b --browser Publishes the tests on 0.0.0.0:7559
213 | -o --port Publish the tests on given port number.
214 | -d --hostname Publish the tests on given hostname.
215 | -l --launch List available browsers to launch or launch specified browser.
216 | -e --headless Launch the browser headlessly. (Requires xvfb)
217 | -r --proxy Launch the browser with specified proxy configuration.
218 | -q --quit Shut down the browser server once all the tests are done.
219 | -f --frame Specify a custom document to run tests on browser. e.g node test -b -f custom.html
220 | -x --exec Execute given commmand before running the tests.
221 | -y --http-proxy Proxy requests matching with given pattern to a target. e.g -y "/images=localhost:8080"
222 |
223 | -t --transform Use given Browserify transforms. e.g node test -b -t coffeeify,brfs
224 | -u --plugin Use given Browserify plugins. e.g node test -b -u foo,bar
225 |
226 | -s --progress Show a progress bar. Useful when tests are running slow.
227 |
228 | -p --tap Output original Tap output without modifying anything.
229 |
230 | -C --no-console Disable showing browser console messages on command-line.
231 |
232 | -v --version Show version and exit
233 | -h --help Show help and exit
234 | --examples Show example commands
235 | ```
236 |
237 | ## Example Commands
238 |
239 | ```
240 | EXAMPLES
241 |
242 | 1. Run the tests on NodeJS.
243 |
244 | $ node test.js
245 | $ node test
246 | $ prova test/index.js
247 | $ prova
248 |
249 | All the above example commands will work same way. Prova assumes the filename of your test is either `test.js` or `test/index.js`
250 |
251 | 2. Publish the tests on localhost:7559, so you can run the tests on a web browser.
252 |
253 | $ node test.js -b
254 | $ prova test -b
255 | $ prova -b
256 |
257 | 3. Publish the tests on given host and port.
258 |
259 | $ node test.js -o 8080 -d foobar.net
260 | $ prova test.js -o 8080 -d foobar.net
261 |
262 | 4. Publish the tests and launch a browser to automatically run the tests.
263 |
264 | $ node test.js -b -l chrome
265 | $ prova test.js -b -l chrome
266 |
267 | 5. List the browsers that can be launched automatically.
268 |
269 | $ prova -l
270 | $ node test.js -l
271 |
272 | 6. Run the tests with PhantomJS.
273 |
274 | $ node test.js -b -l phantom
275 | $ prova test.js -b -l phantom
276 |
277 | 7. Run only specified tests with PhantomJS.
278 |
279 | $ node test.js -b -l phantom -g pattern
280 | $ prova test.js -b -l phantom -g pattern
281 |
282 | 8. Launch Chrome headlessly using xvfb:
283 |
284 | $ node test -b -l chrome -e
285 | $ prova test -b -l chrome -e
286 | ```
287 |
--------------------------------------------------------------------------------
/app/console.js:
--------------------------------------------------------------------------------
1 | var socket = require("./socket");
2 |
3 | module.exports = {
4 | override: all
5 | };
6 |
7 | function all () {
8 | var rpl = {};
9 | var name;
10 | for (name in console) {
11 | rpl[name] = override(name, console[name], console);
12 | }
13 |
14 | window.console = rpl;
15 | }
16 |
17 | function override (name, fn, console) {
18 | return function () {
19 | fn.apply(console, arguments);
20 |
21 | if (name == 'clear' || name == 'memory') {
22 | return;
23 | }
24 |
25 | var params = Array.prototype.slice.call(arguments);
26 |
27 | try {
28 | JSON.stringify(params);
29 | } catch (exc) {
30 | return;
31 | }
32 |
33 | socket.send({
34 | console: true,
35 | method: name,
36 | params: params
37 | });
38 | };
39 | }
40 |
--------------------------------------------------------------------------------
/app/frame.css:
--------------------------------------------------------------------------------
1 | html, body, .prova {
2 | width: 100%;
3 | height: 100%;
4 | padding: 0;
5 | margin: 0;
6 | background: #fff;
7 | }
8 |
9 | .prova {
10 | display:-ms-flexbox;
11 | -ms-flex-pack:center;
12 | -ms-flex-align:center;
13 |
14 | display:-moz-box;
15 | -moz-box-pack:center;
16 | -moz-box-align:center;
17 |
18 | display:-webkit-box;
19 | -webkit-box-pack:center;
20 | -webkit-box-align:center;
21 |
22 | display:box;
23 | box-pack:center;
24 | box-align:center;
25 |
26 | font: normal 12px "pt mono";
27 | color: #333;
28 | }
29 |
30 | @font-face {
31 | font-family: 'PT Mono';
32 | font-style: normal;
33 | font-weight: 400;
34 | src: local('PT Mono'), local('PTMono-Regular'), url(http://themes.googleusercontent.com/static/fonts/ptmono/v2/RTA0Dhj_HESY0h-ax44VkwLUuEpTyoUstqEm5AMlJo4.woff) format('woff');
35 | }
36 |
--------------------------------------------------------------------------------
/app/frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |