stringify-body

1.4.2 • Public • Published

stringify-body

Description

Creates test json files suitable for serverless AWS lambda functions. Files will be created in a directory called "tests".

Usage

  1. In the root of your AWS lambda microservice, create a javascript file to create the templates for your test json files. Each module propery that is exported from this javascript file will be created as its own json file with the tests directory.
// templates.js

module.export = {
  myFile: {
    someData: ["blah", "blah", "blah"],
  },
};
  1. Run stringify-body, passing the path to the file containing your templates with the -p or --path flag. Optionally, you can define a custom output directory name with the -n or --name flag, the default output directory is tests
npx stringify-body -p templates.js

Output:

  1. You can now pass the path to your test json file to a serverless lambda function when invoking locally
sls invoke local --function myFunction --path tests/myFile.json

Nested Directories

For better organization, you may want to nest certain files together in a nested directory. This is acheivable by prefixing the exported module property with a $. Then, each property within that object will generate its own json file nested beneath the parent directory.

// templates.js

module.exports.$nestedDirectory = {
  nestedFile: {
    someData: ["blah", "blah", "blah"] 
  },
  secondNestedFile: {
    someData: ["bing", "bang", "pow"] 
  }
}

Output:

Notes

The directory containing your test json files can also be added to the exclude section of your serverless.yml file to reduce package size.

Using the shorthand -p for --path has issues per: https://github.com/serverless/serverless/issues/7871

Author Info

Name: Jonathan Hansen


Readme

Keywords

Package Sidebar

Install

npm i stringify-body

Weekly Downloads

14

Version

1.4.2

License

MIT

Unpacked Size

6.38 kB

Total Files

8

Last publish

Collaborators

  • feline-dis