question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In 11.0.0-beta.30, when no body is provided `.filteringRequestBody()` no longer has any effect

See original GitHub issue

I have a test case that failed in IcedFrisby in 11.0.0-beta.30. I’ve confirmed that in 11.0.0-beta.29 the test case passes which means this changed in #1632.

I am pretty sure this is a bug, though it’s a slightly awkward / broad test case which I haven’t yet narrowed down to a specific behavior of nock.

it('should fail with the last error when every retry errors out', async function() {
  const retryCount = 4
  let actualRequestCount = 0

  const scope = nock('http://example.test')
    .filteringRequestBody(body => {
      actualRequestCount += 1
      return body
    })
    .get('/just-dont-come-back-2')
    .delayBody(50)
    .times(retryCount + 1)
    .replyWithError(
      Error('This could be a network error or an internal error')
    )

  await expect(
    frisby
      .create(this.test.title)
      .get('http://example.test/just-dont-come-back-2')
      .retry(retryCount, 0)
      .run()
  ).to.be.rejectedWith(
    Error,
    'This could be a network error or an internal error'
  )

  expect(actualRequestCount).to.equal(retryCount + 1)
  scope.done()
})

In 11.0.0-beta.29, the filteringRequestBody callback runs 5 times and the expect(actualRequestCount).to.equal(retryCount + 1) assertion passes. (expect(5).to.equal(5)).

In 11.0.0-beta.30, the filteringRequestBody callback does not run at all, and the assertion fails (expect(0).to.equal(5)).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Aug 6, 2019

The ‘replied’ event does not currently fire when using replyWithError. As for the “should it?”… the current behavior of that event is that it denotes when the IncomingMessage has been passed all the data chunks and is “complete”. With that mindset, it make sense that replyWithError does not emit the replied event as the error is fired on the request object and the response is never provided any data. I would probably vote to leave that event as-is. An event could be added that denotes an Interceptor was consumed, but I think that would end up being 1:1 with the existing request event.

0reactions
paulmelnikowcommented, Aug 6, 2019

Seems reasonable! Probably it’s a good idea to clarify in the API docs when those events fire, though we can save that for another day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weekly Digest (28 July, 2019 - 4 August, 2019) · Issue #1658
#1652 In 11.0.0-beta.30, when no body is provided .filteringRequestBody() no longer has any effect, by paulmelnikow. It received 5 comments.
Read more >
nock - npm
You need to run nock.activate() to re-activate the http interceptor. Without re-activation, nock will not intercept any calls. Activating.
Read more >
Request body not making it to middleware for joi validation
I have a middleware that validates my user object as users are created and also when they make edits. It worked not too...
Read more >
nock | Yarn - Package Manager
This is no longer allowed. In Nock 12 and later, either call .reply() with a status code and a function that returns the...
Read more >
How to use the nock.back function in nock
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... (err: any, res: any, body:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found