http-snapshotter 0.6.0-beta.1 → 0.6.0-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.
- package/index.d.ts +43 -11
- package/index.js +2 -2
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
export type SnapshotFileInfo = {
|
|
2
|
+
absoluteFilePath: string;
|
|
3
|
+
/**
|
|
4
|
+
* in format filePrefix-hash.json`
|
|
5
|
+
*/
|
|
6
|
+
fileName: string;
|
|
7
|
+
filePrefix: string;
|
|
8
|
+
/**
|
|
9
|
+
* The string that would be hashed to be suffixed to the snapshot file name
|
|
10
|
+
*/
|
|
11
|
+
fileSuffixKey: string;
|
|
12
|
+
};
|
|
1
13
|
export type SnapshotText = {
|
|
2
14
|
fileSuffixKey: string;
|
|
3
15
|
requestType: 'json' | 'text';
|
|
@@ -33,7 +45,7 @@ export type SnapshotJson = {
|
|
|
33
45
|
};
|
|
34
46
|
};
|
|
35
47
|
export type Snapshot = SnapshotText | SnapshotJson;
|
|
36
|
-
export type
|
|
48
|
+
export type DiffChange = import('diff').Change;
|
|
37
49
|
export type ReadSnapshotReturnType = Promise<{
|
|
38
50
|
snapshot: Snapshot;
|
|
39
51
|
absoluteFilePath: string;
|
|
@@ -83,6 +95,36 @@ export function attachSnapshotFilenameGenerator(func: (req: Request) => Promise<
|
|
|
83
95
|
}>): void;
|
|
84
96
|
/** Reset snapshot filename generator to default */
|
|
85
97
|
export function resetSnapshotFilenameGenerator(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Default snapshot ignore rules - by default no requests are ignored
|
|
100
|
+
* @param {Request} _request
|
|
101
|
+
* @returns {boolean}
|
|
102
|
+
*/
|
|
103
|
+
export function defaultSnapshotIgnoreRules(_request: Request): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Attach snapshot ignore rules function
|
|
106
|
+
*
|
|
107
|
+
* Here's your opportunity to define custom rules for ignoring requests from being snapshotted.
|
|
108
|
+
* The function receives the Request object and should return true if the request should be ignored.
|
|
109
|
+
*
|
|
110
|
+
* IMPORTANT: Behavior varies by SNAPSHOT mode:
|
|
111
|
+
* - SNAPSHOT=update/append: Ignored requests make real network calls but don't create snapshots
|
|
112
|
+
* - SNAPSHOT=read: Ignored requests throw an error (tests shouldn't make real network calls)
|
|
113
|
+
*
|
|
114
|
+
* Use cases (not limited to):
|
|
115
|
+
* 1. Ignore requests with specific headers (e.g., x-debug-mode: no-snapshot)
|
|
116
|
+
* 2. Ignore requests to specific URLs or domains
|
|
117
|
+
* 3. Ignore requests with specific HTTP methods
|
|
118
|
+
* 4. Ignore requests based on request body content
|
|
119
|
+
*
|
|
120
|
+
* WARNING: Attaching a function on a per-test basis may not be concurrent safe. i.e. If your tests
|
|
121
|
+
* run sequentially, then it is safe. But if your test runner runs test suites concurrently,
|
|
122
|
+
* then it is better to attach a function only once ever.
|
|
123
|
+
* @param {(req: Request) => boolean} func
|
|
124
|
+
*/
|
|
125
|
+
export function attachSnapshotIgnoreRules(func: (req: Request) => boolean): void;
|
|
126
|
+
/** Reset snapshot ignore rules to default (no requests ignored) */
|
|
127
|
+
export function resetSnapshotIgnoreRules(): void;
|
|
86
128
|
/**
|
|
87
129
|
* Start the interceptor
|
|
88
130
|
* @param {object} opts
|
|
@@ -93,13 +135,3 @@ export function start({ snapshotDirectory: _snapshotDirectory, }?: {
|
|
|
93
135
|
}): void;
|
|
94
136
|
/** Stop the interceptor */
|
|
95
137
|
export function stop(): void;
|
|
96
|
-
/**
|
|
97
|
-
* @param {Request} request
|
|
98
|
-
*/
|
|
99
|
-
declare function getSnapshotFileInfo(request: Request): Promise<{
|
|
100
|
-
absoluteFilePath: string;
|
|
101
|
-
fileName: string;
|
|
102
|
-
filePrefix: string;
|
|
103
|
-
fileSuffixKey: string;
|
|
104
|
-
}>;
|
|
105
|
-
export {};
|
package/index.js
CHANGED
|
@@ -162,10 +162,10 @@ async function defaultSnapshotFileNameGenerator(request) {
|
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
* Default snapshot ignore rules - by default no requests are ignored
|
|
165
|
-
* @param {Request}
|
|
165
|
+
* @param {Request} _request
|
|
166
166
|
* @returns {boolean}
|
|
167
167
|
*/
|
|
168
|
-
function defaultSnapshotIgnoreRules(
|
|
168
|
+
function defaultSnapshotIgnoreRules(_request) {
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
171
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-snapshotter",
|
|
3
|
-
"version": "0.6.0-beta.
|
|
3
|
+
"version": "0.6.0-beta.2",
|
|
4
4
|
"description": "Snapshot HTTP requests for tests (node.js)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
8
9
|
"import": "./index.mjs",
|
|
9
|
-
"require": "./index.js"
|
|
10
|
-
"types": "./index.d.ts"
|
|
10
|
+
"require": "./index.js"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|