http-snapshotter 0.1.0 → 0.1.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/README.md +11 -7
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HTTP Snapshotter
|
|
2
2
|
|
|
3
|
-
Take snapshots of HTTP requests for purpose of tests.
|
|
3
|
+
Take snapshots of HTTP requests for purpose of tests (on node.js).
|
|
4
4
|
|
|
5
5
|
WARNING: This module isn't concurrent or thread safe yet. You can only use it on serial test runners like `tape`.
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
16
16
|
const __dirname = dirname(__filename);
|
|
17
17
|
const snapshotDirectory = resolve(__dirname, "http-snapshots");
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
start({ snapshotDirectory });
|
|
20
20
|
|
|
21
21
|
test("Latest XKCD comic (ESM)", async (t) => {
|
|
22
22
|
const res = await fetch("https://xkcd.com/info.0.json");
|
|
@@ -32,14 +32,18 @@ To create snapshots the first time run:
|
|
|
32
32
|
SNAPSHOT=update node test.js
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
You will see a file named `get-xkcd-com-info-0-arAlFb5gfcr9aCN.json` created in the `http-snapshots` directory.
|
|
36
|
-
|
|
37
|
-
e.g.
|
|
35
|
+
You will see a file named `get-xkcd-com-info-0-arAlFb5gfcr9aCN.json` created in the `http-snapshots` directory. Commit this directory to source control.
|
|
38
36
|
|
|
39
37
|
Then onwards running: `node test.js` or `SNAPSHOT=read node test.js` will ensure HTTP network calls are all read from a snapshot file.
|
|
40
|
-
|
|
38
|
+
In this mode, http-snapshotter will prevent any real HTTP calls from happening by failing the test (if it didn't have a snapshot file) and print out the request details and the snapshot file name it should have had.
|
|
39
|
+
|
|
40
|
+
There is also a `SNAPSHOT=ignore` option to neither read nor write from snapshot files and do real network requests instead. This could be useful while writing a new test.
|
|
41
|
+
|
|
42
|
+
Tip: When you do `SNAPSHOT=update` to create snapshots, run it against a single test, so you know what exact snapshots that one test created.
|
|
43
|
+
|
|
44
|
+
Finally after getting all your tests to use snapshots, run your test runner against all your tests and then take a look at `<snapshots directory>/unused-snapshots.log` file to see which snapshot files haven't been used by your final test suite. You can delete unused snapshot files.
|
|
41
45
|
|
|
42
|
-
## About snapshot files and its
|
|
46
|
+
## About snapshot files and its names
|
|
43
47
|
|
|
44
48
|
A snapshot file name unique identifies a request. By default it is a combination of HTTP method + URL + body that makes a request unique.
|
|
45
49
|
The hash of concatenated HTTP method + URL + body makes the file name suffix.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-snapshotter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Snapshot HTTP requests for tests (node.js)",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"exports": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
],
|
|
17
17
|
"author": "Munawwar",
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"homepage": "https://github.com/Munawwar/http-snapshotter",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/Munawwar/http-snapshotter/issues"
|
|
22
|
+
},
|
|
19
23
|
"dependencies": {
|
|
20
24
|
"@mswjs/interceptors": "^0.24.1",
|
|
21
25
|
"@sindresorhus/slugify": "^1.1.2"
|