Debian Codegraph @

README.md

raw
1 # TAD - JavaScript test suite
2
3 Goal of this framework is to allow writing tests with minimal hassle.
4 TAD will locate your test file, and provide tested module for your test functions.
5
6 Example console output:
7
8 <img src="http://medyk.org/tad.png" border="0" width="718" height="370" />
9
10 - [Installation](#installation)
11 - [Usage](#usage)
12 _ [File managment](#usage-file-management)
13 _ [Test files](#usage-test-files)
14 _ [Test functions](#usage-test-functions)
15 _ [Assertions](#usage-assertions) \* [Running tests](#usage-running-tests)
16 - [TODO](#todo)
17
18 <a name="installation" />
19
20 ## Installation
21
22 $ npm install tad
23
24 <a name="usage" />
25
26 ## Usage
27
28 <a name="usage-file-management" />
29
30 ### File management
31
32 Keep your tests in _test_ folder. For each file in in main folder have corresponding test file in
33 _test_ folder.
34
35 <a name="usage-test-files" />
36
37 ### Test files
38
39 Tests should be written as set of functions, it can be just one function:
40
41 ```js
42 module.exports = function (t, a, d) {
43 // tests
44 };
45 ```
46
47 or many thematically grouped functions:
48
49 ```js
50 exports["Test this"] = function (t, a, d) {
51 // tests
52 };
53 exports["Test that"] = function (t, a, d) {
54 // tests
55 };
56 ```
57
58 <a name="usage-test-functions" />
59
60 ### Test functions
61
62 Arguments passed to test functions are:
63
64 - **t** - Tested module
65 - **a** - Assert object
66 - **d** - _Done_ function, it's for tests that need to be run asynchronously.
67 You may pass additional block of tests to this
68 function and they'll be run right after. _d_ argument makes no sense for
69 synchrounous tests, declare such tests without it.
70
71 All arguments are optional, and by the way function is declared suite detect
72 which arguments should be passed to test function. Examples:
73
74 - Asynchronous test:
75
76 ```js
77 exports["Some tests"] = funtcion (t, a, d) {
78 // tests
79 setTimeout(function () {
80 // tests
81 d();
82 }, 100);
83 };
84 ```
85
86 - Synchronous test:
87
88 ```js
89 exports["Some tests"] = function (t, a) {
90 // tests
91 };
92 ```
93
94 Tests can be nested, and declared various ways (synchronous/asynchronous)
95
96 ```js
97 module.exports["Test all"] = function (t, a) {
98 // Preparation code
99
100 // ... tests ...
101
102 return {
103 "Test this": function () {
104 // We already have module and assert object
105 // ... tests ...
106 },
107 "Test that async way": function (d) {
108 // This one is asynchronous
109 // ... tests ....
110
111 seTimeout(function () {
112 // ... tests ...
113 d({
114 "Some extra tests": function () {
115 // ... tests ...
116 }
117 });
118 }, 100);
119 }
120 };
121 };
122 ```
123
124 <a name="usage-assertions" />
125
126 ### Assertions
127
128 TAD uses assert object from [UncommonJS tests runner](https://github.com/Gozala/test-commonjs/),
129 It's API is nearly same as of _assert_ that can be found in Node. Full spec is available at
130 https://github.com/kriskowal/uncommonjs/blob/master/tests/specification.md .
131
132 TAD adds some extra sugar to UncommonJS Assert object:
133
134 - `a === a.strictEqual`, so you can write your assertions as:
135
136 ```js
137 a(shouldBeTrue, true, "It's true");
138 // it has same effect as:
139 a.strictEqual(shouldBeTrue, true, "It's true");
140 ```
141
142 - `a.not` is an alias for `a.notStrictEqual`
143 - `a.deep` is an alias for `a.deepEqual`
144 - `a.notDeep` is an alias for `a.notDeepEqual`
145 - `assert.never` with that you can check function paths that should never be called.
146
147 <a name="usage-running-tests" />
148
149 ### Running tests
150
151 Test your file with provided binary:
152
153 $ bin/tad lib/test-file
154
155 or test all files in path:
156
157 $ bin/tad lib
158
159 <a name="todo" />
160
161 ## TODO
162
163 - Full custom context support
164 - Code coverage
165 - TAP support
166 - jslint, jshint as side validation option
167 - Port tests to browsers