File tree Expand file tree Collapse file tree 3 files changed +51
-5
lines changed Expand file tree Collapse file tree 3 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -891,6 +891,15 @@ it('does something cool', function() {
891
891
});
892
892
```
893
893
894
+ ** IMPORTANT:** By default jobs aren't processed when created during test mode. You can enable job processing by passing true to testMode.enter
895
+
896
+ ``` js
897
+ before (function () {
898
+ queue .testMode .enter (true );
899
+ });
900
+ ```
901
+
902
+
894
903
## Screencasts
895
904
896
905
- [ Introduction] ( http://www.screenr.com/oyNs ) to Kue
Original file line number Diff line number Diff line change @@ -3,16 +3,26 @@ var Job = require('./job'),
3
3
4
4
var originalJobSave = Job . prototype . save ,
5
5
originalJobUpdate = Job . prototype . update ,
6
+ processQueue ,
6
7
jobs ;
7
8
8
9
function testJobSave ( fn ) {
9
- this . id = _ . uniqueId ( ) ;
10
- jobs . push ( this ) ;
11
- if ( _ . isFunction ( fn ) ) fn ( ) ;
10
+ if ( processQueue ) {
11
+ jobs . push ( this ) ;
12
+ originalJobSave . call ( this , fn ) ;
13
+ } else {
14
+ this . id = _ . uniqueId ( ) ;
15
+ jobs . push ( this ) ;
16
+ if ( _ . isFunction ( fn ) ) fn ( ) ;
17
+ }
12
18
} ;
13
19
14
20
function testJobUpdate ( fn ) {
15
- if ( _ . isFunction ( fn ) ) fn ( ) ;
21
+ if ( processQueue ) {
22
+ originalJobUpdate . call ( this , fn ) ;
23
+ } else {
24
+ if ( _ . isFunction ( fn ) ) fn ( ) ;
25
+ }
16
26
} ;
17
27
18
28
/**
@@ -21,13 +31,15 @@ function testJobUpdate( fn ) {
21
31
*/
22
32
23
33
module . exports . jobs = jobs = [ ] ;
34
+ module . exports . processQueue = processQueue = false ;
24
35
25
36
/**
26
37
* Enable test mode.
27
38
* @api public
28
39
*/
29
40
30
- module . exports . enter = function ( ) {
41
+ module . exports . enter = function ( process ) {
42
+ processQueue = process || false ;
31
43
Job . prototype . save = testJobSave ;
32
44
Job . prototype . update = testJobUpdate ;
33
45
} ;
Original file line number Diff line number Diff line change @@ -23,6 +23,31 @@ describe('Test Mode', function() {
23
23
expect ( job . data ) . to . eql ( { foo : 'bar' } ) ;
24
24
} ) ;
25
25
26
+ it ( 'adds jobs to an array in memory and processes them when processQueue is true' , function ( done ) {
27
+ queue . testMode . exit ( ) ;
28
+ queue . testMode . enter ( true ) ;
29
+
30
+ queue . createJob ( 'test-testMode-process' , { foo : 'bar' } ) . save ( ) ;
31
+
32
+ var jobs = queue . testMode . jobs ;
33
+ expect ( jobs . length ) . to . equal ( 1 ) ;
34
+
35
+ var job = _ . last ( jobs ) ;
36
+ expect ( job . type ) . to . equal ( 'test-testMode-process' ) ;
37
+ expect ( job . data ) . to . eql ( { foo : 'bar' } ) ;
38
+
39
+ job . on ( 'complete' , function ( ) {
40
+ queue . testMode . exit ( ) ;
41
+ queue . testMode . enter ( ) ;
42
+ done ( ) ;
43
+ } ) ;
44
+
45
+ queue . process ( 'test-testMode-process' , function ( job , jdone ) {
46
+ job . data . should . be . eql ( { foo : 'bar' } ) ;
47
+
48
+ jdone ( ) ;
49
+ } ) ;
50
+ } ) ;
26
51
27
52
describe ( '#clear' , function ( ) {
28
53
it ( 'resets the list of jobs' , function ( ) {
You can’t perform that action at this time.
0 commit comments