Skip to content

Commit 7628974

Browse files
ローカルテストができるようになった
1 parent df1fab3 commit 7628974

3 files changed

Lines changed: 202 additions & 2 deletions

File tree

hello_lambda_ts/package-lock.json

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hello_lambda_ts/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"description": "",
55
"main": "dist/index.js",
66
"scripts": {
7+
"start": "ts-node src/index.ts",
78
"build": "esbuild src/index.ts --bundle --minify --sourcemap --platform=node --target=node20 --outfile=dist/index.js",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"devDependencies": {
1112
"@types/aws-lambda": "^8.10.138",
1213
"@types/node": "^20.12.12",
1314
"esbuild": "^0.25.9",
15+
"ts-node": "^10.9.2",
1416
"typescript": "^5.4.5"
1517
}
16-
}
18+
}

hello_lambda_ts/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ export const handler: APIGatewayProxyHandler = async (event, context) => {
88
message: 'hello from TypeScript!',
99
}),
1010
};
11-
};
11+
};
12+
13+
// スクリプトが直接実行された場合にテストコードを呼び出す
14+
if (require.main === module) {
15+
console.log("--- Running Local Test ---");
16+
// @ts-ignore
17+
handler({}, {}).then(result => {
18+
console.log(JSON.parse(result.body));
19+
});
20+
console.log("--- End of Local Test ---");
21+
}

0 commit comments

Comments
 (0)