Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 118 lines (86 sloc) 3.53 kb
0d8c3e6 @siddMahen Added errors to teardown callback
authored
1 # stest - A Sane Async Testing Framework
2
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
3 `stest` is a fun, fast and simple testing framework
4 particularly suited towards asynchronous code. It lets
5 you easily structure tests for code with both
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
6 synchronous and asynchronous methods without too much
7 complexity.
e05511b @siddMahen Initial commit
authored
8
9 # Installation:
10
11 Using `npm`:
12
7c36a9c @siddMahen Improved README
authored
13 npm install -g stest
e05511b @siddMahen Initial commit
authored
14
15 # Usage:
16
17 A very simple test:
18
19 var stest = require("stest"),
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
20 assert = require("assert"),
21 mylib = stest.cover("../lib/mylib");
e05511b @siddMahen Initial commit
authored
22
23 var opts = { timeout: 0 };
24
25 stest.addCase("stest", opts,{
26 setup: function(promise){
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
27
e05511b @siddMahen Initial commit
authored
28 promise.emit("event", 42);
29 promise.emit("other_event", "Hello!");
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
30
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
31 mylib.async_func(function(err, obj){
32 promise.emit("async", err, obj);
33 });
e05511b @siddMahen Initial commit
authored
34 },
35 event: function(fortytwo){
36 assert.equal(42, fortytwo);
37 },
38 other_event: function(hello){
39 assert.equal("Hello!", hello);
40 },
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
41 async: function(err, obj){
42 assert.ifError(err);
43 assert.ok(obj);
44 },
0d8c3e6 @siddMahen Added errors to teardown callback
authored
45 teardown: function(errors){
46 if(errors.length > 0) assert.ok(0);
e05511b @siddMahen Initial commit
authored
47 }
48 }).run();
49
50 `stest` hands you a `promise` object which is an instance
51 of `EventEmitter`. Use this to emit events and values
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
52 when your async/sync calls complete, and check them in the
e05511b @siddMahen Initial commit
authored
53 corresponding functions associated with the name of the
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
54 events you've emitted.
e05511b @siddMahen Initial commit
authored
55
56 The `setup` and `teardown` functions are given to you
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
57 to setup your test case, and to perform a teardown.
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
58 `setup` is required, `teardown` is optional.
e05511b @siddMahen Initial commit
authored
59
0d8c3e6 @siddMahen Added errors to teardown callback
authored
60 The `opts` argument allows you to specify a `timeout`
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
61 in miliseconds. If all async calls are not called
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
62 before that time, `stest` will give you a heads up.
63
64 `stest` also supports code coverage using the `cover`
65 method, which shows unseen LOC and gives you a brief
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
66 overview of how much of the file you've tested. Do note
67 that `cover` may trip up if you have really whacky
68 syntax (like assignments inside of conditional statements
69 and such).
e05511b @siddMahen Initial commit
authored
70
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
71 See the source code and inline documentation for more details.
e05511b @siddMahen Initial commit
authored
72
0d8c3e6 @siddMahen Added errors to teardown callback
authored
73 # Running Tests:
e05511b @siddMahen Initial commit
authored
74
0d8c3e6 @siddMahen Added errors to teardown callback
authored
75 Tests can be run en masse using `srunner`:
e05511b @siddMahen Initial commit
authored
76
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
77 Usage: srunner [-s] -r [regexp]
e05511b @siddMahen Initial commit
authored
78
9ca181b @siddMahen Fixed a fatal bug in coverage
authored
79 Options:
0462253 @siddMahen Code coverage done right
authored
80 -s, --silent supress output [boolean]
81 -r, --regexp regexp of files to test [string] [required]
9ca181b @siddMahen Fixed a fatal bug in coverage
authored
82
83 Which looks like this in the command line:
84
0462253 @siddMahen Code coverage done right
authored
85 srunner -r test/test-.*\.js
9ca181b @siddMahen Fixed a fatal bug in coverage
authored
86
ec05a3f @siddMahen Vastly Improved Code Coverage
authored
87 If you prefer not to use `srunner`, you can
0d8c3e6 @siddMahen Added errors to teardown callback
authored
88 still run tests like this:
e05511b @siddMahen Initial commit
authored
89
0d8c3e6 @siddMahen Added errors to teardown callback
authored
90 node test.js
91
4e9017b @siddMahen Improved README, fixed a few doc errors
authored
92 `srunner` isn't dependant on `stest` per se, so it also
93 works really well as a general purpose test runner.
94
0d8c3e6 @siddMahen Added errors to teardown callback
authored
95 # License:
e05511b @siddMahen Initial commit
authored
96
97 (The MIT License)
98
99 Copyright (C) 2011 by Siddharth Mahendraker <siddharth_mahen@me.com>
100
101 Permission is hereby granted, free of charge, to any person obtaining a copy
102 of this software and associated documentation files (the "Software"), to deal
103 in the Software without restriction, including without limitation the rights
104 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
105 copies of the Software, and to permit persons to whom the Software is
106 furnished to do so, subject to the following conditions:
107
108 The above copyright notice and this permission notice shall be included in
109 all copies or substantial portions of the Software.
110
111 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
112 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
113 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
114 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
115 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
116 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
117 THE SOFTWARE.
Something went wrong with that request. Please try again.