aws / aws/aws-sam-cli

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

Open
#4,811 2 comments 4 reactions 0 assignees View on GitHub
area/init type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.