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

VCR middleware #93

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

VCR middleware #93

wants to merge 5 commits into from

Conversation

MUTOgen
Copy link

@MUTOgen MUTOgen commented Dec 15, 2021

TBD

configuration.logger
end

def cassette_name
Copy link
Author

Choose a reason for hiding this comment

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

At this point, the most tricky part is cassette_name.
It should define cassette name based on some data from the request. But to do this right we need to be careful.
I'm not sure we could pass this name from Cypress, b/c BE request could be sent from anywhere (ex. graphql mutation in form submit)

Copy link
Author

Choose a reason for hiding this comment

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

For those projects using GraphQL it would be nice to detect it as well. Right now it considers /graphql as a path for endpoint, but it could be different.
Also, no guarantee, that the operation name will be a part of params

Copy link
Collaborator

@grantspeelman grantspeelman left a comment

Choose a reason for hiding this comment

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

Real awesome that you attempting to get this working 👍🏽

end

def run_with_cassette
VCR.use_cassette(cassette_name, { :record => configuration.vcr_record_mode }) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure 🤔 if this will work as it only wraps one request.

I think we actually need two endpoints, one to inject a cassette and one to eject a cassette.

Copy link
Author

Choose a reason for hiding this comment

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

@grantspeelman As the doc says https://www.rubydoc.info/gems/vcr/VCR:insert_cassette They recommend to use use_cassette instead of pair of insert-eject calls.
I guess use_cassette block should work the same way. The only change here is wrapping "normal" app flow.
Why do you think that insert/eject will perform differently?
I tested it on the real project under test env, and I've got a cassette written with 2 API calls inside.

Copy link
Collaborator

Choose a reason for hiding this comment

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

guess i just don't see how "use_cassette" approach will work, but maybe once you have a working example it will make sense 👍🏽

Copy link
Collaborator

Choose a reason for hiding this comment

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

I, it's making sense now.
Every single request it wrapped in it's own VCR cassette 👍🏽 and it's not really controlled from within Cypress.
This a is a good start and could help some teams around certain scenarios.
Maybe all that is still needed from Cypress is the ability to set a cassette prefix so that different scenarios can use different cassettes.

Copy link
Author

Choose a reason for hiding this comment

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

@grantspeelman I was thinking about some sort of temporary key-value storage, that users can setup in the config and populate values using appCommand during the test. This storage could be reseted the same way as we do it for DB before/after each test. In that perspective, we could pass the whole name for cassette, not just a prefix.
But maybe it's too much.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the whole name for cassette sounds like a good idea, also gets around the issue of having to try and generate a cassette name. Like that idea 👍🏽

@grantspeelman
Copy link
Collaborator

I have tackled this differently in #103

@justin808
Copy link
Member

@grantspeelman @MUTOgen closing, per #103.

@grantspeelman
Copy link
Collaborator

@justin808 #103 has to be used in a very specific way.
This only works when you start the Rails server with a single worker and single thread
This could be a viable alternative approach to the problem.

@justin808
Copy link
Member

@MUTOgen any new feedback on this one?

@MUTOgen
Copy link
Author

MUTOgen commented Apr 13, 2023

@justin808 Nothing specific to mention.
We use this version in Cypress tests, about 12 fixtures so far, primarily for online ordering and POS-related stuff.
AFAIR, we use multiple workers and threads. So, as @grantspeelman said, this might be a problem switching to the current gem implementation.

@justin808
Copy link
Member

@MUTOgen should we close this one?

@MUTOgen MUTOgen mentioned this pull request Jun 2, 2024
@MUTOgen
Copy link
Author

MUTOgen commented Sep 19, 2024

Let's keep this branch until client migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants