@@ -5,7 +5,8 @@ import { EventEmitter } from 'events';
5
5
import { MongoshInvalidInputError } from '@mongosh/errors' ;
6
6
import type { MongoshBus } from '@mongosh/types' ;
7
7
import type { Writable } from 'stream' ;
8
- import { MongoshLoggingAndTelemetry } from './logging-and-telemetry' ;
8
+ import type { MongoshLoggingAndTelemetry } from '.' ;
9
+ import { setupLoggingAndTelemetry } from '.' ;
9
10
10
11
describe ( 'MongoshLoggingAndTelemetry' , function ( ) {
11
12
let logOutput : any [ ] ;
@@ -36,15 +37,15 @@ describe('MongoshLoggingAndTelemetry', function () {
36
37
analyticsOutput = [ ] ;
37
38
bus = new EventEmitter ( ) ;
38
39
39
- loggingAndTelemetry = new MongoshLoggingAndTelemetry (
40
+ loggingAndTelemetry = setupLoggingAndTelemetry ( {
40
41
bus,
41
42
analytics,
42
- {
43
+ userTraits : {
43
44
platform : process . platform ,
44
45
arch : process . arch ,
45
46
} ,
46
- '1.0.0'
47
- ) ;
47
+ mongoshVersion : '1.0.0' ,
48
+ } ) ;
48
49
49
50
logger = new MongoLogWriter ( logId , `/tmp/${ logId } _log` , {
50
51
write ( chunk : string , cb : ( ) => void ) {
@@ -62,37 +63,20 @@ describe('MongoshLoggingAndTelemetry', function () {
62
63
logger . destroy ( ) ;
63
64
} ) ;
64
65
65
- it ( 'throws when running setup twice' , function ( ) {
66
- loggingAndTelemetry . setup ( ) ;
67
-
68
- expect ( ( ) => loggingAndTelemetry . setup ( ) ) . throws (
69
- 'Setup can only be called once.'
70
- ) ;
71
- } ) ;
72
-
73
- it ( 'throws when trying to setup writer prematurely' , function ( ) {
74
- expect ( ( ) => loggingAndTelemetry . attachLogger ( logger ) ) . throws (
75
- 'Run setup() before setting up the log writer.'
76
- ) ;
77
- } ) ;
78
-
79
66
it ( 'throws when running attachLogger twice without detaching' , function ( ) {
80
- loggingAndTelemetry . setup ( ) ;
81
67
loggingAndTelemetry . attachLogger ( logger ) ;
82
68
expect ( ( ) => loggingAndTelemetry . attachLogger ( logger ) ) . throws (
83
69
'Previously set logger has not been detached. Run detachLogger() before setting.'
84
70
) ;
85
71
} ) ;
86
72
87
73
it ( 'does not throw when attaching and detaching loggers' , function ( ) {
88
- loggingAndTelemetry . setup ( ) ;
89
74
loggingAndTelemetry . attachLogger ( logger ) ;
90
75
loggingAndTelemetry . detachLogger ( ) ;
91
76
expect ( ( ) => loggingAndTelemetry . attachLogger ( logger ) ) . does . not . throw ( ) ;
92
77
} ) ;
93
78
94
79
it ( 'tracks new local connection events' , function ( ) {
95
- loggingAndTelemetry . setup ( ) ;
96
80
loggingAndTelemetry . attachLogger ( logger ) ;
97
81
98
82
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -147,7 +131,6 @@ describe('MongoshLoggingAndTelemetry', function () {
147
131
} ) ;
148
132
149
133
it ( 'tracks new atlas connection events' , function ( ) {
150
- loggingAndTelemetry . setup ( ) ;
151
134
loggingAndTelemetry . attachLogger ( logger ) ;
152
135
153
136
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -206,7 +189,6 @@ describe('MongoshLoggingAndTelemetry', function () {
206
189
} ) ;
207
190
208
191
it ( 'detaching logger leads to no logging but persists analytics' , function ( ) {
209
- loggingAndTelemetry . setup ( ) ;
210
192
loggingAndTelemetry . attachLogger ( logger ) ;
211
193
212
194
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -222,7 +204,6 @@ describe('MongoshLoggingAndTelemetry', function () {
222
204
} ) ;
223
205
224
206
it ( 'detaching logger applies to devtools-connect events' , function ( ) {
225
- loggingAndTelemetry . setup ( ) ;
226
207
loggingAndTelemetry . attachLogger ( logger ) ;
227
208
228
209
bus . emit ( 'devtools-connect:connect-fail-early' ) ;
@@ -241,11 +222,11 @@ describe('MongoshLoggingAndTelemetry', function () {
241
222
loggingAndTelemetry . attachLogger ( logger ) ;
242
223
243
224
bus . emit ( 'devtools-connect:connect-fail-early' ) ;
244
- expect ( logOutput ) . to . have . lengthOf ( 3 ) ;
225
+ bus . emit ( 'devtools-connect:connect-fail-early' ) ;
226
+ expect ( logOutput ) . to . have . lengthOf ( 4 ) ;
245
227
} ) ;
246
228
247
229
it ( 'detaching logger mid-way leads to no logging but persists analytics' , function ( ) {
248
- loggingAndTelemetry . setup ( ) ;
249
230
loggingAndTelemetry . attachLogger ( logger ) ;
250
231
251
232
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -266,7 +247,6 @@ describe('MongoshLoggingAndTelemetry', function () {
266
247
} ) ;
267
248
268
249
it ( 'detaching logger is recoverable' , function ( ) {
269
- loggingAndTelemetry . setup ( ) ;
270
250
loggingAndTelemetry . attachLogger ( logger ) ;
271
251
272
252
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -294,7 +274,6 @@ describe('MongoshLoggingAndTelemetry', function () {
294
274
} ) ;
295
275
296
276
it ( 'tracks a sequence of events' , function ( ) {
297
- loggingAndTelemetry . setup ( ) ;
298
277
loggingAndTelemetry . attachLogger ( logger ) ;
299
278
300
279
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -753,7 +732,6 @@ describe('MongoshLoggingAndTelemetry', function () {
753
732
} ) ;
754
733
755
734
it ( 'buffers deprecated API calls' , function ( ) {
756
- loggingAndTelemetry . setup ( ) ;
757
735
loggingAndTelemetry . attachLogger ( logger ) ;
758
736
759
737
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -929,7 +907,6 @@ describe('MongoshLoggingAndTelemetry', function () {
929
907
} ) ;
930
908
931
909
it ( 'does not track database calls outside of evaluate-{started,finished}' , function ( ) {
932
- loggingAndTelemetry . setup ( ) ;
933
910
loggingAndTelemetry . attachLogger ( logger ) ;
934
911
935
912
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
@@ -957,7 +934,6 @@ describe('MongoshLoggingAndTelemetry', function () {
957
934
expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
958
935
expect ( analyticsOutput ) . to . be . empty ;
959
936
960
- loggingAndTelemetry . setup ( ) ;
961
937
loggingAndTelemetry . attachLogger ( logger ) ;
962
938
963
939
bus . emit ( 'mongosh:connect' , {
0 commit comments