aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.53k stars 1.17k forks source link

Feature request: Improved developer experience in VS Code with starter template for Typescript #4811

Open cshenrik opened 1 year ago

cshenrik commented 1 year ago

Describe your idea/feature/enhancement

I wish SAM CLI would make it easier to set up a new Typescript project that works out of the box with Visual Studio Code.

More specifically, I wish breakpoints in VS Code worked out of the box in Jest tests with the "Hello World Example TypeScript" starter template in SAM CLI.

Here's what I have tried:

SAM CLI v. 1.73 VSCode v. 1.75.1 Jest VSCode plugin v. 5.2.3.

  1. Run sam init. Choose "Hello World Example TypeScript" and nodejs18.x.
  2. Run npm install in the hello-world folder.
  3. When I open the included test-handler.test.ts, the editor marks describe, it, and expect as errors.
  4. Remove **/*.test.ts from exclude in tsconfig.json. Then the above errors are fixed.
  5. Set a breakpoint in the lambdaHandler function.
  6. Create a launch configuration as per VSCode's suggestion: "Debug Jest tests using vscode-jest".
  7. When I run it, it fails with Error: Cannot find module '/home/henrik/code/sam-jest-vscode/node_modules/.bin/jest'.
  8. Add /hello-world to the path to the Jest executable in the launch configuration.
  9. Now when I run it, it gives me : Error: Could not find a config file based on provided values: path: "/home/henrik/code/sam-jest-vscode" cwd: "/home/henrik/code/sam-jest-vscode"
  10. Add /hello-world to cwd in the launch configuration.
  11. Now I can run the test, but VS Code brings up the transpiled javascript file instead of the typescript file when it hits the breakpoint.
  12. I tried changing sourceMap to true in tsconfig.json, but it doesn't fix the problem.

Proposal

Add a Jest test launch configuration to the starter templates, so all of this just works out of the box. Also remove **/*.test.ts from exclude in tsconfig.json.

hnnasit commented 1 year ago

Hi @cshenrik thanks for the feature request. I will bring this up with the team about including default debug configuration in the sam init templates. As for the steps 11 and 12, this would be something to bring up with the AWS toolkit vscode. I found an issue that might be related to this https://github.com/aws/aws-toolkit-vscode/issues/3210.

cshenrik commented 1 year ago

Hi @hnnasit,

Thanks for replying.

I don't think this is related to the aws-toolkit plugin, as I'm not trying to run/debug the lambda function. I'm only trying to debug a Jest test.

Regards, Henrik