@@ -2,7 +2,8 @@ import { MongoshInternalError } from '@mongosh/errors';
2
2
import { bson } from '@mongosh/service-provider-core' ;
3
3
import { once } from 'events' ;
4
4
import { promises as fs } from 'fs' ;
5
- import http from 'http' ;
5
+ import type { Server as HTTPServer } from 'http' ;
6
+ import http , { createServer as createHTTPServer } from 'http' ;
6
7
import path from 'path' ;
7
8
import type { Duplex } from 'stream' ;
8
9
import { PassThrough } from 'stream' ;
@@ -29,6 +30,7 @@ import type { CliReplOptions } from './cli-repl';
29
30
import { CliRepl } from './cli-repl' ;
30
31
import { CliReplErrors } from './error-codes' ;
31
32
import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server' ;
33
+ import type { AddressInfo } from 'net' ;
32
34
const { EJSON } = bson ;
33
35
34
36
const delay = promisify ( setTimeout ) ;
@@ -138,7 +140,7 @@ describe('CliRepl', function () {
138
140
const content = await fs . readFile ( path . join ( tmpdir . path , 'config' ) , {
139
141
encoding : 'utf8' ,
140
142
} ) ;
141
- expect ( ( EJSON . parse ( content ) as any ) . enableTelemetry ) . to . be . false ;
143
+ expect ( EJSON . parse ( content ) . enableTelemetry ) . to . be . false ;
142
144
} ) ;
143
145
144
146
it ( 'does not store config options on disk that have not been changed' , async function ( ) {
@@ -188,7 +190,7 @@ describe('CliRepl', function () {
188
190
const content = await fs . readFile ( path . join ( tmpdir . path , 'config' ) , {
189
191
encoding : 'utf8' ,
190
192
} ) ;
191
- expect ( ( EJSON . parse ( content ) as any ) . inspectDepth ) . equal ( Infinity ) ;
193
+ expect ( EJSON . parse ( content ) . inspectDepth ) . equal ( Infinity ) ;
192
194
} ) ;
193
195
194
196
it ( 'emits exit when asked to, Node.js-style' , async function ( ) {
@@ -992,6 +994,62 @@ describe('CliRepl', function () {
992
994
) ;
993
995
} ) ;
994
996
} ) ;
997
+
998
+ context ( 'showing update information' , function ( ) {
999
+ let httpServer : HTTPServer ;
1000
+ let httpServerUrl : string ;
1001
+
1002
+ beforeEach ( async function ( ) {
1003
+ httpServer = createHTTPServer ( ( req , res ) => {
1004
+ res . end (
1005
+ JSON . stringify ( {
1006
+ versions : [ { version : '2023.4.15' } ] ,
1007
+ } )
1008
+ ) ;
1009
+ } ) ;
1010
+ httpServer . listen ( 0 ) ;
1011
+ await once ( httpServer , 'listening' ) ;
1012
+ httpServerUrl = `http://127.0.0.1:${
1013
+ ( httpServer . address ( ) as AddressInfo ) . port
1014
+ } `;
1015
+ } ) ;
1016
+
1017
+ afterEach ( async function ( ) {
1018
+ httpServer . close ( ) ;
1019
+ await once ( httpServer , 'close' ) ;
1020
+ } ) ;
1021
+
1022
+ it ( 'does not attempt to load information about new releases with --eval and no explicit --no-quiet' , async function ( ) {
1023
+ cliReplOptions . shellCliOptions . eval = [ '1+1' ] ;
1024
+ cliRepl = new CliRepl ( cliReplOptions ) ;
1025
+ cliRepl . fetchMongoshUpdateUrlRegardlessOfCiEnvironment = true ;
1026
+ cliRepl . config . updateURL = httpServerUrl ;
1027
+ let fetchingUpdateMetadataCalls = 0 ;
1028
+ cliRepl . bus . on (
1029
+ 'mongosh:fetching-update-metadata' ,
1030
+ ( ) => fetchingUpdateMetadataCalls ++
1031
+ ) ;
1032
+ await startWithExpectedImmediateExit ( cliRepl , '' ) ;
1033
+ expect ( fetchingUpdateMetadataCalls ) . to . equal ( 0 ) ;
1034
+ } ) ;
1035
+
1036
+ it ( 'does attempt to load information about new releases in --no-quiet mode' , async function ( ) {
1037
+ cliReplOptions . shellCliOptions . eval = [ '1+1' ] ;
1038
+ cliReplOptions . shellCliOptions . quiet = false ;
1039
+ cliRepl = new CliRepl ( cliReplOptions ) ;
1040
+ cliRepl . fetchMongoshUpdateUrlRegardlessOfCiEnvironment = true ;
1041
+ cliRepl . config . updateURL = httpServerUrl ;
1042
+ let fetchingUpdateMetadataCalls = 0 ;
1043
+ cliRepl . bus . on (
1044
+ 'mongosh:fetching-update-metadata' ,
1045
+ ( ) => fetchingUpdateMetadataCalls ++
1046
+ ) ;
1047
+ const requestPromise = once ( httpServer , 'request' ) ;
1048
+ await startWithExpectedImmediateExit ( cliRepl , '' ) ;
1049
+ expect ( fetchingUpdateMetadataCalls ) . to . equal ( 1 ) ;
1050
+ await requestPromise ;
1051
+ } ) ;
1052
+ } ) ;
995
1053
} ) ;
996
1054
997
1055
verifyAutocompletion ( {
0 commit comments