File tree Expand file tree Collapse file tree 5 files changed +104
-8
lines changed Expand file tree Collapse file tree 5 files changed +104
-8
lines changed Original file line number Diff line number Diff line change @@ -112,15 +112,14 @@ function _loadUserApp(
112112
113113async function _initializeFunction ( userApp : any ) : Promise < void > {
114114 try {
115- await userApp . initializeFunction ( ) ;
115+ await userApp . initializeFunction ( ) ;
116116 } catch ( e ) {
117- if ( e instanceof TypeError ) {
118- // initializeFunction lifecycle hook not implemented
119- return ;
120- }
121- else {
122- throw e ;
123- }
117+ if ( e instanceof TypeError ) {
118+ // initializeFunction lifecycle hook not implemented
119+ return ;
120+ } else {
121+ throw e ;
122+ }
124123 }
125124}
126125
Original file line number Diff line number Diff line change 1+ /** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+ "use strict" ;
4+
5+ require ( "should" ) ;
6+ import { load } from "../../../src/utils/UserFunction" ;
7+
8+ describe ( "Invoking the load function" , async ( ) => {
9+ it ( "should resolve promise when init hook function is present" , async ( ) => {
10+ const handler = "InitPresent.handler"
11+ const appRoot = "test/unit/utils/function" ;
12+
13+ const handlerFunc = ( await load (
14+ appRoot ,
15+ handler
16+ ) ) as Function ;
17+
18+ handlerFunc . should . be . Function ;
19+ handlerFunc ( ) . should . be . true ;
20+ } ) ;
21+ it ( "should not fail when init hook function is absent" , async ( ) => {
22+ const handler = "InitAbsent.handler"
23+ const appRoot = "test/unit/utils/function" ;
24+
25+ const handlerFunc = ( await load (
26+ appRoot ,
27+ handler
28+ ) ) as Function ;
29+
30+ handlerFunc . should . be . Function ;
31+ } ) ;
32+ it ( "should catch TypeError exception" , async ( ) => {
33+ const handler = "InitThrowsTypeError.handler"
34+ const appRoot = "test/unit/utils/function" ;
35+
36+ const handlerFunc = ( await load (
37+ appRoot ,
38+ handler
39+ ) ) as Function ;
40+
41+ handlerFunc . should . be . Function ;
42+ handlerFunc ( ) . should . be . true ;
43+ } ) ;
44+ } ) ;
Original file line number Diff line number Diff line change 1+ // console.log("******** enter the init block ********");
2+
3+ let resolved = false ;
4+
5+ function sleep ( ms ) {
6+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) . then ( ( ) => { resolved = true } ) ;
7+ }
8+
9+ async function init ( ) {
10+ // console.log("******** enter initializeFunction hook ********");
11+ // console.log("******** Is promised resolved? " + resolved + " ********");
12+ // console.log("******** sleep for 20 ms... ********")
13+ let p = await sleep ( 20 ) ;
14+ // console.log("******** wake up ********");
15+ // console.log("******** Is promised resolved? " + resolved + " ********");
16+ }
17+
18+ init ( ) ;
19+
20+ exports . handler = async ( event , context ) => {
21+ // console.log("******** enter the handler ********");
22+ // console.log("******** Is promised resolved? " + resolved + " ********");
23+ return ( resolved ? true : false ) ;
24+ }
Original file line number Diff line number Diff line change 1+ // console.log("******** enter the init block ********");
2+
3+ let resolved = false ;
4+
5+ function sleep ( ms ) {
6+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) . then ( ( ) => { resolved = true } ) ;
7+ }
8+
9+ exports . initializeFunction = async ( ) => {
10+ // console.log("******** enter initializeFunction hook ********");
11+ // console.log("******** Is promised resolved? " + resolved + " ********");
12+ // console.log("******** sleep for 20 ms... ********")
13+ let p = await sleep ( 20 ) ;
14+ // console.log("******** wake up ********");
15+ // console.log("******** Is promised resolved? " + resolved + " ********");
16+ }
17+
18+ exports . handler = async ( event , context ) => {
19+ // console.log("******** enter the handler ********");
20+ // console.log("******** Is promised resolved? " + resolved + " ********");
21+ return ( resolved ? true : false ) ;
22+ }
Original file line number Diff line number Diff line change 1+ exports . initializeFunction = async ( ) => {
2+ throw new TypeError ;
3+ }
4+
5+ exports . handler = async ( event , context ) => {
6+ return true ;
7+ }
You can’t perform that action at this time.
0 commit comments