@@ -2442,15 +2442,52 @@ describe('CliRepl', function () {
2442
2442
hasCollectionNames : boolean ;
2443
2443
hasDatabaseNames : boolean ;
2444
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
+
2445
2484
describe ( 'autocompletion' , function ( ) {
2446
2485
let cliRepl : CliRepl ;
2447
- const tab = async ( ) => {
2486
+
2487
+ const tabCompletion = async ( ) => {
2448
2488
await tick ( ) ;
2449
2489
input . write ( '\u0009' ) ;
2450
- } ;
2451
- const tabtab = async ( ) => {
2452
- await tab ( ) ;
2453
- await tab ( ) ;
2490
+ await waitCompletion ( cliRepl . bus ) ;
2454
2491
} ;
2455
2492
2456
2493
beforeEach ( async function ( ) {
@@ -2463,6 +2500,13 @@ describe('CliRepl', function () {
2463
2500
testServer ? await testServer . connectionString ( ) : '' ,
2464
2501
{ } as any
2465
2502
) ;
2503
+
2504
+ if ( ! ( testServer as any ) ?. _opts . args ?. includes ( '--auth' ) ) {
2505
+ // make sure there are some collections we can autocomplete on below
2506
+ input . write ( 'db.coll.insertOne({})\n' ) ;
2507
+ input . write ( 'db.movies.insertOne({})\n' ) ;
2508
+ await waitEval ( cliRepl . bus ) ;
2509
+ }
2466
2510
} ) ;
2467
2511
2468
2512
afterEach ( async function ( ) {
@@ -2479,26 +2523,33 @@ describe('CliRepl', function () {
2479
2523
if ( process . env . MONGOSH_TEST_FORCE_API_STRICT ) {
2480
2524
return this . skip ( ) ;
2481
2525
}
2526
+
2482
2527
output = '' ;
2483
2528
input . write ( 'db.wat' ) ;
2484
- await tabtab ( ) ;
2485
- await waitCompletion ( cliRepl . bus ) ;
2529
+ await tabCompletion ( ) ;
2530
+ await tabCompletion ( ) ;
2486
2531
if ( wantWatch ) {
2487
2532
expect ( output ) . to . include ( 'db.watch' ) ;
2488
2533
} else {
2489
2534
expect ( output ) . not . to . include ( 'db.watch' ) ;
2490
2535
}
2491
2536
} ) ;
2492
2537
2493
- it ( 'completes the version method' , async function ( ) {
2538
+ it ( `${
2539
+ wantVersion ? 'completes' : 'does not complete'
2540
+ } the version method`, async function ( ) {
2494
2541
if ( process . env . MONGOSH_TEST_FORCE_API_STRICT ) {
2495
2542
return this . skip ( ) ;
2496
2543
}
2497
2544
output = '' ;
2498
2545
input . write ( 'db.vers' ) ;
2499
- await tabtab ( ) ;
2500
- await waitCompletion ( cliRepl . bus ) ;
2501
- expect ( output ) . to . include ( 'db.version' ) ;
2546
+ await tabCompletion ( ) ;
2547
+ await tabCompletion ( ) ;
2548
+ if ( wantVersion ) {
2549
+ expect ( output ) . to . include ( 'db.version' ) ;
2550
+ } else {
2551
+ expect ( output ) . to . not . include ( 'db.version' ) ;
2552
+ }
2502
2553
} ) ;
2503
2554
2504
2555
it ( 'does not complete legacy JS get/set definitions' , async function ( ) {
@@ -2507,8 +2558,8 @@ describe('CliRepl', function () {
2507
2558
}
2508
2559
output = '' ;
2509
2560
input . write ( 'JSON.' ) ;
2510
- await tabtab ( ) ;
2511
- await waitCompletion ( cliRepl . bus ) ;
2561
+ await tabCompletion ( ) ;
2562
+ await tabCompletion ( ) ;
2512
2563
expect ( output ) . to . include ( 'JSON.__proto__' ) ;
2513
2564
expect ( output ) . not . to . include ( 'JSON.__defineGetter__' ) ;
2514
2565
expect ( output ) . not . to . include ( 'JSON.__defineSetter__' ) ;
@@ -2524,8 +2575,8 @@ describe('CliRepl', function () {
2524
2575
}
2525
2576
output = '' ;
2526
2577
input . write ( 'db.coll.getShardDis' ) ;
2527
- await tabtab ( ) ;
2528
- await waitCompletion ( cliRepl . bus ) ;
2578
+ await tabCompletion ( ) ;
2579
+ await tabCompletion ( ) ;
2529
2580
if ( wantShardDistribution ) {
2530
2581
expect ( output ) . to . include ( 'db.coll.getShardDistribution' ) ;
2531
2582
} else {
@@ -2543,8 +2594,8 @@ describe('CliRepl', function () {
2543
2594
2544
2595
output = '' ;
2545
2596
input . write ( 'db.testcoll' ) ;
2546
- await tabtab ( ) ;
2547
- await waitCompletion ( cliRepl . bus ) ;
2597
+ await tabCompletion ( ) ;
2598
+ await tabCompletion ( ) ;
2548
2599
expect ( output ) . to . include ( collname ) ;
2549
2600
2550
2601
input . write ( `db.${ collname } .drop()\n` ) ;
@@ -2553,50 +2604,63 @@ describe('CliRepl', function () {
2553
2604
2554
2605
it ( 'completes JS value properties properly (incomplete, double tab)' , async function ( ) {
2555
2606
input . write ( 'JSON.' ) ;
2556
- await tabtab ( ) ;
2557
- await waitCompletion ( cliRepl . bus ) ;
2607
+ await tabCompletion ( ) ;
2608
+ await tabCompletion ( ) ;
2558
2609
expect ( output ) . to . include ( 'JSON.parse' ) ;
2559
2610
expect ( output ) . to . include ( 'JSON.stringify' ) ;
2560
2611
expect ( output ) . not . to . include ( 'rawValue' ) ;
2561
2612
} ) ;
2562
2613
2563
2614
it ( 'completes JS value properties properly (complete, single tab)' , async function ( ) {
2564
2615
input . write ( 'JSON.pa' ) ;
2565
- await tab ( ) ;
2566
- await waitCompletion ( cliRepl . bus ) ;
2616
+ await tabCompletion ( ) ;
2567
2617
expect ( output ) . to . include ( 'JSON.parse' ) ;
2568
2618
expect ( output ) . not . to . include ( 'JSON.stringify' ) ;
2569
2619
expect ( output ) . not . to . include ( 'rawValue' ) ;
2570
2620
} ) ;
2571
2621
2572
2622
it ( 'completes shell commands' , async function ( ) {
2623
+ if ( process . env . USE_NEW_AUTOCOMPLETE ) {
2624
+ // TODO(MONGOSH-2035): not supported yet
2625
+ this . skip ( ) ;
2626
+ }
2627
+
2573
2628
input . write ( 'const dSomeVariableStartingWithD = 10;\n' ) ;
2574
2629
await waitEval ( cliRepl . bus ) ;
2575
2630
2576
2631
output = '' ;
2577
2632
input . write ( 'show d' ) ;
2578
- await tab ( ) ;
2579
- await waitCompletion ( cliRepl . bus ) ;
2633
+ await tabCompletion ( ) ;
2580
2634
expect ( output ) . to . include ( 'show databases' ) ;
2581
2635
expect ( output ) . not . to . include ( 'dSomeVariableStartingWithD' ) ;
2582
2636
} ) ;
2583
2637
2584
2638
it ( 'completes use <db>' , async function ( ) {
2639
+ if ( process . env . USE_NEW_AUTOCOMPLETE ) {
2640
+ // TODO(MONGOSH-2035): not supported yet
2641
+ this . skip ( ) ;
2642
+ }
2643
+
2585
2644
if ( ! hasDatabaseNames ) return this . skip ( ) ;
2586
2645
input . write ( 'db.getMongo()._listDatabases()\n' ) ; // populate database cache
2587
2646
await waitEval ( cliRepl . bus ) ;
2588
2647
2589
2648
input . write ( 'use adm' ) ;
2590
- await tab ( ) ;
2591
- await waitCompletion ( cliRepl . bus ) ;
2649
+ await tabCompletion ( ) ;
2592
2650
expect ( output ) . to . include ( 'use admin' ) ;
2593
2651
} ) ;
2594
2652
2595
- it ( 'completes query operators' , async function ( ) {
2653
+ it ( `${
2654
+ wantQueryOperators ? 'completes' : 'does not complete'
2655
+ } query operators`, async function ( ) {
2596
2656
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' ) ;
2657
+ await tabCompletion ( ) ;
2658
+ await tabCompletion ( ) ;
2659
+ if ( wantQueryOperators ) {
2660
+ expect ( output ) . to . include ( 'db.movies.find({year: {$gte' ) ;
2661
+ } else {
2662
+ expect ( output ) . to . not . include ( 'db.movies.find({year: {$gte' ) ;
2663
+ }
2600
2664
} ) ;
2601
2665
2602
2666
it ( 'completes properties of shell API result types' , async function ( ) {
@@ -2614,8 +2678,8 @@ describe('CliRepl', function () {
2614
2678
expect ( output ) . to . include ( 'DeleteResult' ) ;
2615
2679
2616
2680
input . write ( 'res.a' ) ;
2617
- await tabtab ( ) ;
2618
- await waitCompletion ( cliRepl . bus ) ;
2681
+ await tabCompletion ( ) ;
2682
+ await tabCompletion ( ) ;
2619
2683
expect ( output ) . to . include ( 'res.acknowledged' ) ;
2620
2684
} ) ;
2621
2685
@@ -2631,8 +2695,8 @@ describe('CliRepl', function () {
2631
2695
2632
2696
output = '' ;
2633
2697
input . write ( 'db.actestc' ) ;
2634
- await tabtab ( ) ;
2635
- await waitCompletion ( cliRepl . bus ) ;
2698
+ await tabCompletion ( ) ;
2699
+ await tabCompletion ( ) ;
2636
2700
expect ( output ) . to . include ( 'db.actestcoll1' ) ;
2637
2701
expect ( output ) . to . not . include ( 'db.actestcoll2' ) ;
2638
2702
} ) ;
0 commit comments