test/

directory
v3.78.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: MIT

README

How to run, organize and write tests?

As framework deals with significant technical debt baggage many of currently configured tests do not resemble practice we want to follow in newly introduced tests.

Please follow this document as the only guideline, it also provides links to tests that serve as a good example to replicate

Unit tests

Tests are configured with Mocha test framework, and can be run with following command

npm test

All new tests should be configured with help of runServerless util - it's the only way to test functionality against completely initialized serverless instance, and it's the only scenario that reflects real world usage.

The runServerless util (inlined from @serverless/test) is configured at ./utils/run-serverless.js and supports two additional options (fixture and configExt), which provides out of a box setup to run Serverless instance against prepared fixture with eventually extended service configuration

As runServerless tests are expensive, it's good to ensure a minimal count of runServerless runs to test given scope of problems. Ideally with one service example we should cover most of the test cases we can (good example of such approach is ALB health check tests)

When creating a new test, it is an established practice to name the top-level describe after the path to the file, as shown in AWS Kafka tests.

Existing test examples:

Example of test files fully backed by runServerless:

If we're about to add new tests to an existing test file with tests written old way, then best is to create another describe block for new tests at the bottom (as it's done here)

Note: PR's which rewrite existing tests into new method are very welcome! (but, ideally each PR should cover single test file rewrite)

Package integration tests

Package integration tests live under test/integration-package and run in CI with:

npm run integration-test-run-package

Directories

Path Synopsis
fixtures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL