nock 13.1.0 → 13.1.4

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 CHANGED
@@ -3,7 +3,6 @@
3
3
  [![npm](https://img.shields.io/npm/v/nock.svg)][npmjs]
4
4
  [![Build Status](https://travis-ci.org/nock/nock.svg)][build]
5
5
  ![Coverage Status](http://img.shields.io/badge/coverage-100%25-brightgreen.svg)
6
- ![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=nock/nock)
7
6
  [![Backers on Open Collective](https://opencollective.com/nock/backers/badge.svg)](#backers)
8
7
  [![Sponsors on Open Collective](https://opencollective.com/nock/sponsors/badge.svg)](#sponsors)
9
8
 
@@ -1403,6 +1402,14 @@ return nockBack('promisedFixture.json').then(({ nockDone, context }) => {
1403
1402
  })
1404
1403
  ```
1405
1404
 
1405
+ Or, with async/await:
1406
+
1407
+ ```js
1408
+ const { nockDone, context } = await nockBack('promisedFixture.json')
1409
+ // your test code
1410
+ nockDone()
1411
+ ```
1412
+
1406
1413
  #### Options
1407
1414
 
1408
1415
  As an optional second parameter you can pass the following options
@@ -1566,10 +1573,29 @@ By participating in this project you agree to abide by its terms.
1566
1573
  Thanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)):
1567
1574
 
1568
1575
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
1569
- <!-- prettier-ignore -->
1570
- | [<img src="https://avatars1.githubusercontent.com/u/47910?v=4" width="100px;" alt="Pedro Teixeira"/><br /><sub><b>Pedro Teixeira</b></sub>](http://pgte.me)<br />[💻](https://github.com/nock/nock/commits?author=pgte "Code") [🚧](#maintenance-pgte "Maintenance") | [<img src="https://avatars3.githubusercontent.com/u/10771967?v=4" width="100px;" alt="n30n0v"/><br /><sub><b>n30n0v</b></sub>](https://github.com/n30n0v)<br />[💻](https://github.com/nock/nock/commits?author=n30n0v "Code") | [<img src="https://avatars3.githubusercontent.com/u/910753?v=4" width="100px;" alt="Richard Littauer"/><br /><sub><b>Richard Littauer</b></sub>](https://burntfen.com)<br />[🚧](#maintenance-RichardLitt "Maintenance") [💻](https://github.com/nock/nock/commits?author=RichardLitt "Code") [📝](#blog-RichardLitt "Blogposts") | [<img src="https://avatars1.githubusercontent.com/u/3731165?v=4" width="100px;" alt="Ian Walker-Sperber"/><br /><sub><b>Ian Walker-Sperber</b></sub>](http://ianwsperber.com)<br />[💻](https://github.com/nock/nock/commits?author=ianwsperber "Code") | [<img src="https://avatars2.githubusercontent.com/u/1505203?v=4" width="100px;" alt="Ivan Erceg"/><br /><sub><b>Ivan Erceg</b></sub>](http://ilovacha.com)<br />[💻](https://github.com/nock/nock/commits?author=ierceg "Code") [🚧](#maintenance-ierceg "Maintenance") | [<img src="https://avatars2.githubusercontent.com/u/1487036?v=4" width="100px;" alt="Paul Melnikow"/><br /><sub><b>Paul Melnikow</b></sub>](https://twitter.com/paulmelnikow)<br />[💻](https://github.com/nock/nock/commits?author=paulmelnikow "Code") [🚧](#maintenance-paulmelnikow "Maintenance") | [<img src="https://avatars3.githubusercontent.com/u/39992?v=4" width="100px;" alt="Gregor Martynus"/><br /><sub><b>Gregor Martynus</b></sub>](https://twitter.com/gr2m)<br />[💻](https://github.com/nock/nock/commits?author=gr2m "Code") [🚧](#maintenance-gr2m "Maintenance") [💼](#business-gr2m "Business development") [💵](#financial-gr2m "Financial") [📝](#blog-gr2m "Blogposts") |
1571
- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
1572
- | [<img src="https://avatars1.githubusercontent.com/u/6701030?v=4" width="100px;" alt="Hutson Betts"/><br /><sub><b>Hutson Betts</b></sub>](https://gitlab.com/hutson)<br />[💵](#financial-hutson "Financial") | [<img src="https://avatars2.githubusercontent.com/u/6105119?v=4" width="100px;" alt="Jonas Lilja"/><br /><sub><b>Jonas Lilja</b></sub>](http://lilja.io)<br />[💵](#financial-jlilja "Financial") [💻](https://github.com/nock/nock/commits?author=jlilja "Code") | [<img src="https://avatars0.githubusercontent.com/u/4446950?v=4" width="100px;" alt="Benjamin Ki"/><br /><sub><b>Benjamin Ki</b></sub>](https://github.com/benrki)<br />[💵](#financial-benrki "Financial") | [<img src="https://avatars2.githubusercontent.com/u/3250463?v=4" width="100px;" alt="Chad Fawcett"/><br /><sub><b>Chad Fawcett</b></sub>](http://chadf.ca)<br />[💵](#financial-chadfawcett "Financial") |
1576
+ <!-- prettier-ignore-start -->
1577
+ <!-- markdownlint-disable -->
1578
+ <table>
1579
+ <tr>
1580
+ <td align="center"><a href="http://pgte.me"><img src="https://avatars1.githubusercontent.com/u/47910?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pedro Teixeira</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=pgte" title="Code">💻</a> <a href="#maintenance-pgte" title="Maintenance">🚧</a></td>
1581
+ <td align="center"><a href="https://github.com/n30n0v"><img src="https://avatars3.githubusercontent.com/u/10771967?v=4?s=100" width="100px;" alt=""/><br /><sub><b>n30n0v</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=n30n0v" title="Code">💻</a></td>
1582
+ <td align="center"><a href="https://burntfen.com"><img src="https://avatars3.githubusercontent.com/u/910753?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Richard Littauer</b></sub></a><br /><a href="#maintenance-RichardLitt" title="Maintenance">🚧</a> <a href="https://github.com/nock/nock/commits?author=RichardLitt" title="Code">💻</a> <a href="#blog-RichardLitt" title="Blogposts">📝</a></td>
1583
+ <td align="center"><a href="http://ianwsperber.com"><img src="https://avatars1.githubusercontent.com/u/3731165?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ian Walker-Sperber</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=ianwsperber" title="Code">💻</a></td>
1584
+ <td align="center"><a href="http://ilovacha.com"><img src="https://avatars2.githubusercontent.com/u/1505203?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Erceg</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=ierceg" title="Code">💻</a> <a href="#maintenance-ierceg" title="Maintenance">🚧</a></td>
1585
+ <td align="center"><a href="https://twitter.com/paulmelnikow"><img src="https://avatars2.githubusercontent.com/u/1487036?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Melnikow</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=paulmelnikow" title="Code">💻</a> <a href="#maintenance-paulmelnikow" title="Maintenance">🚧</a></td>
1586
+ <td align="center"><a href="https://twitter.com/gr2m"><img src="https://avatars3.githubusercontent.com/u/39992?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gregor Martynus</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=gr2m" title="Code">💻</a> <a href="#maintenance-gr2m" title="Maintenance">🚧</a> <a href="#business-gr2m" title="Business development">💼</a> <a href="#financial-gr2m" title="Financial">💵</a> <a href="#blog-gr2m" title="Blogposts">📝</a></td>
1587
+ </tr>
1588
+ <tr>
1589
+ <td align="center"><a href="https://gitlab.com/hutson"><img src="https://avatars1.githubusercontent.com/u/6701030?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hutson Betts</b></sub></a><br /><a href="#financial-hutson" title="Financial">💵</a></td>
1590
+ <td align="center"><a href="http://lilja.io"><img src="https://avatars2.githubusercontent.com/u/6105119?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Lilja</b></sub></a><br /><a href="#financial-jlilja" title="Financial">💵</a> <a href="https://github.com/nock/nock/commits?author=jlilja" title="Code">💻</a></td>
1591
+ <td align="center"><a href="https://github.com/benrki"><img src="https://avatars0.githubusercontent.com/u/4446950?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Benjamin Ki</b></sub></a><br /><a href="#financial-benrki" title="Financial">💵</a></td>
1592
+ <td align="center"><a href="http://chadf.ca"><img src="https://avatars2.githubusercontent.com/u/3250463?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chad Fawcett</b></sub></a><br /><a href="#financial-chadfawcett" title="Financial">💵</a></td>
1593
+ <td align="center"><a href="http://www.laurencemyers.com.au"><img src="https://avatars.githubusercontent.com/u/6336048?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Laurence Dougal Myers</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=laurence-myers" title="Code">💻</a></td>
1594
+ </tr>
1595
+ </table>
1596
+
1597
+ <!-- markdownlint-restore -->
1598
+ <!-- prettier-ignore-end -->
1573
1599
 
1574
1600
  <!-- ALL-CONTRIBUTORS-LIST:END -->
1575
1601
 
@@ -153,7 +153,7 @@ class InterceptedRequestRouter {
153
153
  return false
154
154
  }
155
155
 
156
- if (!buffer || buffer.length === 0) {
156
+ if (!buffer) {
157
157
  return true
158
158
  }
159
159
 
@@ -442,13 +442,17 @@ module.exports = class Interceptor {
442
442
  markConsumed() {
443
443
  this.interceptionCounter++
444
444
 
445
- remove(this)
446
-
447
- if ((this.scope.shouldPersist() || this.counter > 0) && this.filePath) {
445
+ if (
446
+ (this.scope.shouldPersist() || this.counter > 0) &&
447
+ this.interceptionCounter > 1 &&
448
+ this.filePath
449
+ ) {
448
450
  this.body = fs.createReadStream(this.filePath)
449
451
  this.body.pause()
450
452
  }
451
453
 
454
+ remove(this)
455
+
452
456
  if (!this.scope.shouldPersist() && this.counter < 1) {
453
457
  this.scope.remove(this._key, this)
454
458
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "13.1.0",
10
+ "version": "13.1.4",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
package/types/index.d.ts CHANGED
@@ -52,7 +52,7 @@ declare namespace nock {
52
52
  | RegExp
53
53
  | DataMatcherArray
54
54
  | DataMatcherMap
55
- interface DataMatcherArray extends Array<DataMatcher> {}
55
+ interface DataMatcherArray extends ReadonlyArray<DataMatcher> {}
56
56
  interface DataMatcherMap {
57
57
  [key: string]: DataMatcher
58
58
  }
@@ -198,7 +198,7 @@ declare namespace nock {
198
198
  once(): this
199
199
  twice(): this
200
200
  thrice(): this
201
- optionally(): this
201
+ optionally(flag?: boolean): this
202
202
 
203
203
  delay(opts: number | { head?: number; body?: number }): this
204
204
  delayBody(timeMs: number): this