File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Analytics {
10
10
apiKey = process . env . AMPLITUDE_API_KEY ,
11
11
log,
12
12
funnelId = uuid . v4 ( ) ,
13
+ isMock,
13
14
} ) {
14
15
this . user = user
15
16
this . repo = repo
@@ -18,9 +19,20 @@ class Analytics {
18
19
this . funnelId = funnelId
19
20
this . apiKey = apiKey
20
21
this . log = log
22
+ this . isMock = isMock
21
23
}
22
24
23
25
track ( eventName , metadata = { } ) {
26
+ const log = this . log
27
+
28
+ if (
29
+ process . env . NODE_ENV === 'local' ||
30
+ ( process . env . NODE_ENV === 'test' && ! this . isMock )
31
+ ) {
32
+ log . info ( 'Turn off Analytics in a local or test environment.' )
33
+ return
34
+ }
35
+
24
36
if ( ! eventName ) {
25
37
throw new Error ( 'Analytics missing event name' )
26
38
}
@@ -51,7 +63,6 @@ class Analytics {
51
63
params . append ( 'api_key' , this . apiKey )
52
64
params . append ( 'event' , JSON . stringify ( events ) )
53
65
54
- const log = this . log
55
66
const newEventPromise = nodeFetch ( 'https://api.amplitude.com/httpapi' , {
56
67
method : 'POST' ,
57
68
body : params ,
Original file line number Diff line number Diff line change @@ -11,8 +11,10 @@ describe('Analytics', () => {
11
11
user : 'mockusername' ,
12
12
apiKey : 'mock api key' ,
13
13
funnelId : 'mockFunnelId' ,
14
+ isMock : true ,
14
15
log : {
15
16
error : mockFn ,
17
+ info : mockFn ,
16
18
} ,
17
19
} )
18
20
@@ -27,6 +29,6 @@ describe('Analytics', () => {
27
29
28
30
await analytics . finishQueue ( )
29
31
30
- expect ( mockFn ) . not . toBeCalled ( )
32
+ expect ( mockFn ) . not . toHaveBeenCalled ( )
31
33
} )
32
34
} )
You can’t perform that action at this time.
0 commit comments