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.
npm install serverless-jest-pluginVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Node.js environment to version 14.x or later. Ensure your `serverless.yml` specifies a compatible runtime for your Lambda functions.
Ensure your Serverless Framework CLI version is compatible with the plugin version. For `serverless-jest-plugin` v0.4.0, use Serverless Framework v3.x. If experiencing issues, align your plugin and framework versions based on release notes.
Review your `serverless.yml` and ensure all Jest-specific configurations (e.g., `collectCoverage`, `testEnvironment`) are nested directly under `custom.jest`.
Run `npm install --save-dev serverless-jest-plugin` and then add `- serverless-jest-plugin` to the `plugins` section in your `serverless.yml` file.
Verify the `--handler` argument used with `sls create function` is correct. Inspect the generated test file (e.g., `test/myFunc.test.js`) and ensure the `jestPlugin.getlambda({ handler: '...' })` path matches your function's handler export.Ensure `serverless-jest-plugin` is correctly installed via `npm install --save-dev serverless-jest-plugin` and listed in the `plugins` array of your `serverless.yml` file. Restart your terminal if necessary to pick up changes.