Skip to content

test: add post-deploy template assertion suite for integration fixtures #748

@VirtueMe

Description

@VirtueMe

Background

The current integration test suite (added in #745) deploys all fixtures to LocalStack and verifies that deployment succeeds. This catches runtime errors — malformed IAM policies, invalid state machine definitions, etc.

However, some bugs produce structurally incorrect CloudFormation templates that LocalStack accepts without error but that cause silent failures in production. Two examples already fixed:

Proposed solution

After sls compose deploy runs (which internally packages each fixture and writes the compiled template to .serverless/cloudformation-template-update-stack.json), run a second step that executes verify.test.js files co-located with each fixture:

fixtures/
  notifications/
    serverless.yml
    verify.test.js   ← asserts exactly one SNS TopicPolicy per topic, etc.
  circular-dependency/
    serverless.yml
    verify.test.js   ← asserts no { Ref: Lambda } in IAM policy resources, etc.
  basic-state-machine/
    serverless.yml
    # no verify.test.js needed — deploy success is sufficient

Runner added to the CI workflow after the deploy step:

npx mocha fixtures/**/verify.test.js

The verify.test.js files use the same Mocha + Chai setup as the rest of the test suite and read the already-generated .serverless/cloudformation-template-update-stack.json for their assertions.

Why this matters

This closes the gap between "deploys without error" and "generates a correct template". It also gives future contributors a clear pattern for adding template-level assertions when fixing compilation bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions