@@ -29,53 +29,45 @@ describe("servie-lambda", () => {
2929 memoryLimitInMB : "128"
3030 } as any ) as Context ;
3131
32- it ( "should support routers" , done => {
32+ it ( "should support routers" , async ( ) => {
3333 const handler = createHandler ( function ( ) {
3434 return new Response ( "response" , {
3535 status : 200
3636 } ) ;
3737 } ) ;
3838
39- return handler ( event , context , ( err , res ) => {
40- if ( err ) return done ( err ) ;
39+ const res = await handler ( event , context ) ;
4140
42- expect ( res ) . toEqual ( {
43- statusCode : 200 ,
44- body : "response" ,
45- multiValueHeaders : {
46- "content-type" : [ "text/plain" ] ,
47- "content-length" : [ "8" ]
48- } ,
49- isBase64Encoded : false
50- } ) ;
51-
52- return done ( ) ;
41+ expect ( res ) . toEqual ( {
42+ statusCode : 200 ,
43+ body : "response" ,
44+ multiValueHeaders : {
45+ "content-type" : [ "text/plain" ] ,
46+ "content-length" : [ "8" ]
47+ } ,
48+ isBase64Encoded : false
5349 } ) ;
5450 } ) ;
5551
56- it ( "should fall through to 404" , done => {
52+ it ( "should fall through to 404" , async ( ) => {
5753 const handler = createHandler ( ( _req , next ) => next ( ) ) ;
5854
59- return handler ( event , context , ( err , res ) => {
60- if ( err ) return done ( err ) ;
61-
62- expect ( res ) . toEqual ( {
63- statusCode : 404 ,
64- body : "Cannot GET /test" ,
65- multiValueHeaders : {
66- "content-type" : [ "text/plain" ] ,
67- "content-security-policy" : [ "default-src 'self'" ] ,
68- "x-content-type-options" : [ "nosniff" ] ,
69- "content-length" : [ "16" ]
70- } ,
71- isBase64Encoded : false
72- } ) ;
73-
74- return done ( ) ;
55+ const res = await handler ( event , context ) ;
56+
57+ expect ( res ) . toEqual ( {
58+ statusCode : 404 ,
59+ body : "Cannot GET /test" ,
60+ multiValueHeaders : {
61+ "content-type" : [ "text/plain" ] ,
62+ "content-security-policy" : [ "default-src 'self'" ] ,
63+ "x-content-type-options" : [ "nosniff" ] ,
64+ "content-length" : [ "16" ]
65+ } ,
66+ isBase64Encoded : false
7567 } ) ;
7668 } ) ;
7769
78- it ( "should support multiple headers of the same key" , done => {
70+ it ( "should support multiple headers of the same key" , async ( ) => {
7971 const handler = createHandler ( ( ) => {
8072 return new Response ( null , {
8173 headers : {
@@ -84,37 +76,29 @@ describe("servie-lambda", () => {
8476 } ) ;
8577 } ) ;
8678
87- return handler ( event , context , ( err , res ) => {
88- if ( err ) return done ( err ) ;
79+ const res = await handler ( event , context ) ;
8980
90- expect ( res ) . toEqual ( {
91- statusCode : 200 ,
92- body : "" ,
93- multiValueHeaders : {
94- "set-cookie" : [ "a=a" , "b=b" , "c=c" ]
95- } ,
96- isBase64Encoded : false
97- } ) ;
98-
99- return done ( ) ;
81+ expect ( res ) . toEqual ( {
82+ statusCode : 200 ,
83+ body : "" ,
84+ multiValueHeaders : {
85+ "set-cookie" : [ "a=a" , "b=b" , "c=c" ]
86+ } ,
87+ isBase64Encoded : false
10088 } ) ;
10189 } ) ;
10290
103- it ( "should log and rewrite errors" , done => {
91+ it ( "should log and rewrite errors" , async ( ) => {
10492 const logError = jest . fn ( ) ;
10593 const handler = createHandler ( ( ) => Promise . reject ( new Error ( "boom" ) ) , {
10694 logError
10795 } ) ;
10896
109- return handler ( event , context , ( err , res ) => {
110- if ( err ) return done ( err ) ;
97+ const res = await handler ( event , context ) ;
11198
112- expect ( res ! . statusCode ) . toEqual ( 500 ) ;
113- expect ( res ! . isBase64Encoded ) . toEqual ( false ) ;
114- expect ( res ! . body ) . toContain ( "boom" ) ;
115- expect ( logError ) . toHaveBeenCalled ( ) ;
116-
117- return done ( ) ;
118- } ) ;
99+ expect ( res . statusCode ) . toEqual ( 500 ) ;
100+ expect ( res . isBase64Encoded ) . toEqual ( false ) ;
101+ expect ( res . body ) . toContain ( "boom" ) ;
102+ expect ( logError ) . toHaveBeenCalled ( ) ;
119103 } ) ;
120104} ) ;
0 commit comments