Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
lambda-tdd
Advanced tools
Testing Framework for AWS Lambda. Very useful for integration testing as you can examine how your lambda function executes for certain input and specific environment variables. Tries to model the cloud execution as closely as possible.
context.getRemainingTimeInMillis()
)Example project using js-gardener and lambda-tdd can be found here.
To install run
$ npm install --save-dev lambda-tdd
const lambdaTester = require("lambda-tdd")({
cwd: __dirname,
verbose: process.argv.slice(2).indexOf("--debug") !== -1
});
describe("Testing Tester", () => {
lambdaTester.execute((process.argv.slice(2)
.find(e => e.startsWith("--filter=")) || "")
.substring(9));
});
You can pass an array of test files to the execute()
function or a regular expression pattern. By default tests are auto detected. If a pattern is passed in only matching tests are executed.
The example above allows for use of a --filter=REGEX
parameter to only execute specific tests.
{
"handler": "geoIp",
"env": {
"GOOGLE_PROJECT_ID": "123456789"
},
"event": {
"ip": "173.244.44.10"
},
"nock": [{
"to": {
"match": "^.*?\"http://ip-api\\.(com|ca):80\".*?$"
}
}],
"body": [{
"to.contain": "\"United States\""
}],
"timestamp": 1511072994,
"success": true,
"lambdaTimeout": 5000,
"timeout": 5000
}
More examples can be found here.
Type: string
Default: process.cwd()
Directory which other defaults are relative to.
Type string
Default: lambda-test
Name of this test runner for debug purposes.
Type boolean
Default: false
Display console output while running tests. Useful for debugging.
Type: string
Default: handler.js
Handler file containing the handler functions (specified in test).
Type: string
Default: __cassettes
Folder containing nock recordings.
Type: string
Default: env.yml
Specify yaml file containing environment variables. No existing environment variables can be overwritten.
Type: string
Default: ``
Folder containing test files.
Type: string
Required
The handler inside the handler file, i.e. if handler.js
contained
module.exports.returnEvent = (event, context, cb) => cb(null, event);
we would set this to returnEvent
.
Type object
Default: {}
Contains environment variables that are set for this test. Existing environment variables can be overwritten.
Type unix
Default: Unfrozen
Set unix timestamp that test executing will see. Time does not progress if this option is set.
Type integer
Default: Mocha Default Timeout
Set custom timeout in ms for lambda execution. Handy e.g. when recording nock requests.
Type object
Default: undefined
Event object that is passed to lambda handler.
Type integer
Default: 300000
Set initial lambda timeout in ms. Exposed in lambda function through context.getRemainingTimeInMillis()
.
The timeout is not enforced, but progresses as expected unless timestamp
option is used.
Type boolean
Required
True iff execution is expected to succeed, i.e. no error is passed into callback.
Type array
Default: []
Dynamic expect logic executed against the response string. More details on dynamic expect handling below.
Type array
Default: []
Dynamic expect logic executed against the error string. More details on dynamic expect handling below.
Type array
Default: []
Dynamic expect logic executed against the response.body string. More details on dynamic expect handling below.
Type array
Default: []
Dynamic expect logic executed against the console.log/info
and console.error/warn
output array. You can use errorLogs
and defaultLogs
to access them independently. More details on dynamic expect handling below.
Type array
Default: []
See logs
.
Type array
Default: []
See logs
.
Type array
Default: []
Dynamic expect logic executed against the nock recording. More details on dynamic expect handling below. Note that the nock recording must already exist for this check to evaluate correctly.
Important: If you are running into issues with replaying a cassette file you recorded previously, try editing the cassette and stripping information that might change. Also make sure cassette files never expose secret tokens or passwords!
Uses Chai Assertion Library syntax written as json. Lets assume we have an output array [1, 2]
we want to validate. We can write
expect([1, 2]).to.contain(1);
expect([1, 2]).to.contain(2);
as the following json
[{
"to.contain": 1
}, {
"to": {
"contain": 2
}
}]
Note that targets are either arrays or strings, but never objects (design limitation).
Currently nothing planned
FAQs
Test Framework for AWS Lambda
The npm package lambda-tdd receives a total of 480 weekly downloads. As such, lambda-tdd popularity was classified as not popular.
We found that lambda-tdd demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.