@@ -35,25 +35,29 @@ describe('CRUD API', function() {
35
35
//
36
36
// Cursor
37
37
// --------------------------------------------------
38
- var cursor = db . collection ( 't' ) . find ( { } ) ;
39
- // Possible methods on the the cursor instance
40
- cursor
41
- . filter ( { a : 1 } )
42
- . addCursorFlag ( 'noCursorTimeout' , true )
43
- . addQueryModifier ( '$comment' , 'some comment' )
44
- . batchSize ( 2 )
45
- . comment ( 'some comment 2' )
46
- . limit ( 2 )
47
- . maxTimeMs ( 50 )
48
- . project ( { a : 1 } )
49
- . skip ( 0 )
50
- . sort ( { a : 1 } ) ;
38
+ const makeCursor = ( ) => {
39
+ // Possible methods on the the cursor instance
40
+ return db
41
+ . collection ( 't' )
42
+ . find ( { } )
43
+ . filter ( { a : 1 } )
44
+ . addCursorFlag ( 'noCursorTimeout' , true )
45
+ . addQueryModifier ( '$comment' , 'some comment' )
46
+ . batchSize ( 2 )
47
+ . comment ( 'some comment 2' )
48
+ . limit ( 2 )
49
+ . maxTimeMs ( 50 )
50
+ . project ( { a : 1 } )
51
+ . skip ( 0 )
52
+ . sort ( { a : 1 } ) ;
53
+ } ;
51
54
52
55
//
53
56
// Exercise count method
54
57
// -------------------------------------------------
55
58
var countMethod = function ( ) {
56
59
// Execute the different methods supported by the cursor
60
+ const cursor = makeCursor ( ) ;
57
61
cursor . count ( function ( err , count ) {
58
62
test . equal ( null , err ) ;
59
63
test . equal ( 2 , count ) ;
@@ -67,6 +71,7 @@ describe('CRUD API', function() {
67
71
var eachMethod = function ( ) {
68
72
var count = 0 ;
69
73
74
+ const cursor = makeCursor ( ) ;
70
75
cursor . each ( function ( err , doc ) {
71
76
test . equal ( null , err ) ;
72
77
if ( doc ) count = count + 1 ;
@@ -81,6 +86,7 @@ describe('CRUD API', function() {
81
86
// Exercise toArray
82
87
// -------------------------------------------------
83
88
var toArrayMethod = function ( ) {
89
+ const cursor = makeCursor ( ) ;
84
90
cursor . toArray ( function ( err , docs ) {
85
91
test . equal ( null , err ) ;
86
92
test . equal ( 2 , docs . length ) ;
@@ -92,16 +98,16 @@ describe('CRUD API', function() {
92
98
// Exercise next method
93
99
// -------------------------------------------------
94
100
var nextMethod = function ( ) {
95
- var clonedCursor = cursor . clone ( ) ;
96
- clonedCursor . next ( function ( err , doc ) {
101
+ const cursor = makeCursor ( ) ;
102
+ cursor . next ( function ( err , doc ) {
97
103
test . equal ( null , err ) ;
98
104
test . ok ( doc != null ) ;
99
105
100
- clonedCursor . next ( function ( err , doc ) {
106
+ cursor . next ( function ( err , doc ) {
101
107
test . equal ( null , err ) ;
102
108
test . ok ( doc != null ) ;
103
109
104
- clonedCursor . next ( function ( err , doc ) {
110
+ cursor . next ( function ( err , doc ) {
105
111
test . equal ( null , err ) ;
106
112
test . equal ( null , doc ) ;
107
113
streamMethod ( ) ;
@@ -115,12 +121,12 @@ describe('CRUD API', function() {
115
121
// -------------------------------------------------
116
122
var streamMethod = function ( ) {
117
123
var count = 0 ;
118
- var clonedCursor = cursor . clone ( ) ;
119
- clonedCursor . on ( 'data' , function ( ) {
124
+ const cursor = makeCursor ( ) ;
125
+ cursor . on ( 'data' , function ( ) {
120
126
count = count + 1 ;
121
127
} ) ;
122
128
123
- clonedCursor . once ( 'end' , function ( ) {
129
+ cursor . once ( 'end' , function ( ) {
124
130
test . equal ( 2 , count ) ;
125
131
explainMethod ( ) ;
126
132
} ) ;
@@ -130,8 +136,8 @@ describe('CRUD API', function() {
130
136
// Explain method
131
137
// -------------------------------------------------
132
138
var explainMethod = function ( ) {
133
- var clonedCursor = cursor . clone ( ) ;
134
- clonedCursor . explain ( function ( err , result ) {
139
+ const cursor = makeCursor ( ) ;
140
+ cursor . explain ( function ( err , result ) {
135
141
test . equal ( null , err ) ;
136
142
test . ok ( result != null ) ;
137
143
0 commit comments