1
- import { context as dummyContext } from '../../../../tests/resources/contexts/hello-world' ;
2
1
import { Logger } from '../../src' ;
3
2
import { populateEnvironmentVariables } from '../helpers' ;
4
3
@@ -56,13 +55,8 @@ describe('Logger', () => {
56
55
57
56
logger . error ( 'foo' ) ;
58
57
logger . error ( 'foo' , { bar : 'baz' } ) ;
59
- logger . error ( { bar : 'baz' , message : 'foo' } ) ;
60
58
61
- const error = new Error ( 'Something happened!' ) ;
62
- error . stack = 'A custom stack trace' ;
63
- logger . error ( 'foo' , { bar : 'baz' } , error ) ;
64
-
65
- expect ( console . log ) . toBeCalledTimes ( 4 ) ;
59
+ expect ( console . log ) . toBeCalledTimes ( 2 ) ;
66
60
expect ( console . log ) . toHaveBeenNthCalledWith ( 1 , {
67
61
message : 'foo' ,
68
62
service : 'hello-world' ,
@@ -78,27 +72,6 @@ describe('Logger', () => {
78
72
timestamp : '2016-06-20T12:08:10.000Z' ,
79
73
xray_trace_id : 'abcdef123456abcdef123456abcdef123456'
80
74
} ) ;
81
- expect ( console . log ) . toHaveBeenNthCalledWith ( 3 , {
82
- bar : 'baz' ,
83
- message : 'foo' ,
84
- service : 'hello-world' ,
85
- level : 'ERROR' ,
86
- timestamp : '2016-06-20T12:08:10.000Z' ,
87
- xray_trace_id : 'abcdef123456abcdef123456abcdef123456'
88
- } ) ;
89
- expect ( console . log ) . toHaveBeenNthCalledWith ( 4 , {
90
- bar : 'baz' ,
91
- error : {
92
- message : 'Something happened!' ,
93
- name : 'Error' ,
94
- stack : 'A custom stack trace' ,
95
- } ,
96
- message : 'foo' ,
97
- service : 'hello-world' ,
98
- level : 'ERROR' ,
99
- timestamp : '2016-06-20T12:08:10.000Z' ,
100
- xray_trace_id : 'abcdef123456abcdef123456abcdef123456'
101
- } ) ;
102
75
} ) ;
103
76
104
77
test ( 'should return a valid DEBUG log' , ( ) => {
@@ -152,44 +125,5 @@ describe('Logger', () => {
152
125
153
126
} ) ;
154
127
155
- test ( 'should return a valid INFO log with context enabled' , ( ) => {
156
-
157
- const logger = new Logger ( {
158
- isContextEnabled : true
159
- } ) ;
160
- logger . addContext ( dummyContext ) ;
161
-
162
- logger . info ( 'foo' ) ;
163
- logger . info ( { message : 'foo' , bar : 'baz' } ) ;
164
-
165
- expect ( console . log ) . toBeCalledTimes ( 2 ) ;
166
- expect ( console . log ) . toHaveBeenNthCalledWith ( 1 , {
167
- 'aws_request_id' : 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef' ,
168
- 'cold_start' : true ,
169
- 'lambda_function_arn' : 'arn:aws:lambda:eu-central-1:123456789012:function:Example' ,
170
- 'lambda_function_memory_size' : 128 ,
171
- 'lambda_function_name' : 'foo-bar-function' ,
172
- 'level' : 'INFO' ,
173
- 'message' : 'foo' ,
174
- 'service' : 'hello-world' ,
175
- 'timestamp' : '2016-06-20T12:08:10.000Z' ,
176
- 'xray_trace_id' : 'abcdef123456abcdef123456abcdef123456'
177
- } ) ;
178
- expect ( console . log ) . toHaveBeenNthCalledWith ( 2 , {
179
- 'aws_request_id' : 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef' ,
180
- 'bar' : 'baz' ,
181
- 'cold_start' : true ,
182
- 'lambda_function_arn' : 'arn:aws:lambda:eu-central-1:123456789012:function:Example' ,
183
- 'lambda_function_memory_size' : 128 ,
184
- 'lambda_function_name' : 'foo-bar-function' ,
185
- 'level' : 'INFO' ,
186
- 'message' : 'foo' ,
187
- 'service' : 'hello-world' ,
188
- 'timestamp' : '2016-06-20T12:08:10.000Z' ,
189
- 'xray_trace_id' : 'abcdef123456abcdef123456abcdef123456'
190
- } ) ;
191
-
192
- } ) ;
193
-
194
128
} ) ;
195
129
0 commit comments