Add traversal for Fiber test renderer#10377
Conversation
|
@bvaughn Do you want to try to pull this in and see if our tests all pass (or tell me how to do it :p)? I wrote this tonight and the tests (copied from internal https://fburl.com/3vdfoyz7) all pass so it seems too good to be true but maybe. |
|
Nice! Yes, I'll run this tomorrow morning. |
|
Let's chat when you get in Ben! |
0c001eb to
0eb48f3
Compare
|
Looks like CI is failing b'c of Prettier and some Flow issues |
bvaughn
left a comment
There was a problem hiding this comment.
This looks great Ben!
Aside from the Flow/Prettier issues, LGTM.
By the way, did you intend to add a small test for fragments?
| predicate: Predicate, | ||
| options: ?FindOptions, | ||
| ): Array<ReactTestInstance> { | ||
| const deep = options ? options.deep : true; |
There was a problem hiding this comment.
nit: The name of this option threw me a bit. To me, "deep" relates to the location within the tree but seems more like returnFirst?
There was a problem hiding this comment.
Yea it's a little subtle. It's "if a component and its descendants both match, do we return both or just the parent?" You'd think you'd always want all of them but spreading props is common enough that the pattern is painful otherwise unfortunately.
There was a problem hiding this comment.
That's not how I'm understanding the code. Isn't it a choice between:
- If a component matches, return it, otherwise return the first descendant that matches.
- Return the component and any of its descendants that match.
I think the thing that I find confusing is that deep:false can still return a matching descendant (if the component doesn't match).
Am I misunderstanding this?
There was a problem hiding this comment.
A
B {testId: 'foo'}
div {testId: 'foo'}
section
C {testId: 'foo'}
span {testId: 'foo'}
Finding by props {testId: 'foo'} returns B and C if deep is false but returns B, C, div, and span if deep is true.
Anyway, I didn't write this code – copy/pasted this bit from the internal prototype of this.
Not clear the path to shipping this but this gives us a migration path internally that we need right now (replaces https://fburl.com/udq9ksvk).
0eb48f3 to
3412c7d
Compare
Not clear the path to shipping this but this gives us a migration path internally that we need right now (replaces https://fburl.com/udq9ksvk).