@@ -64,44 +64,77 @@ describe('setupLoggerAndTelemetry', () => {
64
64
bus . emit ( 'mongosh:mongoshrc-mongorc-warn' ) ;
65
65
bus . emit ( 'mongosh:eval-cli-script' ) ;
66
66
67
- expect ( logOutput ) . to . have . lengthOf ( 23 ) ;
68
- expect ( logOutput [ 0 ] . msg ) . to . match ( / ^ m o n g o s h : s t a r t - l o g g i n g \{ " v e r s i o n " : " .+ " , " e x e c P a t h " : " .+ " , " i s C o m p i l e d B i n a r y " : .+ \} $ / ) ;
69
- expect ( logOutput [ 1 ] . msg ) . to . equal ( 'mongosh:update-user {"enableTelemetry":false}' ) ;
70
- expect ( logOutput [ 2 ] . msg ) . to . match ( / ^ m o n g o s h : c o n n e c t / ) ;
71
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " s e s s i o n _ i d " : " 5 f b 3 c 2 0 e e 1 5 0 7 e 8 9 4 e 5 3 4 0 f 3 " / ) ;
72
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " u s e r I d " : " 5 3 d e f e 9 9 5 f a 4 7 e 6 c 1 3 1 0 2 d 9 d " / ) ;
73
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " c o n n e c t i o n U r i " : " m o n g o d b : \/ \/ l o c a l h o s t \/ " / ) ;
74
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " i s _ l o c a l h o s t " : t r u e / ) ;
75
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " i s _ a t l a s " : f a l s e / ) ;
76
- expect ( logOutput [ 2 ] . msg ) . to . match ( / " n o d e _ v e r s i o n " : " v 1 2 \. 1 9 \. 0 " / ) ;
77
- expect ( logOutput [ 3 ] . type ) . to . equal ( 'Error' ) ;
78
- expect ( logOutput [ 3 ] . msg ) . to . match ( / m e o w / ) ;
79
- expect ( logOutput [ 4 ] . msg ) . to . equal ( 'mongosh:use {"db":"admin"}' ) ;
80
- expect ( logOutput [ 5 ] . msg ) . to . equal ( 'mongosh:show {"method":"dbs"}' ) ;
81
- expect ( logOutput [ 6 ] . msg ) . to . equal ( 'mongosh:update-user {"enableTelemetry":true}' ) ;
82
- expect ( logOutput [ 7 ] . msg ) . to . match ( / ^ m o n g o s h : c o n n e c t / ) ;
83
- expect ( logOutput [ 8 ] . type ) . to . equal ( 'Error' ) ;
84
- expect ( logOutput [ 8 ] . msg ) . to . match ( / m e o w / ) ;
85
- expect ( logOutput [ 9 ] . msg ) . to . equal ( 'mongosh:use {"db":"admin"}' ) ;
86
- expect ( logOutput [ 10 ] . msg ) . to . equal ( 'mongosh:show {"method":"dbs"}' ) ;
87
- expect ( logOutput [ 11 ] . msg ) . to . equal ( 'mongosh:setCtx {"method":"setCtx"}' ) ;
88
- expect ( logOutput [ 12 ] . msg ) . to . match ( / ^ m o n g o s h : a p i - c a l l / ) ;
89
- expect ( logOutput [ 12 ] . msg ) . to . match ( / " d b " : " t e s t - 1 6 0 3 9 8 6 6 8 2 0 0 0 " / ) ;
90
- expect ( logOutput [ 13 ] . msg ) . to . match ( / ^ m o n g o s h : a p i - c a l l / ) ;
91
- expect ( logOutput [ 13 ] . msg ) . to . match ( / " e m a i l " : " < e m a i l > " / ) ;
92
- expect ( logOutput [ 14 ] . msg ) . to . match ( / ^ m o n g o s h : e v a l u a t e - i n p u t / ) ;
93
- expect ( logOutput [ 14 ] . msg ) . to . match ( / " i n p u t " : " 1 \+ 1 " / ) ;
94
- expect ( logOutput [ 15 ] . msg ) . to . match ( / " v e r s i o n " : " 3 .6 .1 " / ) ;
95
- expect ( logOutput [ 16 ] . msg ) . to . equal ( 'mongosh:start-loading-cli-scripts' ) ;
96
- expect ( logOutput [ 17 ] . msg ) . to . match ( / ^ m o n g o s h : a p i - l o a d - f i l e / ) ;
97
- expect ( logOutput [ 17 ] . msg ) . to . match ( / " n e s t e d " : t r u e / ) ;
98
- expect ( logOutput [ 17 ] . msg ) . to . match ( / " f i l e n a m e " : " f o o b a r .j s " / ) ;
99
- expect ( logOutput [ 18 ] . msg ) . to . equal ( 'mongosh:start-mongosh-repl {"version":"1.0.0"}' ) ;
100
- expect ( logOutput [ 19 ] . msg ) . to . match ( / " n e s t e d " : f a l s e / ) ;
101
- expect ( logOutput [ 19 ] . msg ) . to . match ( / " f i l e n a m e " : " f o o b a r .j s " / ) ;
102
- expect ( logOutput [ 20 ] . msg ) . to . equal ( 'mongosh:mongoshrc-load' ) ;
103
- expect ( logOutput [ 21 ] . msg ) . to . equal ( 'mongosh:mongoshrc-mongorc-warn' ) ;
104
- expect ( logOutput [ 22 ] . msg ) . to . equal ( 'mongosh:eval-cli-script' ) ;
67
+ bus . emit ( 'mongosh-snippets:loaded' , { installdir : '/' } ) ;
68
+ bus . emit ( 'mongosh-snippets:npm-lookup' , { existingVersion : 'v1.2.3' } ) ;
69
+ bus . emit ( 'mongosh-snippets:npm-lookup-stopped' ) ;
70
+ bus . emit ( 'mongosh-snippets:npm-download-failed' , { npmMetadataURL : 'https://example.com' } ) ;
71
+ bus . emit ( 'mongosh-snippets:npm-download-active' , { npmMetadataURL : 'https://example.com' , npmTarballURL : 'https://example.net' } ) ;
72
+ bus . emit ( 'mongosh-snippets:fetch-index' , { refreshMode : 'always' } ) ;
73
+ bus . emit ( 'mongosh-snippets:fetch-cache-invalid' ) ;
74
+ bus . emit ( 'mongosh-snippets:fetch-index-error' , { action : 'fetch' , url : 'https://localhost' } ) ;
75
+ bus . emit ( 'mongosh-snippets:fetch-index-done' ) ;
76
+ bus . emit ( 'mongosh-snippets:package-json-edit-error' , { error : 'failed' } ) ;
77
+ bus . emit ( 'mongosh-snippets:spawn-child' , { args : [ 'npm' , 'install' ] } ) ;
78
+ bus . emit ( 'mongosh-snippets:load-snippet' , { source : 'load-all' , name : 'foo' } ) ;
79
+ bus . emit ( 'mongosh-snippets:snippet-command' , { args : [ 'install' , 'foo' ] } ) ;
80
+ bus . emit ( 'mongosh-snippets:transform-error' , { error : 'failed' , addition : 'oh no' , name : 'foo' } ) ;
81
+
82
+ let i = 0 ;
83
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / ^ m o n g o s h : s t a r t - l o g g i n g \{ " v e r s i o n " : " .+ " , " e x e c P a t h " : " .+ " , " i s C o m p i l e d B i n a r y " : .+ \} $ / ) ;
84
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:update-user {"enableTelemetry":false}' ) ;
85
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h : c o n n e c t / ) ;
86
+ expect ( logOutput [ i ] . msg ) . to . match ( / " s e s s i o n _ i d " : " 5 f b 3 c 2 0 e e 1 5 0 7 e 8 9 4 e 5 3 4 0 f 3 " / ) ;
87
+ expect ( logOutput [ i ] . msg ) . to . match ( / " u s e r I d " : " 5 3 d e f e 9 9 5 f a 4 7 e 6 c 1 3 1 0 2 d 9 d " / ) ;
88
+ expect ( logOutput [ i ] . msg ) . to . match ( / " c o n n e c t i o n U r i " : " m o n g o d b : \/ \/ l o c a l h o s t \/ " / ) ;
89
+ expect ( logOutput [ i ] . msg ) . to . match ( / " i s _ l o c a l h o s t " : t r u e / ) ;
90
+ expect ( logOutput [ i ] . msg ) . to . match ( / " i s _ a t l a s " : f a l s e / ) ;
91
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " n o d e _ v e r s i o n " : " v 1 2 \. 1 9 \. 0 " / ) ;
92
+ expect ( logOutput [ i ] . type ) . to . equal ( 'Error' ) ;
93
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / m e o w / ) ;
94
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:use {"db":"admin"}' ) ;
95
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:show {"method":"dbs"}' ) ;
96
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:update-user {"enableTelemetry":true}' ) ;
97
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / ^ m o n g o s h : c o n n e c t / ) ;
98
+ expect ( logOutput [ i ] . type ) . to . equal ( 'Error' ) ;
99
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / m e o w / ) ;
100
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:use {"db":"admin"}' ) ;
101
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:show {"method":"dbs"}' ) ;
102
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:setCtx {"method":"setCtx"}' ) ;
103
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h : a p i - c a l l / ) ;
104
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " d b " : " t e s t - 1 6 0 3 9 8 6 6 8 2 0 0 0 " / ) ;
105
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h : a p i - c a l l / ) ;
106
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " e m a i l " : " < e m a i l > " / ) ;
107
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h : e v a l u a t e - i n p u t / ) ;
108
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " i n p u t " : " 1 \+ 1 " / ) ;
109
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " v e r s i o n " : " 3 .6 .1 " / ) ;
110
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:start-loading-cli-scripts' ) ;
111
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h : a p i - l o a d - f i l e / ) ;
112
+ expect ( logOutput [ i ] . msg ) . to . match ( / " n e s t e d " : t r u e / ) ;
113
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " f i l e n a m e " : " f o o b a r .j s " / ) ;
114
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:start-mongosh-repl {"version":"1.0.0"}' ) ;
115
+ expect ( logOutput [ i ] . msg ) . to . match ( / " n e s t e d " : f a l s e / ) ;
116
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " f i l e n a m e " : " f o o b a r .j s " / ) ;
117
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:mongoshrc-load' ) ;
118
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:mongoshrc-mongorc-warn' ) ;
119
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh:eval-cli-script' ) ;
120
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:loaded {"installdir":"/"}' ) ;
121
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:npm-lookup {"existingVersion":"v1.2.3"}' ) ;
122
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:npm-lookup-stopped' ) ;
123
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h - s n i p p e t s : n p m - d o w n l o a d - f a i l e d / ) ;
124
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " n p m M e t a d a t a U R L " : " h t t p s : \/ \/ e x a m p l e .c o m " / ) ;
125
+ expect ( logOutput [ i ] . msg ) . to . match ( / ^ m o n g o s h - s n i p p e t s : n p m - d o w n l o a d - a c t i v e / ) ;
126
+ expect ( logOutput [ i ] . msg ) . to . match ( / " n p m M e t a d a t a U R L " : " h t t p s : \/ \/ e x a m p l e .c o m " / ) ;
127
+ expect ( logOutput [ i ++ ] . msg ) . to . match ( / " n p m T a r b a l l U R L " : " h t t p s : \/ \/ e x a m p l e .n e t " / ) ;
128
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:fetch-index {"refreshMode":"always"}' ) ;
129
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:fetch-cache-invalid' ) ;
130
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:fetch-index-error {"action":"fetch","url":"https://localhost"}' ) ;
131
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:fetch-index-done' ) ;
132
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:package-json-edit-error {"error":"failed"}' ) ;
133
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:spawn-child {"args":["npm","install"]}' ) ;
134
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:load-snippet {"source":"load-all","name":"foo"}' ) ;
135
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:snippet-command {"args":["install","foo"]}' ) ;
136
+ expect ( logOutput [ i ++ ] . msg ) . to . equal ( 'mongosh-snippets:transform-error {"error":"failed","addition":"oh no","name":"foo"}' ) ;
137
+ expect ( i ) . to . equal ( logOutput . length ) ;
105
138
106
139
107
140
const mongosh_version = require ( '../package.json' ) . version ;
@@ -226,6 +259,16 @@ describe('setupLoggerAndTelemetry', () => {
226
259
} ,
227
260
userId : '53defe995fa47e6c13102d9d'
228
261
}
262
+ ] ,
263
+ [
264
+ 'track' ,
265
+ {
266
+ userId : '53defe995fa47e6c13102d9d' ,
267
+ event : 'Snippet Install' ,
268
+ properties : {
269
+ mongosh_version
270
+ }
271
+ }
229
272
]
230
273
] ) ;
231
274
} ) ;
0 commit comments