-
Notifications
You must be signed in to change notification settings - Fork 439
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
[#804] OPTIONS request mocking support #841
Conversation
@@ -41,6 +41,8 @@ function createHandler({ verb, schema, serializerOrRegistry, path, rawHandler, o | |||
handler = new DeleteShorthandHandler(...args); | |||
} else if (verb === 'head') { | |||
handler = new HeadShorthandHandler(...args); | |||
} else if (verb === 'options') { | |||
handler = new GetShorthandHandler(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will rather require it's own handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this the FunctionHandler? I don't think shorthands make sense for options (or do they?)
Looks like Pretender supports OPTIONS. Regarding the shorthand handler, I agree it should have its own handler. Should there even be a shorthand for OPTIONS? What would the behavior be? Perhaps we can start with just adding the verb, and letting users use the function handler, e.g. this.options('/some/url', () => {
// normal function handler response
}); |
@samselikoff I developed a PR but it looks too similar to this one to add it to the repo. the sad part though is that neither seems to address allowing a passthrough of a OPTIONS & POST pairing. I'm also worried that maybe there's another part to this. My error: Seems to me the OPTIONS error isn't the primary error we're getting (at least in my case). It both says it is accepting a passthrough on the POST message (which follows the OPTIONs call) and then errors on the call. |
Ok, my last comment is a bit misleading. I had in earlier testing removed the "options" from the my
I'm back to my state from yesterday where it is fails on the "options" verb of the pretender object: If I look at the properties hanging off of that Pretender object I still see: There must be somewhere, that I haven't grokked yet where the |
Sorry to be so verbose but ... another update ... I switched the URL to a shortened version with wildcard characters:
this DOES work with this PR. 👍 The fully qualified URL ( |
Any chance we could merge this in? even with the fully qualified URL it is an improvement I think. |
I need to fix the style validation errors and see what else is failing. Either way you can use a git commit as the version in package.json if you just want to use it now :)
should do the trick. |
yup @riklaunim that's what I'm doing for now. glad you got to this 18 days before me. :) Thanks for the PR. One last note, working off your code base I noticed that even though my shortened URL works the passthrough call will fail when explicitly asking for 'options'. |
@riklaunim in fact I can't use yours yet as it fails on the same line as it was with base ember-cli-mirage. I had added one piece of defensive code into my clone of your PR:
Not sure whether this is worth having in the final code once everything is sorted but it does get this to working. |
Well, I was wondering why Pretender doesn't have my options and other changes visible. Turns out the installed dependency isn't the one that is being used (that's from a docker container):
node_modules/ember-cli-mirage/node_modules/pretender/pretender.js is used and not the version I install with my project as ./bower_components/pretender/pretender.js And Pretender seems to need this pretenderjs/pretender#166 to work. When I added that to the used pretender.js file - options do mock:
|
@riklaunim got a bit confused on your npm versus bower Pretender versions comment. I'd expect that Mirage is only using the npm version but I think that's what you're saying. Anyway, glad to see your PR on Pretender as I pretty sure it had to originate from there based on what we were seeing hanging off the Pretender object. Sounds like you've nailed that. |
installing ember-cli-mirage adds pretender to bower dependencies so I expected it will use it from bower_components, or if it wants it in node_modules then it will be in node_modules and not /node_modules/subfolder/node_modules/ -- which is pretty hidden (and it seems the version can't be changed by the package user). |
Oh yes that is confusing. @samselikoff is there a reason for this? |
@riklaunim I have forked your PR and pointed to your Pretender PR in the |
I can confirm though that a side effect does seem to be introduced. When I use this PR paired with the Pretender PR, I get no errors but Mirage does not use my Use Case 1: PR breaks scenarios So to be clear, use case 1a:
Use case 1b:
Use Case 2a:
Use Case 2b:
|
Pretender needs to merge the PR and push a new version, then this can use it and not a github commit (which would be pretty odd for a production release). |
yes that was my point 👍 I just did the fork for my immediate needs of seeing the two PR's together. |
the issue above does need addressing though; it would be a showstopper break for Mirage as it stands |
I use it with a big client panel demo and it works. If the are problems - test should show them too - when the verb problem is solved by newer pretender. |
so you're loading fixtures and/or factories to initialise your state? |
Mostly factories, few custom responses. I have some passthrough in another project, can check it too. |
would you let me know how that comes out? I have to shift to a different project for a day but if you're not seeing this behaviour I'll dig into mine again and see what else could be causing it. |
Tested, works. |
I'd love the tl;dr from your convo & experiments - what should our next steps be here? Are we blocked by the Pretender pr? |
At least some tests won't pass as Pretender.options does not exist. Then there may be some other options tests for fixing. It's also odd that node_modules/ember-cli-migrage/node_modules/.... subfolders shows up with Pretender - and not just the one in bower_components. I had to hand modify the Pretender code there instead of getting it from a git version in bower dependencies. I'll see about the Pretender additional tests, then see those tests here. |
Awesome, thank you. So we should hold off on this PR until those are sorted out, right? I appreciate your help :) |
Now fixture tests fail for some reason. |
@@ -75,7 +75,7 @@ | |||
"exists-sync": "0.0.3", | |||
"fake-xml-http-request": "^1.4.0", | |||
"faker": "3.0.1", | |||
"pretender": "^1.2.0", | |||
"pretender": "^1.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this change from this PR now? Once you do the tests will rerun and we can investigate any errors.
Let's get this puppy merged!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.2.0 doesn't have OPTIONS support. 1.3.0 is the first one to have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right but master
is now on 1.4 so if you remove this & rebase we should be set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, rebase to master. OK :)
You have some failures, are your tests passing locally? |
nop, as I commented above - few fixture related tests fail and I don't why. |
Can you help me with this? It seems like even adding options to the list - 14523a7#diff-3da129bcd0b0367d1b65b28e9ecc34c9 - causes the fixtures tests to fail. For some reason visit() return 404 - like if some mock or something stopped working. |
Closing due to inactivity |
Initial commit for OPTIONS request mocking. Does not work yet, throwing:
When options is trying to get mocked.