File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed
Expand file tree Collapse file tree 4 files changed +78
-0
lines changed 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 not fail 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 . not . be . null ;
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+ handlerFunc . should . not . be . null ;
32+ } ) ;
33+ it ( "should catch TypeError exception" , async ( ) => {
34+ const handler = "InitThrowsTypeError.handler"
35+ const appRoot = "test/unit/utils/function" ;
36+
37+ const handlerFunc = ( await load (
38+ appRoot ,
39+ handler
40+ ) ) as Function ;
41+
42+ handlerFunc . should . be . Function ;
43+ handlerFunc . should . not . be . null ;
44+ } ) ;
45+ } ) ;
Original file line number Diff line number Diff line change 1+ exports . handler = async ( event , context ) => {
2+ return 'Function complete.' ;
3+ }
Original file line number Diff line number Diff line change 1+ // console.log("******** enter the init block ********");
2+
3+ let resolved = "No" ;
4+
5+ function sleep ( ms ) {
6+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) . then ( ( ) => { resolved = "Yes!" } ) ;
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+
22+ return 'Function complete.' ;
23+ }
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 'Function complete.' ;
7+ }
You can’t perform that action at this time.
0 commit comments