@@ -118,38 +118,44 @@ async function runUnifiedTest(
118118 // The test runner MUST use the internal MongoClient for these operations.
119119 if ( unifiedSuite . initialData ) {
120120 trace ( 'initialData' ) ;
121- for ( const collData of unifiedSuite . initialData ) {
122- const db = utilClient . db ( collData . databaseName ) ;
123- const collection = db . collection ( collData . collectionName , {
121+ for ( const { databaseName , collectionName } of unifiedSuite . initialData ) {
122+ const db = utilClient . db ( databaseName ) ;
123+ const collection = db . collection ( collectionName , {
124124 writeConcern : { w : 'majority' }
125125 } ) ;
126126
127127 trace ( 'listCollections' ) ;
128- const collectionList = await db
129- . listCollections ( { name : collData . collectionName } )
130- . toArray ( ) ;
128+ const collectionList = await db . listCollections ( { name : collectionName } ) . toArray ( ) ;
131129 if ( collectionList . length !== 0 ) {
132130 trace ( 'drop' ) ;
133131 expect ( await collection . drop ( ) ) . to . be . true ;
134132 }
135133 }
136134
137- for ( const collData of unifiedSuite . initialData ) {
138- const db = utilClient . db ( collData . databaseName ) ;
139- const collection = db . collection ( collData . collectionName , {
135+ for ( const {
136+ databaseName,
137+ collectionName,
138+ createOptions,
139+ documents = [ ]
140+ } of unifiedSuite . initialData ) {
141+ const db = utilClient . db ( databaseName ) ;
142+ const collection = db . collection ( collectionName , {
140143 writeConcern : { w : 'majority' }
141144 } ) ;
142145
143- if ( ! collData . documents ? .length ) {
146+ if ( createOptions || ! documents . length ) {
144147 trace ( 'createCollection' ) ;
145- await db . createCollection ( collData . collectionName , {
148+ const options = createOptions ?? { } ;
149+ await db . createCollection ( collectionName , {
150+ ...options ,
146151 writeConcern : { w : 'majority' }
147152 } ) ;
148- continue ;
149153 }
150154
151- trace ( 'insertMany' ) ;
152- await collection . insertMany ( collData . documents ) ;
155+ if ( documents . length > 0 ) {
156+ trace ( 'insertMany' ) ;
157+ await collection . insertMany ( documents ) ;
158+ }
153159 }
154160 }
155161
0 commit comments