1.4.2 • Published 4 years ago
stringify-body v1.4.2
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
testsdirectory.
// templates.js
module.export = {
myFile: {
someData: ["blah", "blah", "blah"],
},
};- Run
stringify-body, passing the path to the file containing your templates with the-por--pathflag. Optionally, you can define a custom output directory name with the-nor--nameflag, the default output directory istests
npx stringify-body -p templates.jsOutput:
- 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.jsonNested 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