How to re-use some of your E2E tests as smoke tests

When creating automated tests for my serverless API backends, I create a suite of end-to-end (E2E) tests which mostly involve making requests to the deployed API endpoint (API Gateway or AppSync). When run as part of a CI/CD pipeline, these E2E tests run after deployment of a stack to a target AWS environment (test or staging). However, I usually don’t want to run all these E2E tests in production due to potential side effects that they may cause such as creation of data or the triggering of async message flows which may push data to third-party services.

However, there is still a risk of production-environment specific bugs creeping in, such as a new feature that requires a secret which is missing from the prod environment. So it can be nice to run a few sanity/smoke tests to verify that some key behaviours are as expected. These smoke test cases need to be low-impact (ideally readonly) so that you can be sure they won’t negatively impact on the production system.

If you’re authoring your tests with Jest, rather than writing separate smoke test cases, you can re-use existing E2E test cases as smoke tests using Jest’s —testNamePattern CLI option, and then tagging your test case titles (or the higher-level describe constructs) with ”[SMOKE]”, like so:

it('The user can fetch their profile with getMyProfile [SMOKE]')

Then in your package.json scripts section, you can add a command to run your smoke tests:


  "scripts": {
    "test:e2e": "jest ./tests/test-cases/e2e -c",
    "test:smoke": "jest ./tests/test-cases/e2e -c -t '^(.*(\\[SMOKE\\])).*$'"

Note that both commands reference the same test cases folder and config file, the only difference is the -t (testNamePattern) argument. Jest will flag any tests which don’t match this pattern as “skipped”. One thing to be aware of is that Jest will still execute any before* and after* handlers which are within scopes that match your provided regex pattern.

Join daily email list

I publish short emails like this on building software with serverless on a daily-ish basis. They’re casual, easy to digest, and sometimes thought-provoking. If daily is too much, you can also join my less frequent newsletter to get updates on new longer-form articles.

    View Emails Archive

    ☎️ Serverless Clarity Call

    Need quick guidance on a specific issue on your AWS serverless project? Or just wondering where to start with serverless?

    Book a call and ask me anything.

    Learn more >>

    🛫 Serverless Launchpad

    Ready to start building your new AWS serverless project but need help with getting everything setup?

    The Serverless Launchpad is a done-for-you DevOps service installed in under a week. You get a leading-practice multi-account AWS environment, a scaffolded codebase and architecture including the common AWS serverless services, isolated cloud environments for individual developers, automated delivery pipelines right through to production and much more. Everything is IaC, extensively documented and handed over to your developers.

    Learn more >>