Skip to content

Commit 5da56ef

Browse files
docs: add comprehensive comments to AWS SDK v3 mock
- Explain why the mock exists (Jest module resolution issues) - Document ideal solution (upgrade Jest and ts-jest) - Specify conditions for safe removal - Provide testing instructions for future developers Co-Authored-By: hidetaka@digitalcube.jp <hidetaka@digitalcube.jp>
1 parent 6dc4924 commit 5da56ef

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

__tests__/__mocks__/@aws-sdk/client-cloudfront.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
/**
2+
* AWS SDK v3 CloudFront Client Mock
3+
*
4+
* WHY THIS MOCK EXISTS:
5+
* This mock was created to resolve Jest module resolution issues when migrating from AWS SDK v2 to v3.
6+
* The older Jest version (24.9.0) and ts-jest (24.0.2) cannot properly resolve Node.js built-in modules
7+
* like 'node:stream' that AWS SDK v3 uses internally, causing test failures with errors like:
8+
* "Cannot find module 'node:stream' from 'createBufferedReadable.js'"
9+
*
10+
* WHAT THE IDEAL SOLUTION SHOULD BE:
11+
* Instead of using this mock, the testing infrastructure should be updated to properly support
12+
* AWS SDK v3's module resolution patterns. This would involve:
13+
* 1. Upgrading Jest to a modern version (>=27.x) that supports Node.js built-in module resolution
14+
* 2. Upgrading ts-jest to a compatible version (>=27.x)
15+
* 3. Updating Node.js version in CI/CD to >=14.x (already done in package.json engines)
16+
* 4. Configuring Jest with proper ESM support if needed
17+
*
18+
* WHEN THIS FILE CAN BE REMOVED:
19+
* This mock can be safely deleted when ALL of the following conditions are met:
20+
* 1. Jest is upgraded to version 27.x or higher
21+
* 2. ts-jest is upgraded to a compatible version (27.x or higher)
22+
* 3. All tests pass without this mock file present
23+
* 4. The real AWS SDK v3 client can be imported and used in the test environment
24+
*
25+
* To test if this mock is still needed:
26+
* 1. Delete this file temporarily
27+
* 2. Run `yarn test`
28+
* 3. If tests pass, the mock is no longer needed
29+
* 4. If tests fail with module resolution errors, the mock is still required
30+
*
31+
* TECHNICAL DEBT:
32+
* This mock represents technical debt that should be addressed in a future dependency update cycle.
33+
* The mock provides basic functionality for testing but doesn't validate actual AWS SDK v3 behavior.
34+
*/
35+
136
module.exports = {
237
CloudFrontClient: class MockCloudFrontClient {
338
constructor(config) {

0 commit comments

Comments
 (0)