-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Adds optional configuration snapshotTag
#5838
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5838 +/- ##
==========================================
- Coverage 64.12% 64.09% -0.04%
==========================================
Files 217 217
Lines 8332 8341 +9
Branches 4 4
==========================================
+ Hits 5343 5346 +3
- Misses 2988 2994 +6
Partials 1 1
Continue to review full report at Codecov.
|
@cpojer what is your stance on this option these days? |
I’m not a fan of thi. I think to support platform extensions we should add custom support in Jest itself to work properly. There is an old open issue somewhere about making platform extensions first class throughout Jest with a “jest.setPlatform” or “jest.forEachPlatform” function. That one could append the .ios or .android to snapshot files. Note that we also need a reverse lookup function from snapshot file to test file, which we could bake into Jest as well without having to expose anything to users. |
@cpojer Thanks for the input, let me break it into parts to better advance the talk:
Still, I'm open to help with both. I must admit I'm not a Jest Master, but helping is a great way to learn. |
As with every new configuration setting, I think the question should be not "why not to add", but "why to add" the configuration setting.
|
@ArtemGovorov Well... thinking like this... and in the work needed so far... Indeed the point is |
@cpojer I did a small test locally with the platform thing. It worked great indeed, but I'm not sure if the way I implemented it is actually good. Based on my tests the best would be to get
or
add and, finally, replace the As I said, it works but doesn't look that good. You mentioned If you think it is an acceptable implementation, let me know so I can make some more tests on it. All this test also made me think on a |
@ArtemGovorov @cpojer @SimenB Sorry guys to mark you on this. Thanks in advance |
@mjesun @rickhanlonii thoughts? |
I don't think this works with the reverse lookups. I have previously voiced my concerns. I don't think this is something I'm happy to add to Jest at this time, I see little upside of the complexity. |
@cpojer @SimenB This week I took some time to go deep on that. And just like @cpojer mentioned it sounds WAY easier than it is. The main issue is indeed the places where the snapshot extensions are searched. One great example is https://github.com/facebook/jest/blob/3341d162715679a596bfbbec8a7a5c5676c5f1b7/packages/jest-snapshot/src/index.js#L26 which uses the To solve it, in the way that this PR suggests, any reference to the I also tried to set a name to the snapshot but it ended causing conflicts anyways (as I use 2 I still looking for a way to use only one written test to all platforms tested ( As a last option, I'm about to try some sort of loop that "overrides" the Being so, if the team is up to take a look at the function solution (which I mean I would develop it and after that, we would discuss if it sounds good or not) I would work a bit more. Regards, |
I'm feel the same as @cpojer, so the preferable route for me would be to do this in a custom matcher as a separate lib. If there are limitations to doing that, let's build tools that enable what the custom matcher would need |
@rickhanlonii As far as I tested, the problems are:
A B C
Right now it seems that the When you described the the custom matcher, I feel that the changes required in item That's why I proposed try this function (now called ps: Sorry if I insist in a bad idea, I'm trying to figure out a solution based on your feedback. And thanks for the patience 👍 |
I think I prefer option C with a |
@cpojer I remember you mentioned it. I'll take a look on how it works and how tie them together. But any suggestion is welcome. EDIT: Does
|
It does not exist, it would be a new thing |
@SimenB in this case, is my assumption right? Should I create it or you guys plan to add it in a near future? |
Go for it 🙂 |
Ok, in this case I'll break it into pieces. I'm just wondering if I also split them in smaller
|
@cpojer I spent some time doing some tests to plan the steps but I found out a lot of limitations. For this kind of change, I'm always in favor of doing the smallest change possible. With that in mind, follows the challenges I found and ideas I had: I just found out that It seems to me that we could even move the first block to be just before the line 162, but we still have the problem that we create the Other than that, the Basically, it seems to me that this is the place we would have to patch (still checking how it would work on Circus) but I can't find a good solution to be aware of the multiple platform tests without parsing the file ( I ignored the issue above, and tried to simulate the In short:
If it isn't acceptable to have a default identifier in test's name, or path, the changes are big and complex, hitting strong the @ArtemGovorov's concern about moving parts. Maybe there's a way which I missed, but, even wanting a lot this feature, I'm getting skeptical. (if confusing, let me know) EDIT: I tried to use two Jest Projects pointing to the same tests and tried to use the |
I don't think we need to do static analysis here. We can change behavior at runtime and adjust everything to be configurable, like This may be a larger change, yes, but that should be ok. |
@cpojer Makes sense and actually sounds smaller than expected. Thanks for this input! If I got it right Am I right? |
@sidferreira this is exactly what I'm doing and exactly why I'm following this with much interest.
If this solution solves that use-case, it's perfect for me. Let me know if I can do anything to help out! |
@barklund I'll probably start working on it today night (+- 23:00 GMT). It will be great if people join me to test it out. So far, what I planned, using cpojer's ideas (not mentioning him to avoid spam) is to add in https://github.com/facebook/jest/blob/master/packages/jest-runtime/src/index.js
|
Will be able to test it. Lumo use case being that we want to have one snapshot folder per node version we are testing against. |
@arichiardi Is there any specific reason you want different folders? As far as I found in the source code, it can be challenging. And the jest team mentioned they don't like the (at least for now). Also, how exactly you set the different platforms? |
…t into Adds-snapshotPath-config
@sidferreira so the platforms are set on CI with The sub-folder is not really necessary, I just need a way to test against snapshots like:
Maybe this is already doable and I apologize if that's the case. I am trying to use the string to |
@arichiardi Ok, I was in this step also but didn't work for me. Is there a way for you to reset the node in use using before all or something? If so, then the work here will help you out. If not, we need to discuss a bit more. |
Not clear on this sentence:
Can you expand? Do you mean change node version while the test is running? |
@arichiardi Ok, now that you asked like this I got the hint. Well, this is a purpose a bit different than the one planned, but still will keep in mind to try to achieve it anyway. |
The solution in #5838 (comment) and #5838 (comment) feels better TBH, that is why I was kind of wondering if I can set the |
@arichiardi Not at this moment. And making this an option, as far as I checked, would be a big change. |
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.
Oh this is cool exactly what I was looking for 😄
@arichiardi yeah... the other solution didn't work (soon I'll describe the problems) so I tried this option. But kept in mind the point you mentioned (the |
Hey @cpojer ! Well, after some long tests, debugs and stuff, I found out that the changes to make The issue I found is that the Anyway, if you want I can start another PR, focused on that subject, so we can deal with it. |
snapshotPath
snapshotTag
packages/jest-snapshot/src/index.js
Outdated
.filter(snapshotFile => { | ||
if (snapshotTag) { | ||
const baseNameParts = path.basename(snapshotFile).split('.'); | ||
baseNameParts.splice(snapshotTag.split().length * -1 - 1); |
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.
ugh, I don't like splice
at all, can we not mutate this array and use yet another variable?
Also, I feel like there's a nice opportunity to extract a function for finding snapshot associated with a file (some of the logic in line 37 and 44 is quite similar).
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.
Hey @thymikee! well, first of all, I'm all open to suggestions. The idea of the splice is the following:
I want to run my tests on two projects. One for iOS, one for Android. So my snapshotTags will be "ios" and "android".
What happens in this function is that it removes the "snapshot extension" to try to find out if there's a test file related to this snapshot or not. Now, let's imagine this:
./__tests__/RoundButton.js
./__tests__/__snapshots__/RoundButton.js.ios.snap -> created when running the project with ios tag
./__tests__/__snapshots__/RoundButton.js.android.snap -> created when running the project with android tag
./__tests__/__snapshots__/RoundButton.js.snap -> older test, when I didn't have tags yet.
for each time I run the tests, I know only the current snaptshotTag, so if I have a snapshotTag, I need to extract it from the name the snapshot (which in this case I tried to allow to have dots) and the extension. As I have no idea about how many dots will have, in the path and in the snapshotTag, I used "splice" and "split" to remove the needed elements.
As I wrote the text above, I noticed I could it make a bit simpler, and improved, dropping support to tags with "." in it.
I'm looking for your feedback on that.
I just found this PR as I was reading up on #1650. I was curious if there's any reason for why the original suggestion of @cpojer (#1650 (comment) wouldn't work for the use-cases described here?
I believe such an implementation would be preferred, as it would keep the internals simpler but still allow people to configure how the snapshot resolves at own discretion. I'd be happy to help out to implement it, if such PR would have a chance of being accepted? It was asked on the parent issue already but couldn't see any official answer there. |
Hey @viddo ! I simply wasn't aware of that one. Shame on me. Thinking a bit more on that... Maybe we can just make the whole Any words on that @cpojer @SimenB @ArtemGovorov @rickhanlonii |
@sidferreira Took a stab at that, see PR #6143. Re-reading your PR I still think that would only solve part of what you want, you'd still need something like the |
@viddo In this case, I'm using jest's |
#6143 should cover this use case I think, so closing this. Thanks for the PR and discussion @sidferreira! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This is a WIP PR. It is based mainly on #1650 and my needs to have the same React Native test snapshots for each of the different platforms. I'm adding it here to both have help to finish it (as I don't have that much time available) but also have more input about the best solution.
The
snapshotPath
parameter already existed onSnapshotState
, I just added it as aproject
/global
config or a command line argument.Test plan
Currently, on my machine, there are +- 4 (HG-related) tests failing. Those errors failed before and after the changes. After adding the parameters on
package.json
it still has the same results, but of course, it doesn't mean it is working properly.