Skip to content

Commit bfd6bbf

Browse files
authored
Fix projen (#1164)
* Merged * Fix: Jest to run locally * Fix: Update normalized testing * Fix: Rootdir path * doc:Update snapshot testing for tsconfig changes * Chore: Update cdk libs
1 parent 4fcda0f commit bfd6bbf

File tree

12 files changed

+371
-481
lines changed

12 files changed

+371
-481
lines changed

SNAPSHOT_TESTING.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,92 @@ After adding the normalization to your tests, update your snapshots:
5353
npm test -- -u
5454
```
5555

56+
### 4. TypeScript Configuration for External Utilities
57+
58+
When referencing the normalize-template utility from outside your project directory, you may need to update your `tsconfig.json` file:
59+
60+
```json
61+
{
62+
"compilerOptions": {
63+
// Other options...
64+
"rootDir": "../..",
65+
"baseUrl": ".",
66+
"paths": {
67+
"../../test-utils/*": ["../../test-utils/*"]
68+
}
69+
},
70+
"exclude": [
71+
"node_modules",
72+
"cdk.out",
73+
"lib"
74+
],
75+
"include": [
76+
"**/*.ts",
77+
"../../test-utils/**/*.ts"
78+
]
79+
}
80+
```
81+
82+
Key changes:
83+
- Set `rootDir` to include parent directories containing shared utilities
84+
- Add `paths` mapping to resolve imports correctly
85+
- Include the external utility files in the `include` section
86+
87+
This configuration allows TypeScript to compile files that reference utilities outside your project directory.
88+
89+
## What Gets Normalized
90+
91+
The utility currently normalizes:
92+
93+
1. **S3 Asset Keys**: Replaces asset hashes in S3Key properties
94+
- Pattern with extension: `[64 hex chars].zip``NORMALIZED_ASSET_HASH.zip`
95+
- Pattern without extension: `[64 hex chars]``NORMALIZED_ASSET_HASH`
96+
97+
2. **Docker Image Digests**: Replaces image digests
98+
- Pattern: `sha256:[digest]``NORMALIZED_IMAGE_DIGEST`
99+
100+
## Adding New Test Files
101+
102+
When creating new test files that use snapshot testing:
103+
104+
1. Import the normalization utility
105+
2. Apply it to your template before comparing with snapshots
106+
3. Update your snapshots with the `-u` flag
107+
108+
## Extending the Utility
109+
110+
If you encounter other environment-specific values that need normalization, you can extend the utility at `typescript/test-utils/normalize-template.ts`.
111+
112+
Example of adding a new normalization rule:
113+
114+
```typescript
115+
// Inside the normalizeValues function
116+
if (key === 'NewPropertyToNormalize' && typeof obj[key] === 'string' && /pattern-to-match/.test(obj[key])) {
117+
obj[key] = 'NORMALIZED_VALUE';
118+
}
119+
```
120+
121+
## Troubleshooting
122+
123+
If you're still seeing snapshot test failures:
124+
125+
1. **Check for new patterns**: There might be new types of asset hashes or environment-specific values that need normalization
126+
2. **Verify imports**: Make sure you're importing and using the utility correctly
127+
3. **Check snapshot updates**: Ensure you've updated your snapshots after adding normalization
128+
4. **TypeScript configuration**: If you're getting compilation errors about files outside your project directory, check your tsconfig.json settings
129+
130+
## Best Practices
131+
132+
1. **Always normalize before snapshot comparison**: This ensures consistent results
133+
2. **Update snapshots deliberately**: Only use the `-u` flag when you expect changes
134+
3. **Review snapshot diffs**: When updating snapshots, review the changes to ensure they're expected
135+
4. **Keep the utility updated**: As new patterns emerge, add them to the normalization utility
136+
137+
## Additional Resources
138+
139+
- [Jest Snapshot Testing Documentation](https://jestjs.io/docs/snapshot-testing)
140+
- [AWS CDK Testing Documentation](https://docs.aws.amazon.com/cdk/v2/guide/testing.html)
141+
56142
## What Gets Normalized
57143

58144
The utility currently normalizes:

typescript/ec2-instance-connect-endpoint/.eslintrc.json

Lines changed: 0 additions & 236 deletions
This file was deleted.

typescript/ec2-instance-connect-endpoint/.npmignore

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node-linker=hoisted

0 commit comments

Comments
 (0)