stringify-body
v1.4.2
Published
Creates test json files suitable for serverless AWS lambda functions.
Downloads
4
Readme
stringify-body
Description
Creates test json files suitable for serverless AWS lambda functions. Files will be created in a directory called "tests".
Usage
- 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"],
},
};
- 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 istests
npx stringify-body -p templates.js
Output:
- 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