Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/backend/lambdas/projects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "ts-node --transpile-only dev-server.ts",
"build": "tsc",
"test": "jest",
"package": "npm run build && cd dist && zip -r ../lambda.zip . -x '*.map' 'dev-server.*' 'swagger-utils.*'"
},
"devDependencies": {
Expand All @@ -15,5 +16,7 @@
"typescript": "^5.4.5",
"js-yaml": "^4.1.0"
},
"dependencies": {}
"dependencies": {
"jest":"^30.2.0"
}
}
6 changes: 6 additions & 0 deletions apps/backend/lambdas/projects/test/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

test("health test 🌞", async () => {
let res = await fetch("http://localhost:3000/projects/health")
expect(res.status).toBe(200);
});

16 changes: 15 additions & 1 deletion apps/backend/lambdas/tools/lambda-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function templatePackageJson() {
"scripts": {
"dev": "ts-node --transpile-only dev-server.ts",
"build": "tsc",
"test": "jest",
"package": "npm run build && cd dist && zip -r ../lambda.zip . -x '*.map' 'dev-server.*' 'swagger-utils.*'"
},
"devDependencies": {
Expand All @@ -53,7 +54,9 @@ function templatePackageJson() {
"typescript": "^5.4.5",
"js-yaml": "^4.1.0"
},
"dependencies": {}
"dependencies": {
"jest":"^30.2.0"
}
}
`;
}
Expand Down Expand Up @@ -136,6 +139,14 @@ export function getSwaggerHtml(specUrl: string): string {
`;
}

function templateJestSetup(handlerName){
return `
test("health test 🌞", async () => {
let res = await fetch("http://localhost:3000/${handlerName}/health")
expect(res.status).toBe(200);
});
`}

function templateDevServer(handlerName) {
return `import { handler } from './handler';
import { loadOpenApiSpec, getSwaggerHtml } from './swagger-utils';
Expand Down Expand Up @@ -692,13 +703,16 @@ function cmdInitHandler(nameArg) {
const handlerPath = path.join(baseDir, 'handler.ts');
const swaggerUtilsPath = path.join(baseDir, 'swagger-utils.ts');
const devServerPath = path.join(baseDir, 'dev-server.ts');
fs.mkdirSync(path.join(baseDir, 'test'));
const testPath = path.join(baseDir, 'test/example.test.ts')

writeFileIfAbsent(pkgPath, templatePackageJson());
writeFileIfAbsent(tsconfigPath, templateTsconfig());
writeFileIfAbsent(openapiPath, templateOpenApiYaml(nameArg));
writeFileIfAbsent(swaggerUtilsPath, templateSwaggerUtils());
writeFileIfAbsent(devServerPath, templateDevServer(nameArg));
writeFileIfAbsent(handlerPath, templateHandlerTsClean());
writeFileIfAbsent(testPath, templateJestSetup(nameArg));

log(`Created handler at ${baseDir} `);
log('Next:');
Expand Down