npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

step-functions-tester

v0.0.5

Published

Write unit tests for your [aws step functions](https://aws.amazon.com/step-functions/?step-functions.sort-by=item.additionalFields.postDateTime&step-functions.sort-order=desc).

Downloads

4

Readme

step-functions-tester

Write unit tests for your aws step functions.

step-function-sample

Installation

yarn add step-functions-tester

Usage

With mocha:

const TestRunner = require('step-functions-tester')
const { expect } = require('chai')
let testRunner
describe('Step function tester', function () {
  this.timeout('30s')

  before('Set up test runner', async function () {
    testRunner = new TestRunner()
    await testRunner.setUp()
  })
  afterEach('Clean up', async function () {
    await testRunner.cleanUp()
  })
  after('Tear down', async function () {
    await testRunner.tearDown()
  })

  it('Step function test', async function () {
    // AWS Step Function definition
    const stepFunctionDefinition = {StartAt: 'FirstStep', States: {FirstStep: { /* ... */}}}

    const stepFunctionInput = {}

    // Keys are function names in the step function definition, values are arrays of calls
    const callStubs = {'arn:eu-west:111:mockLambda': [{result: 'First call result'}, {result: 'Second call result'}], 'arn:eu-west:111:mockLambda2': [{exception: {type: 'MyError', message: 'Some exception'}}]/*... */}
    
    const { executions } = await testRunner.run(callStubs, stepFunctionDefinition, stepFunctionInput)
    expect(executions).deep.equal(expectedExecutions)
  })
})

Why?

Short answer: infra is code and code should be tested.

Long answer: current AWS response is to write integration tests. However, it is often complicated to write integration tests for the error paths. Additionally, step functions are conceived to perform long running tasks. For example, to check an external resource every hour. We don't want to wait 4 hours to test what happens if the process always fails. This library allows to run tests on step functions where everything external to the step function is mocked.

I want to use this, but my step function is defined inside a yaml file

Use yaml-cfn

yarn add yaml-cfn
const parser = require('yaml-cfn')
const file = fs.readFileSync('yourPath.yml')
const parsedYaml = parser.yamlParse(file.toString())
const definition = parsedYaml.Resources/** Navigate to your definition **/

How is the sausage made?

Amazon exposes a docker image to run step functions locally amazon/aws-stepfunctions-local additionally using sam it is possible to run lambdas locally.

We save the stubs for your lambda functions in redis and return those to the current execution from a fake lambda.

Requirements

## important different versions, even patches can make the tester not run
pip3 install 'aws-sam-cli==1.23.0'
pip3 install docker-compose==1.25.4

Linux.

Gotchas

  • No current support for parallel.
  • Current implementation is quite global and it will run docker on the host network and use default redis port.
  • Not currently working on Mac, PRs are welcome