@@ -3,37 +3,28 @@ import { finished } from 'node:stream/promises';
33import { expect } from 'chai' ;
44import * as sinon from 'sinon' ;
55
6- import { loadContextifiedMongoDBModule } from '../../tools/runner/vm_context_helper' ;
7- import { type FailCommandFailPoint } from '../../tools/utils' ;
8- import { assert as test } from '../shared' ;
9-
10- // Load MongoDB module in VM context
11- const mongodb = loadContextifiedMongoDBModule ( ) ;
12-
13- // Extract the exports we need from the contextified module
14- const {
6+ import {
157 Collection ,
168 CommandFailedEvent ,
9+ type CommandStartedEvent ,
1710 CommandSucceededEvent ,
11+ type Db ,
1812 MongoBulkWriteError ,
19- MongoClient,
13+ type MongoClient ,
2014 MongoServerError ,
2115 ObjectId ,
22- ReturnDocument
23- } = mongodb ;
24-
25- type MongoClient = typeof mongodb . MongoClient . prototype ;
26- type Db = typeof mongodb . Db . prototype ;
27- type CommandStartedEvent = typeof mongodb . CommandStartedEvent . prototype ;
16+ ReturnDocument ,
17+ runNodelessTests
18+ } from '../../mongodb_runtime-testing' ;
19+ import { ensureTypeByName , type FailCommandFailPoint } from '../../tools/utils' ;
20+ import { assert as test } from '../shared' ;
2821
2922const DB_NAME = 'crud_api_tests' ;
3023
3124describe . only ( 'CRUD API' , function ( ) {
3225 let client : MongoClient ;
3326
3427 beforeEach ( async function ( ) {
35- this . configuration . mongodb = mongodb ;
36-
3728 client = this . configuration . newClient ( ) ;
3829
3930 client . s . options . dbName = DB_NAME ; // setup the default db
@@ -113,9 +104,13 @@ describe.only('CRUD API', function () {
113104 const spy = sinon . spy ( Collection . prototype , 'find' ) ;
114105 const result = await collection . findOne ( { } ) ;
115106 expect ( result ) . to . deep . equal ( { _id : 1 } ) ;
116- expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandSucceededEvent ) ;
117- expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
118- expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
107+ if ( runNodelessTests ) {
108+ expect ( ensureTypeByName ( events . at ( 0 ) , 'CommandSucceededEvent' ) ) . to . be . true ;
109+ } else {
110+ expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandSucceededEvent ) ;
111+ expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
112+ expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
113+ }
119114 } ) ;
120115 } ) ;
121116
@@ -145,10 +140,14 @@ describe.only('CRUD API', function () {
145140 it ( 'the cursor for findOne is closed' , async function ( ) {
146141 const spy = sinon . spy ( Collection . prototype , 'find' ) ;
147142 const error = await collection . findOne ( { } ) . catch ( error => error ) ;
148- expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
149- expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandFailedEvent ) ;
150- expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
151- expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
143+ if ( runNodelessTests ) {
144+ expect ( ensureTypeByName ( error , 'MongoServerError' ) ) . to . be . true ;
145+ } else {
146+ expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
147+ expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandFailedEvent ) ;
148+ expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
149+ expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
150+ }
152151 } ) ;
153152 } ) ;
154153 } ) ;
@@ -183,9 +182,13 @@ describe.only('CRUD API', function () {
183182 const spy = sinon . spy ( Collection . prototype , 'aggregate' ) ;
184183 const result = await collection . countDocuments ( { } ) ;
185184 expect ( result ) . to . deep . equal ( 2 ) ;
186- expect ( events [ 0 ] ) . to . be . instanceOf ( CommandSucceededEvent ) ;
187- expect ( spy . returnValues [ 0 ] ) . to . have . property ( 'closed' , true ) ;
188- expect ( spy . returnValues [ 0 ] ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
185+ if ( runNodelessTests ) {
186+ expect ( ensureTypeByName ( events [ 0 ] , 'CommandSucceededEvent' ) ) . to . be . true ;
187+ } else {
188+ expect ( events [ 0 ] ) . to . be . instanceOf ( CommandSucceededEvent ) ;
189+ expect ( spy . returnValues [ 0 ] ) . to . have . property ( 'closed' , true ) ;
190+ expect ( spy . returnValues [ 0 ] ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
191+ }
189192 } ) ;
190193 } ) ;
191194
@@ -215,10 +218,14 @@ describe.only('CRUD API', function () {
215218 it ( 'the cursor for countDocuments is closed' , async function ( ) {
216219 const spy = sinon . spy ( Collection . prototype , 'aggregate' ) ;
217220 const error = await collection . countDocuments ( { } ) . catch ( error => error ) ;
218- expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
219- expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandFailedEvent ) ;
220- expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
221- expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
221+ if ( runNodelessTests ) {
222+ expect ( ensureTypeByName ( error , 'MongoServerError' ) ) . to . be . true ;
223+ } else {
224+ expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
225+ expect ( events . at ( 0 ) ) . to . be . instanceOf ( CommandFailedEvent ) ;
226+ expect ( spy . returnValues . at ( 0 ) ) . to . have . property ( 'closed' , true ) ;
227+ expect ( spy . returnValues . at ( 0 ) ) . to . have . nested . property ( 'session.hasEnded' , true ) ;
228+ }
222229 } ) ;
223230 } ) ;
224231 } ) ;
@@ -795,7 +802,11 @@ describe.only('CRUD API', function () {
795802 . bulkWrite ( ops , { ordered : false , writeConcern : { w : 1 } } )
796803 . catch ( error => error ) ;
797804
798- expect ( error ) . to . be . instanceOf ( MongoBulkWriteError ) ;
805+ if ( runNodelessTests ) {
806+ expect ( ensureTypeByName ( error , 'MongoBulkWriteError' ) ) . to . be . true ;
807+ } else {
808+ expect ( error ) . to . be . instanceOf ( MongoBulkWriteError ) ;
809+ }
799810 // 1004 because one of them is duplicate key
800811 // but since it is unordered we continued to write
801812 expect ( error ) . to . have . property ( 'insertedCount' , 1004 ) ;
@@ -818,7 +829,8 @@ describe.only('CRUD API', function () {
818829 . collection ( 't20_1' )
819830 . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } )
820831 . catch ( err => err ) ;
821- expect ( err ) . to . be . instanceOf ( MongoBulkWriteError ) ;
832+ // expect(err).to.be.instanceOf(MongoBulkWriteError);
833+ expect ( ensureTypeByName ( err , 'MongoBulkWriteError' ) ) . to . be . true ;
822834 } ) ;
823835
824836 describe ( 'sort support' , function ( ) {
@@ -827,7 +839,6 @@ describe.only('CRUD API', function () {
827839 let collection : Collection ;
828840
829841 beforeEach ( async function ( ) {
830- this . configuration . mongodb = mongodb ;
831842 client = this . configuration . newClient ( { monitorCommands : true } ) ;
832843 events = [ ] ;
833844 client . on ( 'commandStarted' , commandStarted =>
0 commit comments