-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(plugin-catch-links): handle pathPrefix #9000
fix(plugin-catch-links): handle pathPrefix #9000
Conversation
* remove pathPrefix before calling navigate
Should we add some tests for pathPrefix scenarios? |
I thought of the same. But I have little to no experience in writing effective tests. So someone else must jump in. |
hey, I have experience writing tests, and also I need this PR to be merged so my site will work. lol ...but I have zero familiarity with the gatsby codebase and not sure exactly what it is that needs to be tested and where to put the tests. |
this whole class is so abstract that I'm not sure what it is really doing, but I see that the PR really only changes two functions inside one file. In the first chunk of changes you change It probably would be nice to have something like this:
|
Also this. Why are we passing "jest.fn()" to the method |
Actually I can't think of any situation where this PR makes things worse. I'm just reusing the regex that was created inside I wouldn't hold back the merge to wait for having tests. But it is a regression from #8289. And maybe tests would have helped to avoid this. Maybe merge and create an issue that this plugin needs more tests? |
Tried my very best™... This is a test that /pathPrefix/somePath href gets passed to hrefHandler as /somePath. This is what's currently right for |
Found what I wanted in gatsby-link tests |
nice @ahinrichs. I like your idea for the test, but how can you know from the test when window.history recieves an event? |
For the best test one really should somehow mock |
After some thinking of it I think the test is more of an integration test. Anyone mind if I move it there? |
This reverts commit 9e09c65.
This was just a try. The integration test worked here but failed in circle.ci. So I reverted. Actually I would like it a bit more as an integration test. The test failed for |
BTW, I always knew I will fall in love with writing tests the moment I start doing it :-) |
hrefHandler.mockImplementation((path) => { | ||
getNavigate()(path) | ||
expect(global.___navigate).toHaveBeenCalledWith( | ||
`${pathPrefix}/someSubPath`, |
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.
will this test actually fail if you revert changes to src/catch-links.js
? gotta say it's kind of confusing one to read ;)
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.
Just the one of them that simulates a build with --prefix-paths. That's the current state: module works in default builds but not in builds active prefix. But I wanted to catch the case too if any change would break the non prefix processing. As I said, these two are more of an integration test. I just don't know why I can't import "gatsby-link"
there.
And yes, it was confusing. I tend to leave otherones code untouched. And this was a straight combination of the existing tests and one of the gatsby-link tests. I did some refactor and added comments.
I created another PR #9051. With this circleci setup the test from commit 9e09c65 succeeds as an integration test (see #9050). Acutally we could still merge this PR in the actual state to get the plugin fixed and maybe--if I'm right with the circle ci setup--could change this PR tests the to integration tests in another step. |
@ahinrichs @pieh any ETA on getting this merged? This bug is causing some big headaches for me. |
@chasemccoy I will be testing this locally today (mostly because those tests are kinda confusing to me :P) |
Just on last change to I'm pretty confident, that this PR first and most important fixes the issue and second the tests at least do no harm. So I think it could be merged. The only thing--beside the new tests being a bit abstract--that is not ideal is the import from @pieh If you feel uncomfortable with the tests, would it help if we just merge the change in the regular code? |
No, we definitely want some kind of tests to catch potential regressions, I just need to dig a bit and see if it actually tests stuff ;) |
So it tests correctly, little verbose but better to have this in (+fix obviously) and try to figure out nicer tests (or some refactoring to not repeat a lot of code there). I just formatted code and skipped empty tests (we shouldn't report success on empty tests - this just gives false sense of coverage) |
Woohoo! Thank y'all for pushing this through, this will save me a lot of headaches. |
Actually - as an test beginner - I followed what was there. I first had a version where the test itself was in a function. But I assumed the code repetition in the tests before was for a reason. So I rewrote them to be two independent code blocks. In the end I discovered the e2e test setup and I think this is best placed there. But this will take some days. |
The empty tests where to give the output some kind of "story telling" impression. They were already there. But skip doesn't make much sense to me. I would then prefer to remove them (and maybe rephrase some of the other texts to stand on their own). |
Remove pathPrefix before calling navigate, closes #8907