1

I'm attempting to deploy a Frisby.js test to AWS Lambda and continually get a reference error. I've included the output log from Lambda, the code in question, and the package.json dependencies. Has anybody encountered an issue like this before when deploying to Lambda?

Lambda output log:

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)

Test file:

// 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:

"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"
JacobB
  • 324
  • 1
  • 3
  • 10

1 Answers1

1

Lambda doesn't install dependencies for you. It expects you to upload a complete package. That means creating a standalone zip archive that includes all your dependencies: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html

Stephen Crosby
  • 1,157
  • 7
  • 19
  • I followed that documentation and am currently including all of the dependencies in the zip archive. The error still persists. – JacobB Sep 08 '16 at 17:28
  • @jab88 If you (separately on your own filesystem) extract the zip archive and attempt to run the code using the same version of node you're using for lambda, without running npm install, does it run? – Stephen Crosby Sep 08 '16 at 21:06
  • It does not. I've always had a script command set in my package.json to run the tests, which does work fine. For example "jasmine-node path/to/file.spec.js" and it runs fine. – JacobB Sep 08 '16 at 21:35
  • Any chance you can share this archive? or another simplified one that exhibits the problematic behavior? – Stephen Crosby Sep 08 '16 at 21:56
  • I went ahead and just re-wrote the tests using the Request module's HTTP calls. No problems and Lambda is liking it much more. I'm fairly certain it's due to Frisby.js needing Jasmine to be global. – JacobB Sep 09 '16 at 14:39