nock 13.3.7 → 13.4.0
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 +39 -0
- package/lib/back.js +17 -0
- package/package.json +3 -3
- package/types/index.d.ts +16 -1
package/README.md
CHANGED
|
@@ -1497,6 +1497,45 @@ To set the mode call `nockBack.setMode(mode)` or run the tests with the `NOCK_BA
|
|
|
1497
1497
|
|
|
1498
1498
|
- lockdown: use recorded nocks, disables all http calls even when not nocked, doesn't record
|
|
1499
1499
|
|
|
1500
|
+
### Verifying recorded fixtures
|
|
1501
|
+
|
|
1502
|
+
Although you can certainly open the recorded JSON fixtures to manually verify requests recorded by nockBack - it's sometimes useful to put those expectations in your tests.
|
|
1503
|
+
|
|
1504
|
+
The `context.query` function can be used to return all of the interceptors that were recored in a given fixture.
|
|
1505
|
+
|
|
1506
|
+
By itself, this functions as a negative expectation - you can verify that certain calls do NOT happen in the fixture. Since `assertScopesFinished` can verify there are no _extra_ calls in a fixture - pairing the two methods allows you to verify the exact set of HTTP interactions recorded in the fixture. This is especially useful when re-recording for instance, a service that synchronizes via several HTTP calls to an external API.
|
|
1507
|
+
|
|
1508
|
+
**NB**: The list of fixtures is only available when reading. It will only be populated for nocks that are played back from fixtures.
|
|
1509
|
+
|
|
1510
|
+
#### Example
|
|
1511
|
+
|
|
1512
|
+
```js
|
|
1513
|
+
it('#synchronize - synchronize with the external API', async localState => {
|
|
1514
|
+
const { nockDone, context } = await back('http-interaction.json')
|
|
1515
|
+
|
|
1516
|
+
const syncronizer = new Synchronizer(localState)
|
|
1517
|
+
|
|
1518
|
+
sycnronizer.syncronize()
|
|
1519
|
+
|
|
1520
|
+
nockDone()
|
|
1521
|
+
|
|
1522
|
+
context.assertScopesFinished()
|
|
1523
|
+
|
|
1524
|
+
expect(context.query()).toEqual(
|
|
1525
|
+
expect.arrayContaining([
|
|
1526
|
+
expect.objectContaining({
|
|
1527
|
+
method: 'POST',
|
|
1528
|
+
path: '/create/thing',
|
|
1529
|
+
}),
|
|
1530
|
+
expect.objectContaining({
|
|
1531
|
+
method: 'POST',
|
|
1532
|
+
path: 'create/thing',
|
|
1533
|
+
}),
|
|
1534
|
+
]),
|
|
1535
|
+
)
|
|
1536
|
+
})
|
|
1537
|
+
```
|
|
1538
|
+
|
|
1500
1539
|
## Common issues
|
|
1501
1540
|
|
|
1502
1541
|
**"No match for response" when using got with error responses**
|
package/lib/back.js
CHANGED
|
@@ -240,6 +240,23 @@ function load(fixture, options) {
|
|
|
240
240
|
assertScopesFinished: function () {
|
|
241
241
|
assertScopes(this.scopes, fixture)
|
|
242
242
|
},
|
|
243
|
+
query: function () {
|
|
244
|
+
const nested = this.scopes.map(scope =>
|
|
245
|
+
scope.interceptors.map(interceptor => ({
|
|
246
|
+
method: interceptor.method,
|
|
247
|
+
uri: interceptor.uri,
|
|
248
|
+
basePath: interceptor.basePath,
|
|
249
|
+
path: interceptor.path,
|
|
250
|
+
queries: interceptor.queries,
|
|
251
|
+
counter: interceptor.counter,
|
|
252
|
+
body: interceptor.body,
|
|
253
|
+
statusCode: interceptor.statusCode,
|
|
254
|
+
optional: interceptor.optional,
|
|
255
|
+
})),
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
return [].concat.apply([], nested)
|
|
259
|
+
},
|
|
243
260
|
}
|
|
244
261
|
|
|
245
262
|
if (fixture && fixtureExists(fixture)) {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.
|
|
10
|
+
"version": "13.4.0",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@definitelytyped/dtslint": "^0.0.163",
|
|
31
|
-
"@sinonjs/fake-timers": "^
|
|
31
|
+
"@sinonjs/fake-timers": "^11.2.2",
|
|
32
32
|
"assert-rejects": "^1.0.0",
|
|
33
33
|
"chai": "^4.1.2",
|
|
34
34
|
"dirty-chai": "^2.0.1",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.js'",
|
|
60
60
|
"lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
|
|
61
61
|
"lint:ts": "dtslint --expectOnly types",
|
|
62
|
-
"test": "nyc --reporter=lcov --reporter=text mocha tests",
|
|
62
|
+
"test": "nyc --reporter=lcov --reporter=text mocha --recursive tests",
|
|
63
63
|
"test:coverage": "open coverage/lcov-report/index.html"
|
|
64
64
|
},
|
|
65
65
|
"license": "MIT",
|
package/types/index.d.ts
CHANGED
|
@@ -118,7 +118,9 @@ declare namespace nock {
|
|
|
118
118
|
filteringPath(regex: RegExp, replace: string): this
|
|
119
119
|
filteringPath(fn: (path: string) => string): this
|
|
120
120
|
filteringRequestBody(regex: RegExp, replace: string): this
|
|
121
|
-
filteringRequestBody(
|
|
121
|
+
filteringRequestBody(
|
|
122
|
+
fn: (body: string, recordedBody: string) => string,
|
|
123
|
+
): this
|
|
122
124
|
|
|
123
125
|
persist(flag?: boolean): this
|
|
124
126
|
replyContentLength(): this
|
|
@@ -265,10 +267,23 @@ declare namespace nock {
|
|
|
265
267
|
}>
|
|
266
268
|
}
|
|
267
269
|
|
|
270
|
+
interface InterceptorSurface {
|
|
271
|
+
method: string
|
|
272
|
+
uri: string
|
|
273
|
+
basePath: string
|
|
274
|
+
path: string
|
|
275
|
+
queries?: string
|
|
276
|
+
counter: number
|
|
277
|
+
body: string
|
|
278
|
+
statusCode: number
|
|
279
|
+
optional: boolean
|
|
280
|
+
}
|
|
281
|
+
|
|
268
282
|
interface BackContext {
|
|
269
283
|
isLoaded: boolean
|
|
270
284
|
scopes: Scope[]
|
|
271
285
|
assertScopesFinished(): void
|
|
286
|
+
query: InterceptorSurface[]
|
|
272
287
|
}
|
|
273
288
|
|
|
274
289
|
interface BackOptions {
|