1 | # gulp-mocha-tdd
|
2 | easy test driven development with gulp and mocha
|
3 |
|
4 | * it('should use mocha for unit tests')
|
5 | * it('should auto-generate the boilerplate module test describe statement')
|
6 | * it('should be able to work with your test naming conventions')
|
7 | * it('should make test driven development easy and convienant')
|
8 | * it('should support mocha options like breakpoints and grep')
|
9 | * it('should use conventions to associate modules with unit tests')
|
10 | * it('should support additional gulp stream handlers (like JSX)')
|
11 | * it('should re-run module tests when either the module or unit test code changes')
|
12 |
|
13 |
|
14 | Usage
|
15 | -----------
|
16 |
|
17 | To execute all tests
|
18 | ```
|
19 | > gulp test
|
20 | ```
|
21 | And watch for module or unit test changes
|
22 | ```
|
23 | > gulp test -w
|
24 | ```
|
25 | Stop on any debugger statements
|
26 | ```
|
27 | > gulp test -d
|
28 | > node-inspector {in another window}
|
29 | browse to http://127.0.0.1:8080/debug?port=5858
|
30 | ```
|
31 | Any other mocha params can be used as well: see ```mocha -h```
|
32 |
|
33 |
|
34 | Test Modules
|
35 | ---------------
|
36 | Test modules do not need the top level ```describe``` function (it will be created automatically based on file structure). You can either just have your tests directly in the file (no usage of ```module.exports```) or you can export a function callback that contains your tests. This callback accepts 2 parameters ```(targetModule, targetModuleDirectoryPath)```. For example:
|
37 |
|
38 | ```
|
39 | var targetModule = require('path/to/target/module');
|
40 | it('should ...', function() {
|
41 | expect(targetModule...).to...
|
42 | });
|
43 | ```
|
44 | or
|
45 | ```
|
46 | module.exports = function(targetModule, targetBase) {
|
47 | it('should ...', function() {
|
48 | expect(targetModule...).to...
|
49 | });
|
50 | it('should ...', function() {
|
51 | expect(require(targetBase + '/targetModuleName')...).to...
|
52 | });
|
53 | }
|
54 | ```
|
55 |
|
56 |
|
57 | All modules must be within a root directory ("js" by default) and tests can either be in a separate root directory ("tests" by default) or tests can be in a directory relative ("_tests" by default) to the module. Tests can use any naming pattern ("{module name}-test.js" by default).
|
58 |
|
59 | For example
|
60 | ```
|
61 | |-- js
|
62 | |-- _tests
|
63 | |-- foo-test.js
|
64 | |-- foo.js
|
65 | ```
|
66 | or
|
67 | ```
|
68 | |-- lib
|
69 | |-- foo.js
|
70 | |-- tests
|
71 | |-- foo.spec.js
|
72 | ```
|
73 |
|
74 | See Options below for available configuration
|
75 |
|
76 | [see examples for details](https://github.com/jhudson8/gulp-mocha-tdd/tree/master/examples)
|
77 |
|
78 | Any files within the test directories prefixed with ```_``` will be ignored for testing allowing for utility modules.
|
79 |
|
80 |
|
81 | Additional Transformations
|
82 | ------------
|
83 | The ```pipe``` option (array of gulp stream handlers) can be used to perform additional transformations. The
|
84 | following gulpfile can be used to support React JSX
|
85 | ```
|
86 | var gulp = require('gulp');
|
87 | var react = require('gulp-react');
|
88 | var gulpMochaTDD = require('gulp-mocha-tdd');
|
89 |
|
90 | gulpMochaTDD(gulp, {
|
91 | pipe: [react({ harmony: true })]
|
92 | });
|
93 | ```
|
94 |
|
95 | Options
|
96 | ------------
|
97 | * ***taskName***: the gulp task name ("test" if undefined)
|
98 | * ***pipe***: array of gulp stream handlers (See above for example)
|
99 | * ***init***: init function executed once before the tests
|
100 | * ***scriptsDirName***: top level directory ("js" if undefined)
|
101 | * ***testFilePattern***: unit test file name (without ext) pattern (use "{name}" to reference the module name; "{name}-test" if undefined)
|
102 | * ***testsDirName***: name of directory which contains the unit test files ("_tests" if undefined)
|
103 | * ***rootTestsDir***: true if using a root tests directory and undefined/false if tests are in a directory relative to the module ([see examples](https://github.com/jhudson8/gulp-mocha-tdd/tree/master/examples))
|
104 |
|
105 |
|
106 | Installation
|
107 | ------------
|
108 | Install dependencies
|
109 | ```
|
110 | npm install --save-dev mocha
|
111 | npm install --save-dev gulp
|
112 | npm install --save-dev gulp-mocha-tdd
|
113 | ```
|
114 |
|
115 | Inject the ```test``` task in ```gulpfile.js```
|
116 | ```
|
117 | var gulp = require('gulp');
|
118 | var gulpMochaTDD = require('gulp-mocha-tdd', {
|
119 | // add options here
|
120 | });
|
121 |
|
122 | gulpMochaTDD(gulp);
|
123 | ```
|
124 |
|
125 | Add ```.test``` to your ```.gitignore``` file
|
126 |
|
\ | No newline at end of file |