Add expectCovariantWorkflow for expecting via workflow classes that have generics #1329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently we removed the
in PropsT
andout OutputT
declaration site variance specifications due to theUnsafeVariance
usage we had withinRenderContext
and the fact that Kotlin 2+ no longer allowed this (see #1320 && #1328).However, any
expectWorkflow( workflowType = SomeWorkflowType::class)
calls whereSomeWorkflowType
was an interface or class that still contained generics (rather than fully specified types), was failing to compile. It simply reported an expectation ofNothing
- which is not a helpful compiler error really that I could find. The problem though, was that these types could no longer be covariant through theOutputT
hierarchy. As such, I have added anexpectCovariantWorkflow
where the class can be a supertype that includes generics, but thechildOutputType
andchildRenderingType
must be specified directly withKType
and then these are verified against the workflow invocations.So far, we have mainly seen this be a problem when there is a factory constructing child workflow instances and the tests do not have access to those instances (or a good class type) in order to expect them.
So this adds a new testing API -
expectCovariantWorkflow
where the base class, and theOutputT
KType
andRenderingT
KType
are all specified explicitly so they can be matched.There are still scenarios where the type system can't keep up - namely if you have nested generics in your generic types. I still do not totally understand when the
RenderTester
ChildRenderInvocation
will successfully and won't successfully determine these types (I have seen both). I have not gotten to the bottom of that, but instead preferred to provide an 'opt-out' of nested generic verification as is needed.To make it easier to work with these edge cases I added a parameter to specify the levels of recursive verification to do on generics.