{"library":"serverless-jest-plugin","title":"Serverless Jest Plugin","description":"serverless-jest-plugin integrates the Jest testing framework directly into the Serverless Framework workflow, enabling test-driven development for AWS Lambda functions and other Serverless components. The current stable version is 0.4.0, which dropped support for Node.js 8.10 and added compatibility for Node.js 14.x and Serverless Framework v3.x. Its release cadence appears to be infrequent, with significant gaps between major updates, focusing on compatibility with new Node.js and Serverless Framework versions. The plugin differentiates itself by providing `sls` commands to create functions with accompanying test templates, create tests for existing handlers, and run tests directly via `sls invoke test`. This streamlines the development process for Serverless applications by embedding testing commands within the familiar Serverless CLI.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install serverless-jest-plugin"],"cli":{"name":"sls","version":null}},"imports":["plugins:\n  - serverless-jest-plugin","custom:\n  jest:\n    collectCoverage: true","sls create function -f myFunction --handler functions/myFunction/index.handler"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"npm install --save-dev serverless-jest-plugin jest serverless\n\n# serverless.yml\n# ... other config ...\nplugins:\n  - serverless-jest-plugin\ncustom:\n  jest:\n    collectCoverage: true\n    testEnvironment: 'node'\n\n# Create a new Serverless service if you don't have one\n# sls create --template aws-nodejs --path my-service\n# cd my-service\n\n# Create a new function and its associated test file\nsls create function -f myFunc --handler functions/myFunc/index.handler --path tests\n\n# Example of generated file structure and content:\n# functions/myFunc/index.js\n// 'use strict';\n// module.exports.handler = async (event) => {\n//   return {\n//     statusCode: 200,\n//     body: JSON.stringify({\n//       message: 'Hello from myFunc!',\n//       input: event,\n//     }, null, 2),\n//   };\n// };\n\n# tests/myFunc.test.js\n// 'use strict';\n// const jestPlugin = require('serverless-jest-plugin');\n// const lambda = jestPlugin.getlambda({\n//   handler: 'functions/myFunc/index.handler'\n// });\n\n// describe('myFunc', () => {\n//   beforeAll((done) => { done(); });\n\n//   it('should return 200 with a greeting message', async () => {\n//     const event = {}; // Mock your event object\n//     const response = await lambda.handler(event);\n//     expect(response.statusCode).toBe(200);\n//     expect(JSON.parse(response.body).message).toEqual('Hello from myFunc!');\n//   });\n// });\n\n# Run all tests using the plugin's command\nsls invoke test\n\n# Run tests for a specific function\nsls invoke test -f myFunc","lang":"javascript","description":"This quickstart demonstrates how to install and configure the plugin, create a new Serverless function along with its test file, and execute tests using the provided `sls invoke test` command.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}