{"id":18376838,"url":"https://github.com/bbc/sfn-sim","last_synced_at":"2025-04-06T20:31:40.185Z","repository":{"id":242505967,"uuid":"804912864","full_name":"bbc/sfn-sim","owner":"bbc","description":"AWS Step Functions simulator for unit testing state machines","archived":false,"fork":false,"pushed_at":"2025-03-03T15:45:35.000Z","size":253,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T06:51:12.727Z","etag":null,"topics":["aws","ignorearchive","state-machine","step-functions","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-23T14:09:17.000Z","updated_at":"2025-03-03T15:45:38.000Z","dependencies_parsed_at":"2024-06-03T13:03:21.091Z","dependency_job_id":"e0c0111f-7bff-4c18-8e37-23fe4992e0eb","html_url":"https://github.com/bbc/sfn-sim","commit_stats":null,"previous_names":["bbc/sfn-sim"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fsfn-sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fsfn-sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fsfn-sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fsfn-sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbc","download_url":"https://codeload.github.com/bbc/sfn-sim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247547580,"owners_count":20956577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","ignorearchive","state-machine","step-functions","testing"],"created_at":"2024-11-06T00:25:02.261Z","updated_at":"2025-04-06T20:31:40.178Z","avatar_url":"https://github.com/bbc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sfn-sim: Step Function simulator\n\nThis library simulates the AWS Step Functions runtime to unit test state machines, a lightweight\nalternative to integration testing with LocalStack.\n\n\n## Installation\n\n```sh\nnpm install --save-dev sfn-sim\n```\n\n\n## Usage\n\nImport the `load` function, load your state machine, then execute with some input:\n\n```js\nimport { load } from 'sfn-sim';\n\nconst stateMachine = load(definition, resources, options);\n\nawait stateMachine.execute(input);\n```\n\nSee below for details on these parameters.\n\n\n## `definition`\n\nThis must be a JSON object which is the `Definition` property of a state machine, which contains the\n`StartAt` and `States` fields at its root.\n\nBy default, your definition will be validated using [statelint](https://github.com/wmfs/statelint);\nthis can be disabled with the `validateDefinition` option set to `false`.\n\nNote that CloudFormation functions and refs are not supported; you should replace these in your\ndefinition before loading it.\n\n\n## `resources`\n\nThis should be an array of objects which are AWS resources used by any `Task` steps in your state\nmachine. Each object must contain `service` and `name` fields, and additional fields depending on\nthe service.\n\nThe supported `service` values are listed below with their requirements, as well as an example using\nthe Lambda and S3 services.\n\n\n### `lambda`\n\nThis resource must contain a `function` field which must be a function. This will be executed as\nyour lambda handler.\n\n\n### `s3`\n\nThis resource must contain an `objects` field which must be an array. This can optionally be\npre-populated with objects, which must contain `key` and `body` fields.\n\n\n### `sns`\n\nThis resource must contain a `messages` field which must be an array.\n\n\n### `sqs`\n\nThis resource must contain a `messages` field which must be an array.\n\n\n### `stepFunctions`\n\nThis resource must contain a `stateMachine` field which must be a function. This will be executed as\nyour state machine.\n\n\n### Resources example\n\n```js\nconst definition = {\n  StartAt: 'CalculateSquare',\n  States: {\n    CalculateSquare: {\n      Type: 'Task',\n      Resource: 'arn:aws:lambda:::function:calculate-square',\n      InputPath: '$.value',\n      ResultPath: '$.value',\n      Next: 'SaveToS3',\n    },\n    SaveToS3: {\n      Type: 'Task',\n      Resource: 'arn:aws:states:::aws-sdk:s3:putObject',\n      Parameters: {\n        Bucket: 'squared-numbers',\n        'Key.$': '$.number',\n        'Body.$': '$.value',\n      },\n      End: true,\n    },\n  },\n};\n\nconst bucketObjects = [];\nconst resources = [\n  {\n    service: 'lambda',\n    name: 'calculate-square',\n    function: (x) =\u003e x * x,\n  },\n  {\n    service: 's3',\n    name: 'squared-numbers',\n    objects: bucketObjects,\n  },\n];\n\nconst stateMachine = load(definition, resources);\n\ntest('writes a squared number to S3', async () =\u003e {\n  await stateMachine.execute({\n    number: 'three',\n    value: 3,\n  });\n\n  expect(bucketObjects).toContainEqual({\n    key: 'three',\n    body: 9,\n  });\n});\n```\n\n\n## `options`\n\nThis should be an object which can be used to override the default configuration of the simulator.\n\n| Key | Description | Default |\n| --- | ----------- | ------- |\n| `validateDefinition` | Whether the provided definition should be validated on `load` | `true` |\n| `simulateWait` | Whether any `Wait` steps should wait in real-time, otherwise passing immediately | `false` |\n| `stateMachineName` | Identifier for the state machine, passed to the context object | `undefined` |\n| `executionName` | Identifier for the execution, passed to the context object | `undefined` |\n\n\n## Notes\n\nThis library supports most available features of Step Functions. Some functionality has not been\nimplemented yet, including:\n\n* Some AWS resources in `Task` steps\n* Some runtime error handling and data validation\n* Waiting for completion with task tokens\n* JSONata query language support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fsfn-sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbc%2Fsfn-sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fsfn-sim/lists"}