Testing Lambda Functions

I’ve been trying to figure out a way to test my lambda functions (with something like Jest), and I’m having a tonne of trouble getting it set up and working. I’m a bit out of my depth, does anyone have any resources that would go over netlify functions testing, or even better, an example project that shows some ways to do it?


1 Like

I’m pretty sure there is no support for test automation yet. You can do manual testing by running netlify dev in a command line, and then netlify functions:invoke in another.

I’m a noob at serverless myself, but I would recommend for you to setup a server.js in whatever framework you prefer (express, hapi), use a translator like serverless-http, and then test against that server.

1 Like

You’d indeed have to do a test either on the already-deployed functions, or on a local copy you setup using netlify-lambda serve, @nonissue . The functions aren’t available until AFTER deploy for execution via our CDN.

You may be able to pick up some other associated advice from this article such as workflows for testing deploy previews before merging to production, or using multiple sites (1 for test, publishing later to prod): [Common Issue] Testing your Netlify builds

Here’s a repo I just created to test out a very simple Netlify Lambda function with React.

One thing to note, when I ran the terminal command netlify-lambda serve to deploy locally, it didn’t seem to work for me.

I added this in my package.json
start:lambda": "netlify-lambda serve functions

then ran this command and it worked beautifully.
npm run start:lambda

Give it a look and see if you can come up with anything!

Seems like it’s worked ok to judge from it working from package.json? netlify-lambda serve does no deploying, it just starts up your functions locally so you can access them on your computer without our infrastructure.

If it doesn’t run from the command line, we’d need more details on what might be going wrong like the actual error messages, you telling us how you have it installed for general usage, etc :slight_smile: