-
Notifications
You must be signed in to change notification settings - Fork 35
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
test: make tests less fragile #111
Conversation
Yeah, I added these tests prior to switching to JST.
so I hope the above explains. |
expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchSnapshot(); | ||
render(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />); | ||
|
||
expect(screen.getByText('array[string]')).toBeInTheDocument(); |
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'd refrain from such tests tbh.
At the very least we should verify the order they appear in component.
The fact that text is in the document does not imply they're render in the correct position, and with correct nesting.
If I swap the order of properties in JST or do something similar, this test won't catch it.
</div> | ||
" | ||
`; | ||
exports[`HTML Output should match combiners/allOfs/base.json 1`] = `"object{5}AllOfMergeObjectsobject{2}Object1Propertystring>= 1 charactersObject2Propertynumber<= 2AllOfMergeValidationsstring>= 1 characters<= 2 charactersAllOfMergeTakeMoreLogicalValidationnumber<= 1AllOfMergeObjectPropertyValidationsobject{1}Propertystring>= 1 characters<= 2 charactersAllOfMergeRefsobject{4}street_addressstringrequiredcitystringrequiredstatestringrequiredzipCodestring"`; |
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.
As mentioned earlier, this not validate nesting correctly.
You'll certainly want to assert the validation, colors (if we still use different colors for types, don't recall), etc. are all in all in the right state.
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.
As for the colors we abandoned them for types in new design
https://www.figma.com/proto/IkNc59AU2JN5Kc1qbd2AiB/Elements?node-id=681%3A242&viewport=302%2C436%2C0.980905294418335&scaling=min-zoom
To add a bit more context to my previous comment.
|
@P0lip I get it. I agree that those things need to be tested. My problem is, I can't figure out any better way to test, a way which also stands the test of time (and a big change in structure). You said your goal was to ensure safety when extracting JST, now mine is to ensure it when dropping tree-list and virtualization. While testing the structure would be nice I agree, keeping the structural tests then having to rebuild all the snapshots would give me way less confidence than these. Unfortunately right now - because of virtualization - there isn't really an accessible DOM structure I could test nesting & stuff with. After merging #109 I plan to update the DOM tree to use nested Again, not to convince you but I think it's not even as bad as it seems like:
There are tests explicitly for nesting in place, so there is some protection on that side.
As @mallachari said we eliminated colors already, so no need.
There are specific tests for this. So while maybe not everywhere but it is already covered.
That is being tested with So the question is: is this good enough for now? Or can you suggest some alternatives that will still provide value when being rebased on top of the structural changes? |
/** | ||
* Makes sure that exactly the first `desiredVisibleElementCount` elements from `hierarchy` are visible on the screen. | ||
*/ | ||
const assertTreeFragmentVisible = curry((hierarchy: readonly string[], desiredVisibleElementCount: number) => { |
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.
curried assertions <3
I mean, the idea is that when you update the snapshot you do verify the output.
Yeah, I get it, but what I'm saying is that these updated tests bring little value in general. One could also try to use https://www.npmjs.com/package/treeify. We leverage that lib in a number of projects. |
Closing in favor of updating snapshots for now, then later developing stronger tests on top of my structural changes. (Which will allow easier testing of nesting & such). |
Summary
When publishing #109 I found out that unfortunately the current tests give me approximately zero confidence when changing structure like in that PR. Unfortunately even a single whitespace change breaks the entire suite, not to mention adding a level of nesting (like another
div
). It makes me have to go through every single snapshot to see if the change is really just as much as intended or more.We have a pretty solid looking testing strategy at @stoplgihtio/undefined for Elements, see here. The aim of this PR is to rewrite the test suite to use these newer techniques which are supposed to be less fragile, so we can be confident that something like #109 doesn't break anything.
Goals
There are techniques lot better than these
getByText
queries I have here, but those would require changes in the component code. (Fixing accessibility problems mainly.) As the goal is to provide a solid baseline for future changes, these were ruled out.it/describe.each
-es, or changed titles where they were misleading, but the cases should in general be the same.Results
Everything should still be passing, which is a win!
What's even nicer is that replaying these commits on top of
refactor/jsv
I get the same green lights (for the rewritten tests at least), proving that the change really makes the test suite robust against even major implementation changes.Oh, and 1000 LOC lost 💪 (mostly snapshots though).
Questions / to-do
I haven't yet figured for sure what to do with the generic fixture based snapshot tests. I'm leaning towards converting them to
.innerText
based snapshots, for the time being at least, that feels like the best balance between safety and sturdiness. What do you think?