@@ -364,6 +364,34 @@ describe('e2e', function() {
364
364
expect ( result ) . to . include ( '{ _id: 1, value: 4 }' ) ;
365
365
} ) ;
366
366
367
+ it ( 'rewrites async properly for common libraries' , async function ( ) {
368
+ this . timeout ( 120_000 ) ;
369
+ // This is being run under the new async rewriter because the old one
370
+ // did not support these libraries at all (for various reasons).
371
+ // Once the new async rewriter is the default, this block can be removed.
372
+ shell = TestShell . start ( {
373
+ args : [ await testServer . connectionString ( ) ] ,
374
+ env : { ...process . env , MONGOSH_ASYNC_REWRITER2 : '1' }
375
+ } ) ;
376
+ await shell . waitForPrompt ( ) ;
377
+ shell . assertNoErrors ( ) ;
378
+
379
+ await shell . executeLine ( 'Date.now = () => new Date().getTime()' ) ; // MONGOSH-597 hack
380
+ await shell . executeLine ( `use ${ dbName } ` ) ;
381
+ await shell . executeLine ( 'db.test.insertOne({ d: new Date("2021-04-07T11:24:54+02:00") })' ) ;
382
+ shell . writeInputLine ( `load(${ JSON . stringify ( require . resolve ( 'lodash' ) ) } )` ) ;
383
+ shell . writeInputLine ( `load(${ JSON . stringify ( require . resolve ( 'moment' ) ) } )` ) ;
384
+ shell . writeInputLine ( 'print("loaded" + "scripts")' ) ;
385
+ await eventually ( ( ) => {
386
+ // Use eventually explicitly to get a bigger timeout, lodash is
387
+ // quite “big” in terms of async rewriting
388
+ shell . assertContainsOutput ( 'loadedscripts' ) ;
389
+ } , { timeout : 60_000 } ) ;
390
+ const result = await shell . executeLine (
391
+ 'moment(_.first(_.map(db.test.find().toArray(), "d"))).format("X")' ) ;
392
+ expect ( result ) . to . include ( '1617787494' ) ;
393
+ } ) ;
394
+
367
395
it ( 'expands explain output indefinitely' , async ( ) => {
368
396
await shell . executeLine ( 'explainOutput = db.test.find().explain()' ) ;
369
397
await shell . executeLine ( 'explainOutput.a = {b:{c:{d:{e:{f:{g:{h:{i:{j:{}}}}}}}}}}' ) ;
0 commit comments