Conventional tests for your JS and TS.
There is only one rule so far and it's incomplete.
- Make sure AWS Lambda event handler input parameters don't escape the file they are defined in.
The following is considered an AWS Lambda handlers if all are true:
- Must be an export of a root source file (file not imported by another source file)
- Looks like one of the following:
- has JSDoc annotation matching an AWS event type e.g.
AWSLambda.DynamoDBStreamEvent
for the first param - has three params (event, context, callback) in that order and with that name
- has two params (event, context) is async
- has one param (event) is async and the function name is called "handler"
- has JSDoc annotation matching an AWS event type e.g.
- AWSLambda.ALBEvent
- AWSLambda.APIGatewayEvent
- AWSLambda.CloudFrontEvent
- AWSLambda.CloudWatchLogsEvent
- AWSLambda.CognitoUserPoolEvent
- AWSLambda.DynamoDBStreamEvent
- AWSLambda.KinesisStreamEvent
- AWSLambda.S3CreateEvent
- AWSLambda.S3Event
- AWSLambda.SNSEvent
- AWSLambda.SQSEvent
You'll need entente or ts-morph for this.
const { createProject } = require("entente");
createProject('./src/index.js');
checkProject(project)
const compilerOptions = {
allowJs: true,
checkJs: true,
noEmit: true,
resolveJsonModule: true,
};
const project = new Project({ compilerOptions });
project.resolveSourceFileDependencies();
project.addSourceFilesAtPaths(['./src/**/*.js', "!./src/**/*.spec.js"]);
checkProject(project)
- Make it work with commonjs modules. ts-morph is having a hard time here.
- Make sure it doesn't escape through a renamed reference.
- express request/response objects are not passed around
- GraphQL response objects are converted to view models before use
- types defined externally to the project can only be passed out of the file where they are first used (don't couple yourself to external objects) -- but you can define them anywhere
- types defined externally to the project can only be used in leaf (files that do not reference other source files) or entrypoint files (files not referened by other source files)