2016-09-08 4 views
1

bereitgestellt wird Ich versuche, einen Frisby.js-Test für AWS Lambda bereitzustellen, und erhalte kontinuierlich einen Referenzfehler. Ich habe das Ausgabeprotokoll von Lambda, den fraglichen Code und die Abhängigkeiten von package.json eingeschlossen. Ist bei der Bereitstellung bei Lambda schon einmal ein Problem aufgetreten?Jasmine ist nicht definiert, wenn Frisby-Test auf AWS Lambda

Lambda Ausgabeprotokoll:

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) 

Testdatei:

// 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 Abhängigkeiten:

"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" 

Antwort

1

Lambda installiert keine Abhängigkeiten für Sie. Es erwartet, dass Sie ein komplettes Paket hochladen. Das bedeutet, ein eigenständiges Zip-Archiv zu erstellen, das alle Ihre Abhängigkeiten enthält: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html

+0

Ich folgte dieser Dokumentation und bin derzeit alle Abhängigkeiten im Zip-Archiv enthalten. Der Fehler besteht weiterhin. – jab88

+0

@ jab88 Wenn Sie (separat in Ihrem eigenen Dateisystem) das Zip-Archiv extrahieren und versuchen, den Code mit derselben Version des Knotens auszuführen, den Sie für Lambda verwenden, ohne npm install auszuführen, wird es ausgeführt? –

+0

Es tut es nicht. Ich habe immer einen Skriptbefehl in meinem Paket.json gesetzt, um die Tests auszuführen, was gut funktioniert. Zum Beispiel "jasmine-node path/to/file.spec.js" und es läuft gut. – jab88

Verwandte Themen