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.

Difficulty clearing one scope

See original GitHub issue

Context In a parallel test suite, it is not easy to clear a single nock scope if there are multiple initialized. Calling nock.cleanAll() is not an option per test file, since that would break other in progress test files. scope.complete() almost gets there, but I have some test suites that will not use all routes set up for a scope (I reuse and re-initialize the same scope for multiple test cases)

Simple example of the interface I am looking for:

// test1.js
describe('test1', () => {
  let scope
  before(async () => {
    scope = nock('http://google.com')
  })
  after(() => scope.cleanAll())

  it('test', () => {
    // call some http requests
  })
})
// test2.js
describe('test2', () => {
  let scope
  before(async () => {
    scope = nock('http://news.ycombinator.com')
  })
  after(() => scope.cleanAll())

  it('test', () => {
    // call some http requests
  })
})

Alternatives The alternative is to only run tests in serial.

Has the feature been requested before? concerns related to parallel testing have been brought up before: https://github.com/nock/nock/issues/541 https://github.com/nock/nock/issues/30

If the feature request is accepted, would you be willing to submit a PR? Yes, if help is provided

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
KrayzeeKevcommented, Mar 5, 2021

We often just want to remove a scope. So we do: scope.interceptors.forEach(nock.removeInterceptor) It works. But it’s bad. I shouldn’t be poking my nose in nock’s internal variables. A future release could break that and I’d have no right to complain. BUT the use-case seems compelling. You build a set of mocks on a single scope and you keep the scope. When you’re done (but other stuff may be nock’ed elsewhere) you want to remove your mocks. That seems like the primary use-case for saving the scope (other than augmenting it during the initial build). It’d be nice if there was a scope.remove() or scope.delete() and maybe even scope.suspend() and scope.resume(). I might make a small PR to add something that does that one line but was wondering if I’d missed something. Is there a reason not to expose a “delete”/“cancel” on a scope? Seems like a gimme to me.

1reaction
huancommented, Aug 4, 2021

I might make a small PR to add something that does that one line but was wondering if I’d missed something. Is there a reason not to expose a “delete”/“cancel” on a scope? Seems like a gimme to me.

I vote for scope.restore() because we have nock.restore(), and sinon has a sandbox it also uses restore().

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Troubleshoot Your Riflescope Zeroing Problems
Some shooters intentionally mount scopes this way to better clear the ejection port, knowing that the windage and elevation dials are then ...
Read more >
How To Clean A Riflescope | Leupold
Always start your cleaning by clearing away large particles of dust or debris from your optic using compressed air or a soft lens...
Read more >
Scope Cleaning and Repair - Infection Control Today
“Sooner is better,” he adds. “Scopes allowed to sit for more than 30 minutes without reprocessing are at very high risk for developing...
Read more >
Recon by Fire - Call of Duty: Modern Warfare 2 Wiki Guide - IGN
There is no one inside, so you can keep moving. Clearing the Main Building. advertisement. Follow Price and do as ...
Read more >
Post-Nasal Drip - Total ENT Care
Glands in your nose and throat continually produce mucus (one to two quarts a ... clearing, which usually produces little or no mucus,...
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