我正在尝试将Frisby.js测试部署到AWS Lambda并不断收到引用错误。我已经包含了Lambda的输出日志,有问题的代码以及package.json依赖项。有没有人在部署到Lambda之前遇到过这样的问题?
Lambda输出日志:
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@gmail.com", 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"
答案 0 :(得分:1)
Lambda不会为您安装依赖项。它希望您上传完整的包。这意味着创建一个包含所有依赖项的独立zip存档: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html