@@ -2441,16 +2441,81 @@ describe('CliRepl', function () {
2441
2441
wantShardDistribution : boolean ;
2442
2442
hasCollectionNames : boolean ;
2443
2443
hasDatabaseNames : boolean ;
2444
+ } ) : void {
2445
+ let wantVersion = true ;
2446
+ let wantQueryOperators = true ;
2447
+
2448
+ if ( process . env . USE_NEW_AUTOCOMPLETE && ! testServer ) {
2449
+ // mongodb-ts-autocomplete does not support noDb mode. It wouldn't be able
2450
+ // to list collections anyway, and since the collections don't exist it
2451
+ // wouldn't autocomplete methods on those collections.
2452
+ wantVersion = false ;
2453
+ wantQueryOperators = false ;
2454
+ wantWatch = false ;
2455
+ wantShardDistribution = false ;
2456
+ hasCollectionNames = false ;
2457
+ hasDatabaseNames = false ;
2458
+ }
2459
+
2460
+ if ( process . env . USE_NEW_AUTOCOMPLETE && testServer ) {
2461
+ if ( ( testServer as any ) ?. _opts . args ?. includes ( '--auth' ) ) {
2462
+ // mongodb-ts-autocomplete does not take into account the server version
2463
+ // or capabilities, so it always completes db.watch
2464
+ wantWatch = true ;
2465
+ // db.collection.getShardDistribution won't be autocompleted because we
2466
+ // can't list the collections due to to auth being required
2467
+ wantShardDistribution = false ;
2468
+ // we can't get the document schema because auth is required
2469
+ wantQueryOperators = false ;
2470
+ } else {
2471
+ // mongodb-ts-autocomplete does not take into account the server version
2472
+ // or capabilities, so it always completes db.watch and
2473
+ // db.collection.getShardDistribution assuming collection exists and can
2474
+ // be listed
2475
+ wantWatch = true ;
2476
+ wantShardDistribution = true ;
2477
+
2478
+ // TODO: we need MQL support in mongodb-ts-autocomplete in order for it
2479
+ // to autocomplete collection field names
2480
+ wantQueryOperators = false ;
2481
+ }
2482
+ }
2483
+
2484
+ return _verifyAutocompletion ( {
2485
+ testServer,
2486
+ wantVersion,
2487
+ wantQueryOperators,
2488
+ wantWatch,
2489
+ wantShardDistribution,
2490
+ hasCollectionNames,
2491
+ hasDatabaseNames,
2492
+ } ) ;
2493
+ }
2494
+
2495
+ function _verifyAutocompletion ( {
2496
+ testServer,
2497
+ wantVersion,
2498
+ wantQueryOperators,
2499
+ wantWatch,
2500
+ wantShardDistribution,
2501
+ hasCollectionNames,
2502
+ hasDatabaseNames,
2503
+ } : {
2504
+ testServer : MongodSetup | null ;
2505
+ wantVersion : boolean ;
2506
+ wantQueryOperators : boolean ;
2507
+ wantWatch : boolean ;
2508
+ wantShardDistribution : boolean ;
2509
+ hasCollectionNames : boolean ;
2510
+ hasDatabaseNames : boolean ;
2444
2511
} ) : void {
2445
2512
describe ( 'autocompletion' , function ( ) {
2446
2513
let cliRepl : CliRepl ;
2447
- const tab = async ( ) => {
2514
+
2515
+ const tabCompletion = async ( ) => {
2448
2516
await tick ( ) ;
2449
2517
input . write ( '\u0009' ) ;
2450
- } ;
2451
- const tabtab = async ( ) => {
2452
- await tab ( ) ;
2453
- await tab ( ) ;
2518
+ await waitCompletion ( cliRepl . bus ) ;
2454
2519
} ;
2455
2520
2456
2521
beforeEach ( async function ( ) {
@@ -2463,6 +2528,13 @@ describe('CliRepl', function () {
2463
2528
testServer ? await testServer . connectionString ( ) : '' ,
2464
2529
{ } as any
2465
2530
) ;
2531
+
2532
+ if ( ! ( testServer as any ) ?. _opts . args ?. includes ( '--auth' ) ) {
2533
+ // make sure there are some collections we can autocomplete on below
2534
+ input . write ( 'db.coll.insertOne({})\n' ) ;
2535
+ input . write ( 'db.movies.insertOne({})\n' ) ;
2536
+ await waitEval ( cliRepl . bus ) ;
2537
+ }
2466
2538
} ) ;
2467
2539
2468
2540
afterEach ( async function ( ) {
@@ -2479,26 +2551,33 @@ describe('CliRepl', function () {
2479
2551
if ( process . env . MONGOSH_TEST_FORCE_API_STRICT ) {
2480
2552
return this . skip ( ) ;
2481
2553
}
2554
+
2482
2555
output = '' ;
2483
2556
input . write ( 'db.wat' ) ;
2484
- await tabtab ( ) ;
2485
- await waitCompletion ( cliRepl . bus ) ;
2557
+ await tabCompletion ( ) ;
2558
+ await tabCompletion ( ) ;
2486
2559
if ( wantWatch ) {
2487
2560
expect ( output ) . to . include ( 'db.watch' ) ;
2488
2561
} else {
2489
2562
expect ( output ) . not . to . include ( 'db.watch' ) ;
2490
2563
}
2491
2564
} ) ;
2492
2565
2493
- it ( 'completes the version method' , async function ( ) {
2566
+ it ( `${
2567
+ wantVersion ? 'completes' : 'does not complete'
2568
+ } the version method`, async function ( ) {
2494
2569
if ( process . env . MONGOSH_TEST_FORCE_API_STRICT ) {
2495
2570
return this . skip ( ) ;
2496
2571
}
2497
2572
output = '' ;
2498
2573
input . write ( 'db.vers' ) ;
2499
- await tabtab ( ) ;
2500
- await waitCompletion ( cliRepl . bus ) ;
2501
- expect ( output ) . to . include ( 'db.version' ) ;
2574
+ await tabCompletion ( ) ;
2575
+ await tabCompletion ( ) ;
2576
+ if ( wantVersion ) {
2577
+ expect ( output ) . to . include ( 'db.version' ) ;
2578
+ } else {
2579
+ expect ( output ) . to . not . include ( 'db.version' ) ;
2580
+ }
2502
2581
} ) ;
2503
2582
2504
2583
it ( 'does not complete legacy JS get/set definitions' , async function ( ) {
@@ -2507,8 +2586,8 @@ describe('CliRepl', function () {
2507
2586
}
2508
2587
output = '' ;
2509
2588
input . write ( 'JSON.' ) ;
2510
- await tabtab ( ) ;
2511
- await waitCompletion ( cliRepl . bus ) ;
2589
+ await tabCompletion ( ) ;
2590
+ await tabCompletion ( ) ;
2512
2591
expect ( output ) . to . include ( 'JSON.__proto__' ) ;
2513
2592
expect ( output ) . not . to . include ( 'JSON.__defineGetter__' ) ;
2514
2593
expect ( output ) . not . to . include ( 'JSON.__defineSetter__' ) ;
@@ -2524,8 +2603,8 @@ describe('CliRepl', function () {
2524
2603
}
2525
2604
output = '' ;
2526
2605
input . write ( 'db.coll.getShardDis' ) ;
2527
- await tabtab ( ) ;
2528
- await waitCompletion ( cliRepl . bus ) ;
2606
+ await tabCompletion ( ) ;
2607
+ await tabCompletion ( ) ;
2529
2608
if ( wantShardDistribution ) {
2530
2609
expect ( output ) . to . include ( 'db.coll.getShardDistribution' ) ;
2531
2610
} else {
@@ -2543,8 +2622,8 @@ describe('CliRepl', function () {
2543
2622
2544
2623
output = '' ;
2545
2624
input . write ( 'db.testcoll' ) ;
2546
- await tabtab ( ) ;
2547
- await waitCompletion ( cliRepl . bus ) ;
2625
+ await tabCompletion ( ) ;
2626
+ await tabCompletion ( ) ;
2548
2627
expect ( output ) . to . include ( collname ) ;
2549
2628
2550
2629
input . write ( `db.${ collname } .drop()\n` ) ;
@@ -2553,17 +2632,16 @@ describe('CliRepl', function () {
2553
2632
2554
2633
it ( 'completes JS value properties properly (incomplete, double tab)' , async function ( ) {
2555
2634
input . write ( 'JSON.' ) ;
2556
- await tabtab ( ) ;
2557
- await waitCompletion ( cliRepl . bus ) ;
2635
+ await tabCompletion ( ) ;
2636
+ await tabCompletion ( ) ;
2558
2637
expect ( output ) . to . include ( 'JSON.parse' ) ;
2559
2638
expect ( output ) . to . include ( 'JSON.stringify' ) ;
2560
2639
expect ( output ) . not . to . include ( 'rawValue' ) ;
2561
2640
} ) ;
2562
2641
2563
2642
it ( 'completes JS value properties properly (complete, single tab)' , async function ( ) {
2564
2643
input . write ( 'JSON.pa' ) ;
2565
- await tab ( ) ;
2566
- await waitCompletion ( cliRepl . bus ) ;
2644
+ await tabCompletion ( ) ;
2567
2645
expect ( output ) . to . include ( 'JSON.parse' ) ;
2568
2646
expect ( output ) . not . to . include ( 'JSON.stringify' ) ;
2569
2647
expect ( output ) . not . to . include ( 'rawValue' ) ;
@@ -2575,8 +2653,7 @@ describe('CliRepl', function () {
2575
2653
2576
2654
output = '' ;
2577
2655
input . write ( 'show d' ) ;
2578
- await tab ( ) ;
2579
- await waitCompletion ( cliRepl . bus ) ;
2656
+ await tabCompletion ( ) ;
2580
2657
expect ( output ) . to . include ( 'show databases' ) ;
2581
2658
expect ( output ) . not . to . include ( 'dSomeVariableStartingWithD' ) ;
2582
2659
} ) ;
@@ -2587,16 +2664,21 @@ describe('CliRepl', function () {
2587
2664
await waitEval ( cliRepl . bus ) ;
2588
2665
2589
2666
input . write ( 'use adm' ) ;
2590
- await tab ( ) ;
2591
- await waitCompletion ( cliRepl . bus ) ;
2667
+ await tabCompletion ( ) ;
2592
2668
expect ( output ) . to . include ( 'use admin' ) ;
2593
2669
} ) ;
2594
2670
2595
- it ( 'completes query operators' , async function ( ) {
2671
+ it ( `${
2672
+ wantQueryOperators ? 'completes' : 'does not complete'
2673
+ } query operators`, async function ( ) {
2596
2674
input . write ( 'db.movies.find({year: {$g' ) ;
2597
- await tabtab ( ) ;
2598
- await waitCompletion ( cliRepl . bus ) ;
2599
- expect ( output ) . to . include ( 'db.movies.find({year: {$gte' ) ;
2675
+ await tabCompletion ( ) ;
2676
+ await tabCompletion ( ) ;
2677
+ if ( wantQueryOperators ) {
2678
+ expect ( output ) . to . include ( 'db.movies.find({year: {$gte' ) ;
2679
+ } else {
2680
+ expect ( output ) . to . not . include ( 'db.movies.find({year: {$gte' ) ;
2681
+ }
2600
2682
} ) ;
2601
2683
2602
2684
it ( 'completes properties of shell API result types' , async function ( ) {
@@ -2614,8 +2696,8 @@ describe('CliRepl', function () {
2614
2696
expect ( output ) . to . include ( 'DeleteResult' ) ;
2615
2697
2616
2698
input . write ( 'res.a' ) ;
2617
- await tabtab ( ) ;
2618
- await waitCompletion ( cliRepl . bus ) ;
2699
+ await tabCompletion ( ) ;
2700
+ await tabCompletion ( ) ;
2619
2701
expect ( output ) . to . include ( 'res.acknowledged' ) ;
2620
2702
} ) ;
2621
2703
@@ -2631,8 +2713,8 @@ describe('CliRepl', function () {
2631
2713
2632
2714
output = '' ;
2633
2715
input . write ( 'db.actestc' ) ;
2634
- await tabtab ( ) ;
2635
- await waitCompletion ( cliRepl . bus ) ;
2716
+ await tabCompletion ( ) ;
2717
+ await tabCompletion ( ) ;
2636
2718
expect ( output ) . to . include ( 'db.actestcoll1' ) ;
2637
2719
expect ( output ) . to . not . include ( 'db.actestcoll2' ) ;
2638
2720
} ) ;
0 commit comments