-
Notifications
You must be signed in to change notification settings - Fork 58
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
FED-1886 Null-safe props: runtime validation of required props #862
FED-1886 Null-safe props: runtime validation of required props #862
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
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.
Made a partial pass and got through most of the lib changes; one area of feedback but otherwise this looks great! Will make another pass at the tests in a bit
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.
Couple more comments; sorry it took me so long to circle back to the tests!
group('(New boilerplate) validates required props:', () { | ||
group('non-nullable required prop', () { | ||
group('throws when a prop is required and not set', () { | ||
test('on mount', () { |
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 we want to verify more specifically that these throw when the props are invoked, before they're even attempted to be rendered.
So the setup should be more like:
expect(() {
(ComponentTest()
..requiredNullable = true
)();
},
throwsA(isA<MissingRequiredPropsError>()...
Though I do think that also having test coverage that they render properly, like you have now, is probably a good idea.
returnsNormally); | ||
}); | ||
}); | ||
}, tags: 'ddc'); |
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.
Can we also verify that validation is disabled in dart2js? Doesn't have to be exhaustive will all the cases; just one test that missing required props don't cause failures should be sufficient.
@@ -15,6 +15,8 @@ | |||
// Dummy annotations that would be used by Pub code generator | |||
library over_react.component_declaration.annotations; | |||
|
|||
export 'package:meta/meta.dart' show mustCallSuper; |
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 interesting, this is so that generated code can use @mustCallSuper
, right? Could we add a comment here to that effect.
Kind of gross that it has to be exported from over_react and added to its public API, though I don't think it would cause any issues...
And I can't think of any better alternatives, unless we created an alias for it that was named something else, and maybe deprecated (e.g., @Deprecated('For generated use only) const $overReact$mustCallSuper = mustCallSuper;
)... Not sure if that's worth the trouble though.
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.
Sorry, I know you just ripped out the tests for the old boilerplate, but would you mind adding some tests that verify that late props aren't validated upon UiProps invocation for those? That way we're guarded against any regressions to that behavior in the future.
Co-authored-by: Greg Littlefield <greg.littlefield@workiva.com>
Co-authored-by: Greg Littlefield <greg.littlefield@workiva.com>
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.
+10
Motivation
FED-1717 completes support for null-safe props, and this ticket will implement runtime validation that all required late props are specified.
Changes
@requiredProp
). It's too disruptive/risky of a changeto make this start to throw; and we'll be deprecating this prop oncelate
is available.assert
vsinDevMode
.UiProps.disableRequiredPropValidation()
, which unsets a flag? Or maybe we should have people invoke the component differently, or use the componentFactory directly?Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: