-
Notifications
You must be signed in to change notification settings - Fork 4.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
docgen: Replace fixtures with inline parsed code. #40428
Conversation
ae9829a
to
13e5361
Compare
Size Change: 0 B Total Size: 1.23 MB ℹ️ View Unchanged
|
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 you're correct to skip the line numbers, they're not actually used by the rest of the code as far as I can tell.
Assertion module: null
seems wise though, given it does vary and is significant:
if ( entry && entry.module === null ) { |
lineStart
and lineEnd
, while explicitly added, are probably more helpful for debugging than anything.
Love this clean up!
expect( | ||
getTypeAnnotation( { tag: 'param', name: 'foo' }, node, 0 ) | ||
).toBe( literal ); | ||
expect( getTypeAnnotation( { tag: 'return' }, node ) ).toBe( | ||
literal | ||
); |
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.
It'd be nice for these to be separate tests so they fail separate from each other (the code that handles them is relatively separate as well). It'd be annoying for this test to fail on the first assertion, fix it, only to find out that it was also failing on the second, mostly unrelated assertion.
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.
split!
Previously in the `docgen` package test suite we relied on developers manually creating a set of files for each test that includes a reference snippet of code, a parsed AST, and an exports listing. These files weren't linked together in any way. In this patch we're removing the manual steps and inlining the code snippets inside each test in the suite. This removes a level of manual work and indirection when maintaining the tests while leaning more on `docgen`'s `engine` component, which itself does the actual parsing.
159b126
to
08784cb
Compare
What?
Previously in the
docgen
package test suite we relied on developers manually creatinga set of files for each test that includes a reference snippet of code, a parsed AST,
and an exports listing. These files weren't linked together in any way.
In this patch we're removing the manual steps and inlining the code snippets inside each
test in the suite. This removes a level of manual work and indirection when maintaining
the tests while leaning more on
docgen
'sengine
component, which itself does theactual parsing.
Why?
We don't want to have to depend on people remembering do every manual step on every change in order to hold together the assurances our tests provide. In the course of refactoring this code, for example, there were several places where we were testing ASTs that didn't correspond to the code they purported to represent.
After this change we won't have the opportunities to create those mismatches and the false sense of safety they provide.
How?
This patch removes what amounts to duplicate copies of test data. By narrowing to a single source of truth and using the
docgen
functionality directly from inside the tests we are giving ourselves a double-assurance that everything works as we want it to. Because the new single source of truth stands inline directly in each test we've removed a layer of indirection when trying to understand or modify the tests and their assertions.Testing Instructions
There are no built-bundle changes in this PR. There are only test refactors. Please audit the test changes and consider the refactored approach: specifically these things:
parse()
andfirstToken()
test helpers an acceptable level of abstraction within test code? While relatively shallow in their functionality they allow us to focus our tests on the code and the expected results. Without them we would be adding a fair amount of noise within the tests.code.js
as written over preserving the AST representations)expect.objectContaining()
gives us a lot of flexibility in focusing on the values we want to assert and ignore the incidentals. Of note, line numbers were already a source of discrepancy between the test code fixtures and the AST fixtures.module: null
do we need this or can we remove that constraint?