-
Notifications
You must be signed in to change notification settings - Fork 189
Description
Summary
Package builds (e.g. npm run build) only compile source code under src/. Test files under tests/ are never type-checked as part of the build, meaning type errors in tests can go unnoticed until runtime.
Every package already has a tests/tsconfig.json configured with noEmit: true that includes both source and test files — it just isn't invoked during the build.
Why is this needed?
Type errors in test files can silently accumulate and only surface at runtime. Including test compilation in the build ensures type errors are caught early and consistently.
Which area does this relate to?
All packages
Solution
For each package, make two changes:
1. Remove redundant source inclusion from tests/tsconfig.json
Source files imported by tests are already resolved via module resolution, so explicitly including ../src/**/* just duplicates work that the main build already does.
For packages that include ../../testing/src/setupEnv.ts (e.g. event-handler, logger, parameters):
-"include": ["../../testing/src/setupEnv.ts", "../src/**/*", "./**/*"]
+"include": ["../../testing/src/setupEnv.ts", "./**/*"]For all other packages:
-"include": ["../src/**/*", "./**/*"]
+"include": ["./**/*"]2. Add test type-checking to the build in package.json
The test type-check runs in parallel with the ESM and CJS builds (note the single &).
"scripts": {
...
+ "build:tests": "tsc --noEmit -p tests/tsconfig.json",
- "build": "npm run build:esm & npm run build:cjs",
+ "build": "npm run build:esm & npm run build:cjs & npm run build:tests",
...
}Apply to all packages.
3. Create missing tests/tsconfig.json for jmespath
The jmespath package is the only one missing this file. Create packages/jmespath/tests/tsconfig.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"noEmit": true
},
"include": ["./**/*"]
}Acknowledgment
- This request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.