2016-09-08 24 views
1

AWS LambdaにFrisby.jsテストをデプロイしようとしていて、引き続き参照エラーが発生しています。私はLambdaの出力ログ、問題のコード、package.jsonの依存関係を含めました。ラムダに展開するときに、誰かがこのような問題に遭遇しましたか?FrisbyテストをAWS LambdaにデプロイするときにJasmineが定義されていません

ラムダ出力ログ:

module initialization error: ReferenceError: jasmine is not defined 
at Object.<anonymous> (/var/task/testing/node_modules/frisby/lib/frisby.js:1125:1) 
at Module._compile (module.js:409:26) 
at Object.Module._extensions..js (module.js:416:10) 
at Module.load (module.js:343:32) 
at Function.Module._load (module.js:300:12) 
at Module.require (module.js:353:17) 
at require (internal/module.js:12:17) 
at Object.<anonymous> (/var/task/testing/index.js:1:76) 
at Module._compile (module.js:409:26) 
at Object.Module._extensions..js (module.js:416:10) 

テストファイル:

// This test checks to see if a blog post was made the previous day 

exports.handler = function index(event, context, callback){ 

var frisby = require("frisby"); 
var jasmine = require("jasmine"); 

var currentDate = new Date(); 
var yesterdayDate = new Date(currentDate.getTime() - 86400000).toISOString().split("T")[0]; 

// We will need to check yesterday's date against the latest blog post date, so this offset accounts for that. 
var dateOffset = new Date(currentDate.getTime() - 86400000); 
var offsetDayOfWeek = dateOffset.getDay(); 

frisby.create("will login successfully and return a JWT for future use") 
    .post("http://testurl.com/login", 
     { email: "[email protected]", password: "reallysecurepassword"}, 
     { json: true }) 
    .expectStatus(200) 
    .expectHeader("Content-Type", 
     "application/json; charset=utf-8") 
    .afterJSON(function (res) { 
     frisby.globalSetup({ 
      request: { 
       headers: { "x-access-token": res.jwt, 
        "Content-Type": "application/json; charset=utf-8" } 
      } 
     }); 

     // Test doesn't need to run on weekends 
     if(offsetDayOfWeek != 0 && offsetDayOfWeek != 6) { 
      frisby.create(site + ": Gets date from most recent blog post and checks against yesterday's date") 
       .get("http://testurl.com/get-blog-post") 
       .expectStatus(200) 
       .afterJSON(function (res) { 
        var postedDate = res[0].DatePosted.split("T")[0]; 
        if (postedDate != yesterdayDate) { 
         console.log(site + ": No new blogs posted."); 
         console.log("Last blog post date: " + postedDate); 
        } 
        expect(postedDate == yesterdayDate).toBe(true); 
       }) 
       .toss(); 
     } 
    }) 
    .toss(); 
}; 

package.jsonの依存関係:

"dependencies": { 
"body-parser": "~1.15.1", 
"cookie-parser": "~1.4.3", 
"debug": "~2.2.0", 
"express": "~4.13.4", 
"jade": "~1.11.0", 
"morgan": "~1.7.0", 
"serve-favicon": "~2.3.0", 
"frisby": "0.8.5", 
"jasmine-node": "1.14.5", 
"jasmine": "2.5.1" 

答えて

1

ラムダはあなたのための依存関係をインストールしません。完全なパッケージをアップロードすることを期待しています。つまり、すべての依存関係を含むスタンドアロンのzipアーカイブを作成することを意味します: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html

+0

私はその文書に従っており、現在zipアーカイブのすべての依存関係が含まれています。エラーは引き続き発生します。 – jab88

+0

@ jab88 npm installを実行しないで、ラムダ用に使用しているのと同じバージョンのノードを使用してzipアーカイブを解凍し、コードを実行しようとすると(独自のファイルシステム上にある場合)、実行されますか? –

+0

それはありません。私は常にpackage.jsonにスクリプトコマンドを設定してテストを実行していますが、うまくいきます。たとえば、 "jasmine-node path/to/file.spec.js"とすると、正常に動作します。 – jab88

関連する問題