Skip to content

Commit

Permalink
fix: revert #2350 (Push persisted interceptors to the end instead of …
Browse files Browse the repository at this point in the history
…ignore on remove) (#2511)

This reverts commit 8aab603.  See #2500
  • Loading branch information
gr2m committed Aug 16, 2023
1 parent c8b0e4b commit fcea779
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -1005,7 +1005,7 @@ const scope = nock('http://example.com')
.reply(200, 'Persisting all the way')
```

Note that while a persisted scope will always intercept the requests, it is considered "done" after the first interception, and they are pushed to the bottom of the stack after consumption.
Note that while a persisted scope will always intercept the requests, it is considered "done" after the first interception.

If you want to stop persisting an individual persisted mock you can call `persist(false)`:

Expand Down
8 changes: 1 addition & 7 deletions lib/intercept.js
Expand Up @@ -110,7 +110,7 @@ function addInterceptor(key, interceptor, scope, scopeOptions, host) {
}

function remove(interceptor) {
if (--interceptor.counter > 0) {
if (interceptor.__nock_scope.shouldPersist() || --interceptor.counter > 0) {
return
}

Expand All @@ -122,12 +122,6 @@ function remove(interceptor) {
// matching instance. I'm also not sure why we couldn't delete _all_
// matching instances.
interceptors.some(function (thisInterceptor, i) {
if (interceptor.__nock_scope.shouldPersist()) {
return thisInterceptor === interceptor
? interceptors.push(interceptors.splice(i, 1)[0])
: false
}

return thisInterceptor === interceptor ? interceptors.splice(i, 1) : false
})
}
Expand Down
19 changes: 0 additions & 19 deletions tests/test_persist_optionally.js
Expand Up @@ -144,25 +144,6 @@ describe('`persist()`', () => {
expect(scope.isDone()).to.be.true()
})

it('persisted mocks go to the bottom of the stack after matching', async () => {
const scope = nock('http://example.test')
.persist()
.get('/')
.reply(200, 'Persisting all the way')

const specificTestScope = nock('http://example.test')
.get('/')
.reply(201, 'return different response once')

await got('http://example.test/')

expect(scope.isDone()).to.be.true()

await got('http://example.test/')

expect(specificTestScope.isDone()).to.be.true()
})

it('persisted mocks appear in `pendingMocks()`', async () => {
const scope = nock('http://example.test')
.get('/abc')
Expand Down

0 comments on commit fcea779

Please sign in to comment.