http-snapshotter 0.6.0 → 0.6.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +14 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -96,7 +96,7 @@ let snapshotDirectory = null;
96
96
  * @typedef {import('diff').Change} DiffChange
97
97
  */
98
98
 
99
- const dynamodbHostNameRegex = /^(?:dynamodb|\d+\.ddb)\.([^.]+)\.amazonaws\.com$/;
99
+ const dynamodbHostNameRegex = /^(?:\d+\.)?(?:dynamodb|ddb)\.([^.]+)\.amazonaws\.com$/;
100
100
 
101
101
  /**
102
102
  * Stable JSON stringify with sorted keys for deterministic hashing
@@ -119,11 +119,18 @@ async function defaultSnapshotFileNameGenerator(request) {
119
119
  let filePrefix;
120
120
 
121
121
  const url = new URL(request.url);
122
- const matches = url.hostname.match(dynamodbHostNameRegex)
123
- if (matches) {
122
+ const dynamodbRegion = url.hostname.match(dynamodbHostNameRegex)?.[1] || '';
123
+ const normalizedRequestUrl = (() => {
124
+ if (!dynamodbRegion) return request.url;
125
+ const normalizedUrl = new URL(request.url);
126
+ normalizedUrl.hostname = `dynamodb.${dynamodbRegion}.amazonaws.com`;
127
+ return normalizedUrl.toString();
128
+ })();
129
+
130
+ if (dynamodbRegion) {
124
131
  filePrefix = [
125
132
  'dynamodb',
126
- matches[1], // e.g. eu-west-1
133
+ dynamodbRegion, // e.g. eu-west-1
127
134
  slugify(request.headers?.get?.('x-amz-target')?.split?.('.')?.pop?.() || ''), // e.g. get-item, put-item
128
135
  slugify(JSON.parse(await request.clone().text())?.TableName),
129
136
  ].filter(Boolean).join('-');
@@ -149,6 +156,9 @@ async function defaultSnapshotFileNameGenerator(request) {
149
156
  }
150
157
  return request.clone().text();
151
158
  }
159
+ if (key === 'url') {
160
+ return normalizedRequestUrl;
161
+ }
152
162
  //@ts-ignore
153
163
  return request[key];
154
164
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-snapshotter",
3
- "version": "0.6.0",
3
+ "version": "0.6.1-beta.2",
4
4
  "description": "Snapshot HTTP requests for tests (node.js)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",