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"
나는 그 문서를 읽고 현재 zip 아카이브의 모든 종속성을 포함하고 있습니다. 오류는 계속 발생합니다. – jab88
@ jab88 npm install을 실행하지 않고 람다 용 노드와 동일한 버전의 노드를 사용하여 zip 아카이브를 추출한 후 (별도로 파일 시스템에 저장하는 경우) 코드가 실행됩니까? –
그렇지 않습니다. 필자는 항상 패키지에 스크립트 명령을 설정했습니다. 테스트를 실행하려면 Json이 필요합니다. 예를 들어 "jasmine-node path/to/file.spec.js"와 같이 잘 실행됩니다. – jab88