Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NockBack] Record "unmatched" requests only. #1235

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

guerrerocarlos
Copy link

@guerrerocarlos guerrerocarlos commented Oct 4, 2018

Reason for this PR

The record mode behavior does not meet the documentation:

record: "use recorded nocks, record new nocks"
/lib/back.js - line 309

Related Issue: #1115

This PR corrects it, by appending newly recorded nocks to existing ones.

Explanation of the code changes

Previously nock could wether intercept or record, but couldn't do both at the same time.

Now the record method is used a secondLayer during the intercept, effectively being able to do both at the same, so that when there are no interceptors for a requests, the recording mechanism takes it from there.

Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check the failing tests?

@@ -163,7 +163,6 @@ var record = {
recorder.clear();
nock.cleanAll();
nock.activate();
nock.disableNetConnect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know why that was here before, but this change seems unrelated to your changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually related, otherwise you have to manually enable it in order for the requests to go through and be seen by the recorder.

The record mode should not disableNetConnect by default. For that behavior the other modes can be used.

@stale
Copy link

stale bot commented Mar 14, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.

@stale stale bot added the stale label Mar 14, 2019
@gr2m gr2m added the pinned label Mar 14, 2019
@stale stale bot removed the stale label Mar 14, 2019
@villelahdenvuo
Copy link

Any updates on this PR? I would like to be able to use mocks with recorder, for example I have a hard-to-reproduce request that I have managed to record and I want to write tests based on that request, changing small details of it. Now I either have to disable mocks to record new ones and use something else to mock the first request, which is not optimal. It would be nice if I could use the existing nock mock and record any subsequent requests for additional tests.

@gr2m
Copy link
Member

gr2m commented Jun 7, 2019

You can install @guerrerocarlos’ fork for the time being

npm install guerrerocarlos/nock#fix/record-unmatched

@villelahdenvuo
Copy link

I tried using the fork, but for some reason the recorder would not log any requests, although they we correctly passed through. Oh well, I can use Jest to mock the first request, but this would be a nice feature in Nock for sure.

@nwalters512
Copy link

@guerrerocarlos are you still planning on seeing this through? If not, I'd still like to see this implemented and will work on this on my own fork.

@gr2m I see that one of the failing tests is "recording turns off nock interception (backward compatibility behavior)" - do you have any context on what this means? Would this feature then be a breaking change?

@gr2m
Copy link
Member

gr2m commented Oct 5, 2019

I don't think the feature would require a breaking change. If you'd like to send a new pull request based on the latest master, that'd be great.

@jrnail23
Copy link

+1 for this feature... I'm trying to avoid implementing something similar on my own, as I've got the same need.

@dkrantsberg
Copy link

@guerrerocarlos Any plans to finally merge this PR?
I also came across the need to be able to mock certain requests while still recording others.

@gr2m
Copy link
Member

gr2m commented Dec 19, 2019

This PR will need to be rebased on latest master before we can move forward. If anyone wants to give that a go and send a separate PR, we would be happy to review it

@simlu
Copy link

simlu commented Jun 20, 2020

For anyone looking, I'm working on this functionality for node-tdd in this pull request.

@gr2m
Pr is fully functional, but could probably be improved. Would love if you could take a peak at it

@ollelauribostrom
Copy link

This PR will need to be rebased on latest master before we can move forward. If anyone wants to give that a go and send a separate PR, we would be happy to review it

I took a stab at this in #2038 🙂

guerrerocarlos added a commit to guerrerocarlos/nock that referenced this pull request Jul 6, 2020
@guerrerocarlos
Copy link
Author

@gr2m @ollelauribostrom, rebased here: #2039

@gr2m gr2m added Recorder related to recording fixtures or Nock Back and removed pinned labels Nov 7, 2021
irfan798 pushed a commit to irfan798/nock that referenced this pull request Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Recorder related to recording fixtures or Nock Back
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants