@@ -123,11 +123,14 @@ describe('CRUD API explain option', function () {
123123 describe ( 'explain helpers w/ maxTimeMS' , function ( ) {
124124 let client : MongoClient ;
125125 const commands : CommandStartedEvent [ ] = [ ] ;
126+ let collection : Collection ;
126127
127128 beforeEach ( async function ( ) {
128129 client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
129130 await client . connect ( ) ;
130131
132+ collection = await client . db ( 'explain-test' ) . createCollection ( 'bar' ) ;
133+
131134 client . on ( 'commandStarted' , filterForCommands ( 'explain' , commands ) ) ;
132135 commands . length = 0 ;
133136 } ) ;
@@ -139,7 +142,6 @@ describe('CRUD API explain option', function () {
139142 describe ( 'cursor explain commands' , function ( ) {
140143 describe ( 'when maxTimeMS is specified via a cursor explain method, it sets the property on the command' , function ( ) {
141144 test ( 'find()' , async function ( ) {
142- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
143145 await collection
144146 . find ( { name : 'john doe' } )
145147 . explain ( { maxTimeMS : 2000 , verbosity : 'queryPlanner' } ) ;
@@ -149,8 +151,6 @@ describe('CRUD API explain option', function () {
149151 } ) ;
150152
151153 test ( 'aggregate()' , async function ( ) {
152- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
153-
154154 await collection
155155 . aggregate ( [ { $match : { name : 'john doe' } } ] )
156156 . explain ( { maxTimeMS : 2000 , verbosity : 'queryPlanner' } ) ;
@@ -161,19 +161,13 @@ describe('CRUD API explain option', function () {
161161 } ) ;
162162
163163 it ( 'when maxTimeMS is not specified, it is not attached to the explain command' , async function ( ) {
164- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
165- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
166-
167164 await collection . find ( { name : 'john doe' } ) . explain ( { verbosity : 'queryPlanner' } ) ;
168165
169166 const [ { command } ] = commands ;
170167 expect ( command ) . not . to . have . property ( 'maxTimeMS' ) ;
171168 } ) ;
172169
173170 it ( 'when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence' , async function ( ) {
174- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
175- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
176-
177171 await collection
178172 . find (
179173 { } ,
@@ -194,15 +188,12 @@ describe('CRUD API explain option', function () {
194188
195189 describe ( 'regular commands w/ explain' , function ( ) {
196190 it ( 'when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence' , async function ( ) {
197- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
198- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
199-
200191 await collection . deleteMany (
201192 { } ,
202193 {
203194 maxTimeMS : 1000 ,
204195 explain : {
205- verbosity : true ,
196+ verbosity : 'queryPlanner' ,
206197 maxTimeMS : 2000
207198 }
208199 }
@@ -214,7 +205,6 @@ describe('CRUD API explain option', function () {
214205
215206 describe ( 'when maxTimeMS is specified as an explain option' , function ( ) {
216207 it ( 'attaches maxTimeMS to the explain command' , async function ( ) {
217- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
218208 await collection . deleteMany (
219209 { } ,
220210 { explain : { maxTimeMS : 2000 , verbosity : 'queryPlanner' } }
@@ -226,8 +216,6 @@ describe('CRUD API explain option', function () {
226216 } ) ;
227217
228218 it ( 'when maxTimeMS is not specified, it is not attached to the explain command' , async function ( ) {
229- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
230-
231219 await collection . deleteMany ( { } , { explain : { verbosity : 'queryPlanner' } } ) ;
232220
233221 const [ { command } ] = commands ;
0 commit comments