44
55const os = require ( 'os' ) ;
66const fs = require ( 'fs' ) ;
7+ const path = require ( 'path' ) ;
78const readline = require ( 'readline' ) ;
89
910const AWS = require ( 'aws-sdk' ) ;
@@ -197,16 +198,24 @@ function test (testsFile) {
197198 */
198199 function onLambdaTests ( obj ) {
199200
200- if ( Array . isArray ( obj ) ) tests = obj ;
201- continueTest ( ) ;
201+ console . log ( 'Lamnda tests' , obj ) ;
202202
203+ if ( Array . isArray ( obj ) ) {
204+
205+ tests = obj ;
206+ continueTest ( ) ;
207+
208+ }
203209 }
204210
205211 function onLambdaConfig ( obj ) {
206212
207- if ( isObject ( obj ) ) lambdaCfg = obj ;
208- continueTest ( ) ;
213+ if ( isObject ( obj ) ) {
214+
215+ lambdaCfg = obj ;
216+ continueTest ( ) ;
209217
218+ }
210219 }
211220
212221 function continueTest ( ) {
@@ -224,12 +233,20 @@ function test (testsFile) {
224233function executeTests ( tests , lambdaCfg ) {
225234
226235 let splits ;
236+ let module ;
237+ let eventHandler ;
238+ let filePath ;
227239
228240 splits = lambdaCfg [ K_HANDLER ] . split ( '.' ) ;
229241
230242 if ( splits . length === 2 ) {
231243
232- const handler = require ( splits [ 0 ] ) [ splits [ 1 ] ] ;
244+ module = splits [ 0 ] ;
245+ eventHandler = splits [ 1 ] ;
246+
247+ filePath = path . join ( process . cwd ( ) , module + '.js' ) ;
248+
249+ const handler = require ( filePath ) [ eventHandler ] ;
233250
234251 let i , length ;
235252
@@ -773,7 +790,7 @@ function getJSON (file, options, callback) {
773790
774791 if ( isNEString ( options . checkFileType ) ) {
775792
776- if ( checkJSONObject ( object , file , options . printErrors ) ) {
793+ if ( checkJSONObject ( object , options ) ) {
777794
778795 // Config is valid and checked
779796 isValid = true ;
@@ -820,18 +837,17 @@ function writeJSON (file, object) {
820837
821838/**
822839 * @param {Object|Array } object
823- * @param {string } fileType
824- * @param {boolean } [printErrors = false]
840+ * @param {GetJSONOptions } options
825841 * @returns {boolean }
826842 */
827- function checkJSONObject ( object , fileType , printErrors ) {
843+ function checkJSONObject ( object , options ) {
828844 let result ;
829845
830846 result = isObject ( object ) ;
831847
832848 if ( result ) {
833849
834- switch ( fileType ) {
850+ switch ( options . checkFileType ) {
835851 case FILE_LAMBDA_CFG :
836852
837853 checkNEString ( K_ARCHIVE_NAME ) ;
@@ -847,6 +863,8 @@ function checkJSONObject (object, fileType, printErrors) {
847863 break ;
848864 case DEFAULT_FILE_TESTS :
849865
866+ console . log ( 'Check tests' , object ) ;
867+
850868 if ( Array . isArray ( object ) ) {
851869
852870 let i , length ;
@@ -873,7 +891,11 @@ function checkJSONObject (object, fileType, printErrors) {
873891
874892 } else {
875893
876- if ( printErrors ) console . error ( 'Invalid ' + fileType ) ;
894+ if ( options . printErrors ) {
895+
896+ console . error ( 'Invalid ' + options . checkFileType ) ;
897+
898+ }
877899
878900 }
879901
@@ -883,7 +905,12 @@ function checkJSONObject (object, fileType, printErrors) {
883905 let isValid ;
884906
885907 isValid = isNEString ( object [ property ] ) ;
886- if ( printErrors && ! isValid ) console . error ( 'Invalid ' + property ) ;
908+
909+ if ( options . printErrors && ! isValid ) {
910+
911+ console . error ( 'Invalid ' + property ) ;
912+
913+ }
887914
888915 result = result === true && isValid ;
889916 }
0 commit comments