1 | Whiskey
|
2 | =======
|
3 |
|
4 | Whiskey is a simple test runner for NodeJS applications.
|
5 |
|
6 | Features
|
7 | ========
|
8 |
|
9 | * Each test file runs isolated in a separate process
|
10 | * Support for running multiple tests in parallel (`--concurrency` option)
|
11 | * Support for a test initialization function which is run before running the tests in a test file
|
12 | * Support for a test file timeout
|
13 | * setUp / tearDown function support
|
14 | * Nicely formatted reports (colors!)
|
15 | * Support for code coverage (cli reporter, html reporter)
|
16 | * Support for reporting variables which have leaked into a global scope
|
17 |
|
18 | Dependencies
|
19 | ===========
|
20 |
|
21 | * optparse-js
|
22 | * async
|
23 | * sprintf
|
24 | * rimraf
|
25 | * magic-templates
|
26 | * terminal
|
27 | * [node-jscoverage](https://github.com/Kami/node-jscoverage) (only required if `--coverage` option is used)
|
28 |
|
29 | Changes
|
30 | =======
|
31 |
|
32 | For changes please see [CHANGES.md](/cloudkick/whiskey/blob/master/CHANGES.md) file.
|
33 |
|
34 | Installation
|
35 | ============
|
36 |
|
37 | Install it using npm:
|
38 | ```
|
39 | npm install whiskey
|
40 | ```
|
41 |
|
42 | Usage
|
43 | =====
|
44 |
|
45 | whiskey [options] --tests "<test files>"
|
46 |
|
47 | #### Available options
|
48 |
|
49 | * **-t, --tests** - Whitespace separated list of test files to run
|
50 | * **-ti, --test-init-file** - A path to the initialization file which must export
|
51 | `init` function and it is called in a child process *before running the tests in
|
52 | each test file
|
53 | * **-c, --chdir** - An optional path to which the child process will chdir to before
|
54 | running the tests
|
55 | * **--timeout [NUMBER]** - How long to wait for tests to complete before timing
|
56 | out
|
57 | * **--failfast** - Stop running the tests on a first failure or a timeout
|
58 | * **--no-styles** - Don't use styles and colors
|
59 | * **--concurrency [NUMBER]** - Maximum number of tests which will run in parallel (defaults to 1)
|
60 | * **--quiet** - Don't print stdout and stderr
|
61 | * **--real-time** - Print stdout and stderr as soon as it comes in
|
62 | * **--test-reporter [cli,tap]** - Which test reporter to use (defaults to cli)
|
63 | * **--coverage** - Use this option to enable the test coverage
|
64 | * **--coverage-reporter [cli,html]** - Which coverage reporter to use (defaults to cli)
|
65 | * **--coverage-dir** - Directory where the coverage HTML report is saved
|
66 | * **--scope-leaks** - Record which variables were leaked into a global scope
|
67 | * **--scope-leaks-reporter [cli]** - Which scope leak reporter to use (defauls
|
68 | to cli)
|
69 | * **--debug** - Attach a Node debugger to the test process
|
70 |
|
71 | Note: When specifying multiple test a list with the test paths must be quoted,
|
72 | for example: `whiskey --tests "tests/a.js tests/b.js tests/c.js"`
|
73 |
|
74 | Test File Examples
|
75 | ==================
|
76 |
|
77 | A simple example (success):
|
78 |
|
79 | ``` javascript
|
80 | var called = 0;
|
81 |
|
82 | exports['test_async_one_equals_one'] = function(test, assert) {
|
83 | setTimeout(function() {
|
84 | assert.equal(1, 1);
|
85 | called++;
|
86 | test.finish();
|
87 | }, 1000);
|
88 | }
|
89 |
|
90 | exports['tearDown'] = function(test, assert) {
|
91 | assert.equal(called, 1);
|
92 | test.finish();
|
93 | }
|
94 | ```
|
95 |
|
96 | A simple example (failure):
|
97 |
|
98 | ``` javascript
|
99 | exports['test_two_equals_one'] = function(test, assert) {
|
100 | assert.equal(2, 1);
|
101 | test.finish();
|
102 | }
|
103 | ```
|
104 |
|
105 | For more examples please check the `example/` folder.
|
106 |
|
107 | Debugging
|
108 | =========
|
109 |
|
110 | If you want to debug your test, you can use the `--debug` option. This will
|
111 | cause Whiskey to start the test process with the V8 debugger attached to it
|
112 | and put you into the Node debugger prompt.
|
113 |
|
114 | Whiskey will also by default set a breakpoint at the beginning of your test
|
115 | file.
|
116 |
|
117 | Note: This option can only be used with a single test file.
|
118 |
|
119 | Troubleshooting
|
120 | ===============
|
121 |
|
122 | ### I use `long-stack-straces` module in my own code and all of the tests get reported as succeeded
|
123 |
|
124 | Long stack traces modules intercepts the default Error object and throws a custom
|
125 | one. The problem with this is that Whiskey internally relies on attaching the
|
126 | test name to the `Error` object so it can figure out to which test the exception
|
127 | belongs. long-stack-traces throws a custom Error object and as a consequence test
|
128 | name attribute gets lost so Whiskey thinks your test didn't throw any exceptions.
|
129 |
|
130 | The solution for this problem is to disable `long-stack-trace` module when running
|
131 | the tests. This shouldn't be a big deal, because Whiskey internally already uses
|
132 | `long-stack-traces` module which means that you will still get long stack traces
|
133 | in the exceptions which were thrown in your tests.
|
134 |
|
135 | ### My test gets reported as "timeout" instead of "failure"
|
136 |
|
137 | If your test gets reported as "timeout" instead of "failure" your test code most
|
138 | likely looks similar to the one bellow:
|
139 |
|
140 | ```javascript
|
141 | exports["test failure"] = function(test, assert){
|
142 | setTimeout(function() {
|
143 | throw "blaaaaah";
|
144 | test.finish();
|
145 | },200);
|
146 | };
|
147 | ```
|
148 |
|
149 | The problem with this is that if you run tests in parallel (`--concurrency` > 1)
|
150 | and you don't use a custom assert object which gets passed to each test function,
|
151 | Whiskey can't figure out to which test the exception belongs. As a consequence,
|
152 | the test is reported as "timed out" and the exception is reported as "uncaught".
|
153 |
|
154 | The solution for this problem is to run the tests in sequential mode (drop the
|
155 | --concurrency option).
|