Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions SNAPSHOT_TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,92 @@ After adding the normalization to your tests, update your snapshots:
npm test -- -u
```

### 4. TypeScript Configuration for External Utilities

When referencing the normalize-template utility from outside your project directory, you may need to update your `tsconfig.json` file:

```json
{
"compilerOptions": {
// Other options...
"rootDir": "../..",
"baseUrl": ".",
"paths": {
"../../test-utils/*": ["../../test-utils/*"]
}
},
"exclude": [
"node_modules",
"cdk.out",
"lib"
],
"include": [
"**/*.ts",
"../../test-utils/**/*.ts"
]
}
```

Key changes:
- Set `rootDir` to include parent directories containing shared utilities
- Add `paths` mapping to resolve imports correctly
- Include the external utility files in the `include` section

This configuration allows TypeScript to compile files that reference utilities outside your project directory.

## What Gets Normalized

The utility currently normalizes:

1. **S3 Asset Keys**: Replaces asset hashes in S3Key properties
- Pattern with extension: `[64 hex chars].zip``NORMALIZED_ASSET_HASH.zip`
- Pattern without extension: `[64 hex chars]``NORMALIZED_ASSET_HASH`

2. **Docker Image Digests**: Replaces image digests
- Pattern: `sha256:[digest]``NORMALIZED_IMAGE_DIGEST`

## Adding New Test Files

When creating new test files that use snapshot testing:

1. Import the normalization utility
2. Apply it to your template before comparing with snapshots
3. Update your snapshots with the `-u` flag

## Extending the Utility

If you encounter other environment-specific values that need normalization, you can extend the utility at `typescript/test-utils/normalize-template.ts`.

Example of adding a new normalization rule:

```typescript
// Inside the normalizeValues function
if (key === 'NewPropertyToNormalize' && typeof obj[key] === 'string' && /pattern-to-match/.test(obj[key])) {
obj[key] = 'NORMALIZED_VALUE';
}
```

## Troubleshooting

If you're still seeing snapshot test failures:

1. **Check for new patterns**: There might be new types of asset hashes or environment-specific values that need normalization
2. **Verify imports**: Make sure you're importing and using the utility correctly
3. **Check snapshot updates**: Ensure you've updated your snapshots after adding normalization
4. **TypeScript configuration**: If you're getting compilation errors about files outside your project directory, check your tsconfig.json settings

## Best Practices

1. **Always normalize before snapshot comparison**: This ensures consistent results
2. **Update snapshots deliberately**: Only use the `-u` flag when you expect changes
3. **Review snapshot diffs**: When updating snapshots, review the changes to ensure they're expected
4. **Keep the utility updated**: As new patterns emerge, add them to the normalization utility

## Additional Resources

- [Jest Snapshot Testing Documentation](https://jestjs.io/docs/snapshot-testing)
- [AWS CDK Testing Documentation](https://docs.aws.amazon.com/cdk/v2/guide/testing.html)

## What Gets Normalized

The utility currently normalizes:
Expand Down
236 changes: 0 additions & 236 deletions typescript/ec2-instance-connect-endpoint/.eslintrc.json

This file was deleted.

27 changes: 0 additions & 27 deletions typescript/ec2-instance-connect-endpoint/.npmignore

This file was deleted.

1 change: 1 addition & 0 deletions typescript/ec2-instance-connect-endpoint/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
Loading
Loading