1
- /**
2
- * Test InvocationLogs class
3
- *
4
- * @group unit/commons/invocationLogs
5
- *
6
- */
1
+ import { beforeEach , describe , expect , it } from 'vitest' ;
7
2
import { TestInvocationLogs } from '../../src/TestInvocationLogs.js' ;
8
3
9
4
const exampleLogs = `START RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 Version: $LATEST
@@ -15,7 +10,7 @@ END RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678
15
10
REPORT RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678\tDuration: 2.16 ms\tBilled Duration: 3 ms\tMemory Size: 128 MB\tMax Memory Used: 57 MB\t` ;
16
11
17
12
describe ( 'Constructor' , ( ) => {
18
- test ( 'it should parse base64 text correctly', ( ) => {
13
+ it ( 'parses base64 text correctly', ( ) => {
19
14
const invocationLogs = new TestInvocationLogs (
20
15
Buffer . from ( exampleLogs ) . toString ( 'base64' )
21
16
) ;
@@ -33,29 +28,29 @@ describe('doesAnyFunctionLogsContains()', () => {
33
28
Buffer . from ( exampleLogs ) . toString ( 'base64' )
34
29
) ;
35
30
} ) ;
36
- test ( 'it should return true if the text appear in any logs', ( ) => {
31
+ it ( 'returns true if the text appear in any of the logs', ( ) => {
37
32
const phraseInMessage = 'This is' ;
38
33
expect ( invocationLogs . doesAnyFunctionLogsContains ( phraseInMessage ) ) . toBe (
39
34
true
40
35
) ;
41
36
} ) ;
42
- test ( 'it should return false if the text does not appear in any logs ', ( ) => {
37
+ it ( 'returns false if the text does not appear anywhere ', ( ) => {
43
38
const phraseNotInMessage = 'A quick brown fox jumps over the lazy dog' ;
44
39
expect ( invocationLogs . doesAnyFunctionLogsContains ( phraseNotInMessage ) ) . toBe (
45
40
false
46
41
) ;
47
42
} ) ;
48
43
49
- test ( 'it should return true for key in the log ', ( ) => {
44
+ it ( 'returns true if the provided key appears in any of the logs ', ( ) => {
50
45
const keyInLog = 'error' ;
51
46
expect ( invocationLogs . doesAnyFunctionLogsContains ( keyInLog ) ) . toBe ( true ) ;
52
47
} ) ;
53
48
54
- test ( 'it should return true for a text in an error key', ( ) => {
49
+ it ( 'returns true it the provided text appears in an error key within the logs ', ( ) => {
55
50
const textInError = '/var/task/index.js:2778' ;
56
51
expect ( invocationLogs . doesAnyFunctionLogsContains ( textInError ) ) . toBe ( true ) ;
57
52
} ) ;
58
- test ( 'it should return false for the text that appears only on the ', ( ) => {
53
+ it ( 'excludes the report logs from the search ', ( ) => {
59
54
const textInStartLine = 'Version: $LATEST' ;
60
55
const textInEndLine = 'END RequestId' ;
61
56
const textInReportLine = 'Billed Duration' ;
@@ -70,7 +65,7 @@ describe('doesAnyFunctionLogsContains()', () => {
70
65
) ;
71
66
} ) ;
72
67
73
- test ( 'it should apply filter log based on the given level', ( ) => {
68
+ it ( 'filters log based on the given level', ( ) => {
74
69
const debugLogHasWordINFO = invocationLogs . doesAnyFunctionLogsContains (
75
70
'INFO' ,
76
71
'DEBUG'
@@ -100,7 +95,7 @@ describe('getFunctionLogs()', () => {
100
95
) ;
101
96
} ) ;
102
97
103
- test ( 'it should retrive logs of the given level only', ( ) => {
98
+ it ( 'retrives logs of the given level only', ( ) => {
104
99
const infoLogs = invocationLogs . getFunctionLogs ( 'INFO' ) ;
105
100
expect ( infoLogs . length ) . toBe ( 2 ) ;
106
101
expect ( infoLogs [ 0 ] . includes ( 'INFO' ) ) . toBe ( true ) ;
@@ -114,7 +109,7 @@ describe('getFunctionLogs()', () => {
114
109
expect ( errorLogs [ 0 ] . includes ( 'ERROR' ) ) . toBe ( true ) ;
115
110
} ) ;
116
111
117
- test ( 'it should NOT return logs generated by Lambda service (e.g. START, END, and REPORT)' , ( ) => {
112
+ it ( "doesn't return logs generated by Lambda service (e.g. START, END, and REPORT)" , ( ) => {
118
113
const errorLogs = invocationLogs . getFunctionLogs ( 'ERROR' ) ;
119
114
expect ( errorLogs . length ) . toBe ( 1 ) ;
120
115
expect ( errorLogs [ 0 ] . includes ( 'START' ) ) . toBe ( false ) ;
@@ -124,7 +119,7 @@ describe('getFunctionLogs()', () => {
124
119
} ) ;
125
120
126
121
describe ( 'parseFunctionLog()' , ( ) => {
127
- test ( 'it should return object with the correct values based on the given log', ( ) => {
122
+ it ( 'returns an object with the correct values based on the given log', ( ) => {
128
123
const rawLogStr =
129
124
'{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"DEBUG","message":"This is a DEBUG log but contains the word INFO some context and persistent key","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works"}' ;
130
125
@@ -146,7 +141,7 @@ describe('parseFunctionLog()', () => {
146
141
} ) ;
147
142
} ) ;
148
143
149
- test ( 'it should throw an error if receive incorrect formatted raw log string', ( ) => {
144
+ it ( 'throws an error if receive incorrect formatted raw log string', ( ) => {
150
145
const notJSONstring = 'not-json-string' ;
151
146
expect ( ( ) => {
152
147
TestInvocationLogs . parseFunctionLog ( notJSONstring ) ;
0 commit comments