From f903c31b0fa573d2a8c62196ec6423bc30bdeb85 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Thu, 15 Jun 2023 13:53:37 -0500 Subject: [PATCH 01/22] Src migration hints & pubspec overrides --- .../common_component_util.dart | 40 +++++------ .../over_react_test/console_log_utils.dart | 14 ++-- lib/src/over_react_test/custom_matchers.dart | 26 ++++---- lib/src/over_react_test/dom_util.dart | 4 +- lib/src/over_react_test/jacket.dart | 22 +++---- lib/src/over_react_test/props_meta.dart | 2 +- lib/src/over_react_test/react_util.dart | 66 +++++++++---------- lib/src/over_react_test/validation_util.dart | 4 +- lib/src/over_react_test/zone_util.dart | 10 +-- pubspec.yaml | 15 +++++ 10 files changed, 109 insertions(+), 94 deletions(-) diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 027be519..77fb4f3a 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -81,16 +81,16 @@ void commonComponentTests(BuilderOnlyUiFactory factory, { bool shouldTestPropForwarding = true, List unconsumedPropKeys = const [], List skippedPropKeys = const [], - List Function(PropsMetaCollection) getUnconsumedPropKeys, - List Function(PropsMetaCollection) getSkippedPropKeys, + List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, + List Function(PropsMetaCollection)/*?*/ getSkippedPropKeys, Map nonDefaultForwardingTestProps = const {}, bool shouldTestClassNameMerging = true, bool shouldTestClassNameOverrides = true, bool ignoreDomProps = true, bool shouldTestRequiredProps = true, @Deprecated('This flag is not needed as the test will auto detect the version') - bool isComponent2, - dynamic childrenFactory() + bool/*?*/ isComponent2, + dynamic childrenFactory()/*?*/ }) { childrenFactory ??= _defaultChildrenFactory; @@ -135,11 +135,11 @@ void expectCleanTestSurfaceAtEnd() { Set nodesBefore; setUpAll(() { - nodesBefore = document.body.children.toSet(); + nodesBefore = document.body/*!*/.children.toSet(); }); tearDownAll(() { - Set nodesAfter = document.body.children.toSet(); + Set nodesAfter = document.body/*!*/.children.toSet(); var nodesAdded = nodesAfter.difference(nodesBefore).map((element) => element.outerHtml).toList(); expect(nodesAdded, isEmpty, reason: 'tests should leave the test surface clean.'); @@ -163,8 +163,8 @@ void expectCleanTestSurfaceAtEnd() { void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory(), { @required List unconsumedPropKeys, @required List skippedPropKeys, - @required List Function(PropsMetaCollection) getUnconsumedPropKeys, - @required List Function(PropsMetaCollection) getSkippedPropKeys, + @required List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, + @required List Function(PropsMetaCollection)/*?*/ getSkippedPropKeys, @required bool ignoreDomProps, @required Map nonDefaultForwardingTestProps, }) { @@ -335,7 +335,7 @@ void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory() /// Test for prop keys that both are forwarded and exist on the forwarding target's default props. if (isDartComponent(forwardingTarget)) { final forwardingTargetType = (forwardingTarget as ReactElement).type as ReactClass; - Map forwardingTargetDefaults; + Map/*?*/ forwardingTargetDefaults; switch (forwardingTargetType.dartComponentVersion) { // ignore: invalid_use_of_protected_member case ReactDartComponentVersion.component: // ignore: invalid_use_of_protected_member forwardingTargetDefaults = forwardingTargetType.dartDefaultProps; // ignore: deprecated_member_use @@ -427,7 +427,7 @@ void testClassNameMerging(BuilderOnlyUiFactory factory, dynamic childrenFactory( ..classNameBlacklist = 'blacklisted-class-1 blacklisted-class-2'; var renderedInstance = render(builder(childrenFactory())); - Iterable forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); + Iterable forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( allOf( @@ -477,7 +477,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor // but still fail the test if something goes wrong. try { classesToOverride = getForwardingTargets(reactInstanceWithoutOverrides) - .map((target) => findDomNode(target).classes) + .map((target) => findDomNode(target)/*!*/.classes) .expand((CssClassSet classSet) => classSet) .toSet(); } catch(e) { @@ -500,7 +500,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor )(childrenFactory()) ); - Iterable forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); + Iterable forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( hasExactClasses('') ), reason: '$classesToOverride not overridden'); @@ -580,8 +580,8 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) void component2RequiredPropsTest() { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction originalConsoleError = context['console']['error']; + List consoleErrors = []; + JsFunction/*?*/ originalConsoleError = context['console']['error']; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); @@ -590,10 +590,10 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) }); final reactComponentFactory = factory().componentFactory as - ReactDartComponentFactoryProxy2; // ignore: avoid_as + ReactDartComponentFactoryProxy2/*?*//*!*//*!*/; // ignore: avoid_as for (var propKey in requiredProps) { - if (!reactComponentFactory.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory/*!*/.defaultProps.containsKey(propKey)) { try { mount((factory() @@ -657,12 +657,12 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) } else { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction originalConsoleError = context['console']['error']; + List consoleErrors = []; + JsFunction/*?*//*?*/ originalConsoleError = context['console']['error']; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); - originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5], + originalConsoleError/*!*/.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); @@ -671,7 +671,7 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) for (var propKey in nullableProps) { // Props that are defined in the default props map will never not be set. - if (!reactComponentFactory.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory/*!*/.defaultProps.containsKey(propKey)) { try { mount((factory() ..remove(propKey) diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index 4d485f64..4a25da9d 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -34,16 +34,16 @@ import 'package:react/react_client/react_interop.dart'; /// props that are not valid, the errors will be caught to allow the test to complete. /// /// To handle asynchronous behavior, see [recordConsoleLogsAsync]. -List recordConsoleLogs( +List recordConsoleLogs( Function() callback, { ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true, }) { - final consoleLogs = []; + final consoleLogs = []; final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); @@ -81,16 +81,16 @@ List recordConsoleLogs( /// with the exception being the provided callback should be asynchronous. /// /// Related: [recordConsoleLogs] -FutureOr> recordConsoleLogsAsync( +FutureOr> recordConsoleLogsAsync( Future Function() asyncCallback, { ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true, }) async { - var consoleLogs = []; + var consoleLogs = []; final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); @@ -101,7 +101,7 @@ FutureOr> recordConsoleLogsAsync( // NOTE: Using console.log or print within this function will cause an infinite // loop when the logType is set to `log`. consoleLogs.add(message); - consoleRefs[config] + consoleRefs[config]/*!*/ .apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); } diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index 181037a2..e0107e39 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -61,7 +61,7 @@ class ClassNameMatcher extends Matcher { // There's a bug in DDC where, though the docs say `className` should // return `String`, it will return `AnimatedString` for `SvgElement`s. See // https://github.com/dart-lang/sdk/issues/36200. - String castClassName; + /*late*/String castClassName; if (className is String) { castClassName = className; } else if (className is AnimatedString) { @@ -114,16 +114,16 @@ class ClassNameMatcher extends Matcher { @override Description describeMismatch(item, Description mismatchDescription, Map matchState, bool verbose) { Set missingClasses = matchState['missingClasses']; - Set unwantedClasses = matchState['unwantedClasses']; - List extraneousClasses = matchState['extraneousClasses']; + Set/*!*/ unwantedClasses = matchState['unwantedClasses']; + List/*!*/ extraneousClasses = matchState['extraneousClasses']; List descriptionParts = []; if (allowExtraneous) { - if (unwantedClasses.isNotEmpty) { + if (unwantedClasses/*!*/.isNotEmpty) { descriptionParts.add('has unwanted classes: $unwantedClasses'); } } else { - if (extraneousClasses.isNotEmpty) { + if (extraneousClasses/*!*/.isNotEmpty) { descriptionParts.add('has extraneous classes: $extraneousClasses'); } } @@ -164,7 +164,7 @@ class _HasToStringValue extends CustomMatcher { _HasToStringValue(matcher) : super('Object with toString() value', 'toString()', matcher); @override - featureValueOf(Object item) => item.toString(); + featureValueOf(Object/*?*/ item) => item.toString(); } class _HasPropMatcher extends CustomMatcher { @@ -187,7 +187,7 @@ class _HasPropMatcher extends CustomMatcher { @override Map featureValueOf(item) { - if (_useDomAttributes(item)) return findDomNode(item).attributes; + if (_useDomAttributes(item)) return findDomNode(item)/*!*/.attributes; if (item is react.Component) return item.props; return getProps(item); @@ -269,7 +269,7 @@ class _IsFocused extends Matcher { ..add('is not a valid Element.'); } - if (!document.documentElement.contains(item)) { + if (!document.documentElement/*!*/.contains(item)) { return mismatchDescription ..add('is not attached to the document, and thus cannot be focused.') ..add(' If testing with React, you can use `renderAttachedToDocument`.'); @@ -314,7 +314,7 @@ Matcher throwsPropError(String propName, [String message = '']) { /// /// __Note__: The [message] is matched rather than the [Error] instance due to Dart's wrapping of all `throw` /// as a [DomException] -Matcher throwsPropError_Required(String propName, [String message = '']) { +Matcher throwsPropError_Required(String propName, [String/*?*/ message = '']) { return throwsA(anyOf( hasToStringValue('V8 Exception'), /* workaround for https://github.com/dart-lang/sdk/issues/26093 */ hasToStringValue(contains('RequiredPropError: Prop $propName is required. $message'.trim())) @@ -362,10 +362,10 @@ Matcher throwsPropError_Combination(String propName, String prop2Name, [String m /// and pass it to [recordConsoleLogs] to run the function and record the resulting /// logs that are emitted during the function runtime. class _LoggingFunctionMatcher extends CustomMatcher { - _LoggingFunctionMatcher(dynamic matcher, {this.config, String description, String name, bool onlyIfAssertsAreEnabled = false}) + _LoggingFunctionMatcher(dynamic matcher, {this.config, String/*?*/ description, String/*?*/ name, bool onlyIfAssertsAreEnabled = false}) : super(description ?? 'emits the logs', name ?? 'logs', _wrapMatcherForSingleLog(matcher, onlyIfAssertsAreEnabled)); - final ConsoleConfiguration config; + final ConsoleConfiguration/*?*/ config; static dynamic _wrapMatcherForSingleLog(dynamic expected, [bool onlyIfAssertsAreEnabled = false]) { if (onlyIfAssertsAreEnabled && !assertsEnabled()) return anything; @@ -400,7 +400,7 @@ class _LoggingFunctionMatcher extends CustomMatcher { /// caught error. /// /// Related: [logsToConsole], [hasNoLogs] -Matcher hasLog(dynamic expected, {ConsoleConfiguration consoleConfig, bool onlyIfAssertsAreEnabled = false}) => +Matcher hasLog(dynamic expected, {ConsoleConfiguration/*?*/ consoleConfig, bool onlyIfAssertsAreEnabled = false}) => _LoggingFunctionMatcher(anyElement(contains(expected)), config: consoleConfig, onlyIfAssertsAreEnabled: onlyIfAssertsAreEnabled); /// A Matcher used to compare a list of logs against a provided matcher. @@ -440,7 +440,7 @@ Matcher hasLog(dynamic expected, {ConsoleConfiguration consoleConfig, bool onlyI /// ``` /// /// Related: [hasLog], [hasNoLogs] -Matcher logsToConsole(dynamic expected, {ConsoleConfiguration consoleConfig, bool onlyIfAssertsAreEnabled = false}) => +Matcher logsToConsole(dynamic expected, {ConsoleConfiguration/*?*/ consoleConfig, bool onlyIfAssertsAreEnabled = false}) => _LoggingFunctionMatcher(expected, config: consoleConfig, onlyIfAssertsAreEnabled: onlyIfAssertsAreEnabled); /// A matcher to verify that a callback function does not emit any logs. diff --git a/lib/src/over_react_test/dom_util.dart b/lib/src/over_react_test/dom_util.dart index f54712a2..35ed7f42 100644 --- a/lib/src/over_react_test/dom_util.dart +++ b/lib/src/over_react_test/dom_util.dart @@ -61,7 +61,7 @@ void triggerDocumentClick(Element target) { /// /// Verifies that the [target] element is not a detached node. void triggerDocumentMouseEvent(Element target, String event) { - if (!document.documentElement.contains(target)) { + if (!document.documentElement/*!*/.contains(target)) { throw ArgumentError.value(target, 'target', 'Target should be attached to the document.'); } @@ -76,7 +76,7 @@ void triggerDocumentMouseEvent(Element target, String event) { /// /// See: . Future triggerFocus(Element target, {Duration timeout = _defaultTriggerTimeout}) { - if (!document.documentElement.contains(target)) { + if (!document.documentElement/*!*/.contains(target)) { throw ArgumentError.value(target, 'target', 'Target should be attached to the document.'); } diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index fb0b7a08..98dee358 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -46,7 +46,7 @@ import './zone_util.dart'; /// /// To have the instance not automatically unmounted when the test if over set [autoTearDown] to `false`. TestJacket mount(over_react.ReactElement reactElement, { - Element mountNode, + Element/*?*/ mountNode, bool attachedToDocument = false, bool autoTearDown = true }) { @@ -58,16 +58,16 @@ TestJacket mount(over_react.ReactElement reactElem } /// Provides more a more consistent and easier to use API to test and manipulate a rendered [ReactComponent]. -class TestJacket { +class TestJacket { - TestJacket._(over_react.ReactElement reactElement, {Element mountNode, this.attachedToDocument = false, this.autoTearDown = true}) + TestJacket._(over_react.ReactElement reactElement, {Element/*?*/ mountNode, this.attachedToDocument = false, this.autoTearDown = true}) : mountNode = mountNode ?? (DivElement() ..style.height = '800px' ..style.width = '800px') { _render(reactElement); } - /* [1] */ Object _renderedInstance; + /* [1] */ Object/*?*/ _renderedInstance; final Element mountNode; final bool attachedToDocument; final bool autoTearDown; @@ -115,7 +115,7 @@ class TestJacket { /// > ``` /// > queryByTestId(jacket.mountNode, yourTestId) /// > ``` - ReactComponent getInstance() { + ReactComponent/*?*/ getInstance() { // [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is // a DOM component (Element) - does not throw. The cast to `ReactComponent` - while not "sound", is harmless // since it is an anonymous JS interop class - not a Dart type. @@ -137,7 +137,7 @@ class TestJacket { ''')); } - return _renderedInstance as ReactComponent; + return _renderedInstance as ReactComponent/*?*/; } /// Returns the props associated with the mounted React composite component instance. @@ -169,7 +169,7 @@ class TestJacket { /// > ``` /// > jacket.mountNode.querySelector(someSelectorThatTargetsTheRootNode); /// > ``` - Element getNode() { + Element/*?*/ getNode() { if (!_isCompositeComponent && !_isDomComponent) { throw StateError(over_react.unindent(''' getNode() is only supported when the rendered object is a DOM or composite (class based) component. @@ -192,7 +192,7 @@ class TestJacket { /// > If you are rendering a function component using [mount], calling [getDartInstance] will throw a `StateError`. /// > /// > See [getInstance] for more information about this limitation. - T getDartInstance() { + T/*?*/ getDartInstance() { // [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is // a DOM component (Element) - is to return `null`. While that will most likely cause null exceptions once the // consumer attempts to make a call on the "Dart instance" they have requested - we don't want this change @@ -203,7 +203,7 @@ class TestJacket { 'getDartInstance() is only supported when the rendered object is a composite (class based) component.'); } - return over_react.getDartComponent(_renderedInstance) as T; + return over_react.getDartComponent(_renderedInstance) as T/*?*/; } /// Returns if the jacket component is mounted or not. @@ -220,13 +220,13 @@ class TestJacket { /// > If you are rendering a function or DOM component using [mount], calling [setState] will throw a `StateError`. /// > /// > See [getInstance] for more information about this limitation. - void setState(newState, [callback()]) { + void setState(newState, [callback()/*?*/]) { if (!_isCompositeComponent) { throw StateError( 'setState() is only supported when the rendered object is a composite (class based) component.'); } - getDartInstance().setState(newState, callback); + getDartInstance()/*!*/.setState(newState, callback); } /// Unmounts the React component instance and cleans up any attached DOM nodes. diff --git a/lib/src/over_react_test/props_meta.dart b/lib/src/over_react_test/props_meta.dart index 8089a45a..dcf7d4c2 100644 --- a/lib/src/over_react_test/props_meta.dart +++ b/lib/src/over_react_test/props_meta.dart @@ -20,7 +20,7 @@ import 'package:react/react_client/react_interop.dart'; /// /// Returns `null` if [el] does not render a UiComponent2 or does not use the /// new mixin syntax (determined by whether accessing propsMeta throws). -PropsMetaCollection getPropsMeta(ReactElement el) { +PropsMetaCollection/*?*/ getPropsMeta(ReactElement el) { // ignore: invalid_use_of_protected_member final isComponent2 = ReactDartComponentVersion.fromType(el.type) == '2'; if (!isComponent2) return null; diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index ecd1c483..4ea5cfe7 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -54,9 +54,9 @@ export 'package:over_react/src/util/react_wrappers.dart'; /// [autoTearDown] to false. If [autoTearDown] is set to true once it will, if provided, call [autoTearDownCallback] /// once the component has been unmounted. /* [1] */ render(dynamic component, - {bool autoTearDown = true, - Element container, - Callback autoTearDownCallback}) { + {bool/*?*/ autoTearDown = true, + Element/*?*/ container, + Callback/*?*/ autoTearDownCallback}) { var renderedInstance; component = component is component_base.UiProps ? component() : component; @@ -68,7 +68,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; renderedInstance = react_dom.render(component, container); } - if (autoTearDown) { + if (autoTearDown/*!*/) { addTearDown(() { unmount(renderedInstance); if (autoTearDownCallback != null) autoTearDownCallback(); @@ -84,7 +84,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; /// [autoTearDown] to false. /// /// See: . -ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Callback autoTearDownCallback}) { +ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Callback/*?*/ autoTearDownCallback}) { var renderer = react_test_utils.createRenderer(); if (autoTearDown) { addTearDown(() { @@ -106,7 +106,7 @@ ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Cal void unmount(dynamic instanceOrContainerNode) { if (instanceOrContainerNode == null) return; - Element containerNode; + /*late*/Element containerNode; if (instanceOrContainerNode is Element) { containerNode = instanceOrContainerNode; @@ -136,7 +136,7 @@ void unmount(dynamic instanceOrContainerNode) { /// > If [component] is a function component, calling [renderAndGetDom] will throw a `StateError`. /// > /// > See `TestJacket.getNode` for more information about this limitation. -Element renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback autoTearDownCallback}) { +Element/*?*/ renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback/*?*/ autoTearDownCallback}) { final renderedInstance = render(component, autoTearDown: autoTearDown, autoTearDownCallback: autoTearDownCallback); if (!react_test_utils.isCompositeComponent(renderedInstance) && !react_test_utils.isDOMComponent(renderedInstance)) { @@ -177,9 +177,9 @@ List _attachedReactContainers = []; /// /// Returns the rendered component. /* [1] */ renderAttachedToDocument(dynamic component, - {bool autoTearDown = true, - Element container, - Callback autoTearDownCallback}) { + {bool/*?*/ autoTearDown = true, + Element/*?*/ container, + Callback/*?*/ autoTearDownCallback}) { container ??= DivElement() // Set arbitrary height and width for container to ensure nothing is cut off. ..style.setProperty('width', '800px') @@ -187,12 +187,12 @@ List _attachedReactContainers = []; setComponentZone(); - document.body.append(container); + document.body/*!*/.append(container); - if (autoTearDown) { + if (autoTearDown/*!*/) { addTearDown(() { react_dom.unmountComponentAtNode(container); - container.remove(); + container/*!*/.remove(); if (autoTearDownCallback != null) autoTearDownCallback(); }); } else { @@ -211,7 +211,7 @@ void tearDownAttachedNodes() { } } -typedef void _EventSimulatorAlias(componentOrNode, [Map eventData]); +typedef void _EventSimulatorAlias(componentOrNode, [Map/*?*/ eventData]); /// Helper function to simulate clicks final _EventSimulatorAlias click = react_test_utils.Simulate.click; @@ -244,11 +244,11 @@ final _EventSimulatorAlias mouseDown = react_test_utils.Simulate.mouseDown; final _EventSimulatorAlias mouseUp = react_test_utils.Simulate.mouseUp; /// Helper function to simulate mouseEnter events. -final _EventSimulatorAlias mouseEnter = (componentOrNode, [Map eventData = const {}]) => +final _EventSimulatorAlias mouseEnter = (componentOrNode, [Map/*?*/ eventData = const {}]) => Simulate._mouseEnter(componentOrNode, jsifyAndAllowInterop(eventData)); /// Helper function to simulate mouseLeave events. -final _EventSimulatorAlias mouseLeave = (componentOrNode, [Map eventData = const {}]) => +final _EventSimulatorAlias mouseLeave = (componentOrNode, [Map/*?*/ eventData = const {}]) => Simulate._mouseLeave(componentOrNode, jsifyAndAllowInterop(eventData)); @JS('React.addons.TestUtils.Simulate') @@ -261,7 +261,7 @@ abstract class Simulate { } /// Returns whether [props] contains [key] with a value set to a space-delimited string containing [value]. -bool _hasTestId(Map props, String key, String value) { +bool _hasTestId(Map props, String key, String/*!*/ value) { var testId = props[key]; return testId != null && splitSpaceDelimitedString(testId.toString()).contains(value); } @@ -296,7 +296,7 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -/* [1] */ getByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +/* [1] */ getByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { final results = getAllByTestId(root, value, key: key); return results.isEmpty ? null : results.first; } @@ -343,7 +343,7 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +List /* < [1] > */ getAllByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { if (root is react.Component) root = root.jsThis; if (isValidElement(root)) { @@ -351,9 +351,9 @@ List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defa } return react_test_utils.findAllInRenderedTree(root, allowInterop((descendant) { - Map props; + Map/*?*/ props; if (react_test_utils.isDOMComponent(descendant)) { - props = findDomNode(descendant).attributes; + props = findDomNode(descendant)/*!*/.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } @@ -381,7 +381,7 @@ List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defa /// /// // This returns [ `` ] /// getAllComponentsByTestId(root, 'foo') -List getAllComponentsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) => +List getAllComponentsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) => getAllByTestId(root, value, key: key) .map((element) => getDartComponent(element)) // ignore: unnecessary_lambdas .where((component) => component != null) @@ -415,7 +415,7 @@ List getAllComponentsByTestId(dynamic root, String /// getComponentRootDomByTestId(renderedInstance, 'value'); // returns the `outer` `
` /// /// Related: [queryByTestId]. -Element getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +Element/*?*/ getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { return findDomNode(getByTestId(root, value, key: key)); } @@ -450,7 +450,7 @@ Element getComponentRootDomByTestId(dynamic root, String value, {String key = de /// queryByTestId(renderedInstance, 'value'); // returns the `inner` `
` /// /// Related: [queryAllByTestId], [getComponentRootDomByTestId]. -Element queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int shadowDepth}) { +Element/*?*/ queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int/*?*/ shadowDepth}) { var results = _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: false, depth: shadowDepth); return results.isNotEmpty ? results.first : null; } @@ -490,15 +490,15 @@ Element queryByTestId(dynamic root, String value, {String key = defaultTestIdKey ///
/// /// queryAllByTestId(renderedInstance, 'value'); // returns both `inner` `
`s -List queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int shadowDepth}) { +List queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int/*?*/ shadowDepth}) { return _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: true, depth: shadowDepth); } String _makeTestIdSelector(String value, {String key = defaultTestIdKey}) => '[$key~="$value"]'; -List _findDeep(Node root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int depth}) { +List _findDeep(Node/*!*/ root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int/*?*/ depth}) { List nodes = []; - void recursiveSeek(Node _root, int _currentDepth) { + void recursiveSeek(Node/*!*/ _root, int _currentDepth) { // The LHS type prevents `rootQuerySelectorAll` from returning `_FrozenElementList>` instead of `` in DDC final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : null; nodes.addAll(rootQuerySelectorAll(itemSelector)); @@ -518,7 +518,7 @@ List _findDeep(Node root, String itemSelector, {bool searchInShadowDom /// Returns the [react.Component] of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -react.Component getComponentByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +react.Component/*?*/ getComponentByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getDartComponent(instance); @@ -530,7 +530,7 @@ react.Component getComponentByTestId(dynamic root, String value, {String key = d /// Returns the props of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -Map getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +Map/*?*/ getPropsByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getProps(instance); @@ -539,7 +539,7 @@ Map getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey} return null; } -List _getAllByTestIdShallow(ReactElement root, String value, {String key = defaultTestIdKey}) { +List _getAllByTestIdShallow(ReactElement/*!*/ root, String/*!*/ value, {String key = defaultTestIdKey}) { Iterable flattenChildren(dynamic children) sync* { if (children is Iterable) { yield* children.expand(flattenChildren); @@ -548,7 +548,7 @@ List _getAllByTestIdShallow(ReactElement root, String value, {Stri } } - final matchingDescendants = []; + final matchingDescendants = []; var breadthFirstDescendants = Queue()..add(root); while (breadthFirstDescendants.isNotEmpty) { @@ -575,9 +575,9 @@ List findDescendantsWithProp(/* [1] */ root, dynamic propKey) { return false; } - Map props; + Map/*?*/ props; if (react_test_utils.isDOMComponent(descendant)) { - props = findDomNode(descendant).attributes; + props = findDomNode(descendant)/*!*/.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index 68a76b5f..0ae9b1da 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -170,7 +170,7 @@ void clearValidationWarnings() { _validationWarnings.clear(); } -List _validationWarnings; +List/*?*/ _validationWarnings; void _recordValidationWarning(String warningMessage) { - _validationWarnings.add(warningMessage); + _validationWarnings/*!*/.add(warningMessage); } diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index 94d31373..a69ef6bb 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -17,7 +17,7 @@ import 'dart:async'; import 'package:react/react_client.dart'; import 'package:test/test.dart'; -Zone _zone; +Zone/*?*/ _zone; /// Validates that [storeZone] was called before [zonedExpect] was. void validateZone() { @@ -28,7 +28,7 @@ void validateZone() { /// Store the specified _(or current if none is specified)_ [zone] /// for use within [zonedExpect]. -void storeZone([Zone zone]) { +void storeZone([Zone/*?*/ zone]) { if (zone == null) { zone = Zone.current; } @@ -38,10 +38,10 @@ void storeZone([Zone zone]) { /// Calls [expect] in package:test/test.dart in the zone stored in [storeZone]. /// /// Useful for expectations in blocks called in other zones. -void zonedExpect(actual, matcher, {String reason}) { +void zonedExpect(actual, matcher, {String/*?*/ reason}) { validateZone(); - return _zone.run(() { + return _zone/*!*/.run(() { expect(actual, matcher, reason: reason); }); } @@ -73,6 +73,6 @@ void zonedExpect(actual, matcher, {String reason}) { /// renderIntoDocument(( /// TestComponent()..onComponentDidMount = shouldPassTest)()); // Passes /// }); -void setComponentZone([Zone zone]) { +void setComponentZone([Zone/*?*/ zone]) { componentZone = zone ?? Zone.current; } diff --git a/pubspec.yaml b/pubspec.yaml index 4201327a..11e9c7f4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,3 +18,18 @@ dev_dependencies: build_web_compilers: ^3.0.0 dependency_validator: ^3.2.2 pedantic: ^1.8.0 + +dependency_overrides: + w_common: ^3.0.0 + w_flux: + git: + url: git@github.com:Workiva/w_flux.git + ref: null-safety + over_react: + git: + url: git@github.com:Workiva/over_react.git + ref: null-safety + react: + git: + url: git@github.com:Workiva/react-dart.git + ref: null-safety-manual \ No newline at end of file From 8c69363952d3dcbf53708aadc6a4bdd4154af2a5 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Thu, 15 Jun 2023 14:56:16 -0500 Subject: [PATCH 02/22] Test dir suggestion --- .../common_component_util_test.dart | 20 ++-- .../console_log_utils_test.dart | 8 +- .../over_react_test/custom_matchers_test.dart | 4 +- test/over_react_test/dom_util_test.dart | 16 ++-- test/over_react_test/jacket_test.dart | 94 +++++++++---------- test/over_react_test/react_util_test.dart | 46 ++++----- .../utils/shadow_nested_component.dart | 2 +- .../utils/test_common_component.dart | 4 +- .../test_common_component_required_props.dart | 6 +- .../over_react_test/validation_util_test.dart | 8 +- test/over_react_test/zone_render_tests.dart | 2 +- 11 files changed, 105 insertions(+), 105 deletions(-) diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index b0d77f4b..afb030ed 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -48,7 +48,7 @@ main() { }); group('should skip checking for certain props', () { - final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()()); + final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()())/*!*/; final consumedKeys = meta.forMixin(new_boilerplate.ShouldNotBeForwardedProps).keys; final skippedKey = consumedKeys.first; @@ -93,7 +93,7 @@ main() { group('does not call `factory` directly within the consuming group', () { void sharedTest( BuilderOnlyUiFactory factory, { - List Function(PropsMetaCollection) getUnconsumedPropKeys, + List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, }) { var wasFactoryCalled = false; @@ -161,7 +161,7 @@ main() { void expectedFailGroup(String description, void Function() groupBody, {@required dynamic testFailureMatcher}) { group(description, () { int totalTestCount = 0; - List testFailureErrors; + /*late*/List testFailureErrors; setUpAll(() => testFailureErrors = []); void testButReAndIgnoreExceptions(name, testBody) { @@ -250,9 +250,9 @@ const UiFactory arbitraryUiFactory = domProps; UiFactory registerHelperComponent({ @required HelperRenderFunction render, - Map defaultProps, - Iterable consumedProps, - PropsMetaCollection propsMeta, + Map/*?*/ defaultProps, + Iterable/*?*/ consumedProps, + PropsMetaCollection/*?*/ propsMeta, }) { final factory = registerComponent2(() { return CommonHelperComponent( @@ -263,7 +263,7 @@ UiFactory registerHelperComponent({ ); }); - return ([Map backingMap]) => arbitraryUiFactory(backingMap)..componentFactory = factory; + return ([Map/*?*/ backingMap]) => arbitraryUiFactory(backingMap)..componentFactory = factory; } class CommonHelperComponent extends UiComponent2 { @@ -273,9 +273,9 @@ class CommonHelperComponent extends UiComponent2 { final HelperRenderFunction renderValue; CommonHelperComponent({ - @required Map defaultPropsValue, - @required Iterable consumedPropsValue, - @required PropsMetaCollection propsMetaValue, + @required Map/*?*/ defaultPropsValue, + @required Iterable/*?*/ consumedPropsValue, + @required PropsMetaCollection/*?*/ propsMetaValue, @required this.renderValue, }) : defaultPropsValue = defaultPropsValue ?? {}, diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index c65812d4..0254f2e2 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -226,14 +226,14 @@ main() { var jacket = mount(Sample()(), attachedToDocument: true); var logs = await recordConsoleLogsAsync(() async { var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); }, configuration: warnConfig); expect(logs, hasLength(1)); - expect(logs.first.contains('I have been clicked'), isTrue); + expect(logs.first/*!*/.contains('I have been clicked'), isTrue); }); test('handles errors caused when rendering', () async { @@ -298,7 +298,7 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); @@ -312,7 +312,7 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index be71e314..9f19ab4e 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -383,7 +383,7 @@ main() { List allAttachedNodes = []; Element makeAttachedNode() { var node = DivElement()..tabIndex = 1; - document.body.append(node); + document.body/*!*/.append(node); allAttachedNodes.add(node); @@ -865,7 +865,7 @@ void shouldFail(value, Matcher matcher, expected) { if (expected is String) { expect(_errorString, equalsIgnoringWhitespace(expected)); } else { - expect(_errorString.replaceAll(RegExp(r'[\s\n]+'), ' '), expected); + expect(_errorString/*!*/.replaceAll(RegExp(r'[\s\n]+'), ' '), expected); } } diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index 2aa0d03a..a3633359 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -23,11 +23,11 @@ main() { test('triggerTransitionEnd correctly dispatches a transitionend event', () async { var flag = false; - document.body.onTransitionEnd.listen((Event event) { + document.body/*!*/.onTransitionEnd.listen((Event event) { flag = true; }); - await triggerTransitionEnd(document.body); + await triggerTransitionEnd(document.body/*!*/); expect(flag, isTrue); }); @@ -42,7 +42,7 @@ main() { test('when the target is attached to the document', () { var renderedInstance = renderAttachedToDocument((Dom.div()..onClick = ((_) => flag = true))()); - triggerDocumentClick(findDomNode(renderedInstance)); + triggerDocumentClick(findDomNode(renderedInstance)/*!*/); expect(flag, isTrue); }); @@ -50,7 +50,7 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onClick = ((_) => flag = true))()); - expect(() => triggerDocumentClick(findDomNode(renderedInstance)), throwsArgumentError); + expect(() => triggerDocumentClick(findDomNode(renderedInstance)/*!*/), throwsArgumentError); expect(flag, isFalse); }); }); @@ -65,7 +65,7 @@ main() { test('when the target is attached to the document', () { var renderedInstance = renderAttachedToDocument((Dom.div()..onMouseDown = ((_) => flag = true))()); - triggerDocumentMouseEvent(findDomNode(renderedInstance), 'mousedown'); + triggerDocumentMouseEvent(findDomNode(renderedInstance)/*!*/, 'mousedown'); expect(flag, isTrue); }); @@ -73,7 +73,7 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onMouseDown = ((_) => flag = true))()); - expect(() => triggerDocumentMouseEvent(findDomNode(renderedInstance), 'mousedown'), throwsArgumentError); + expect(() => triggerDocumentMouseEvent(findDomNode(renderedInstance)/*!*/, 'mousedown'), throwsArgumentError); expect(flag, isFalse); }); }); @@ -91,7 +91,7 @@ main() { ..tabIndex = '1' )()); - await triggerFocus(findDomNode(renderedInstance)); + await triggerFocus(findDomNode(renderedInstance)/*!*/); expect(flag, isTrue); }); @@ -99,7 +99,7 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onFocus = ((_) => flag = true))()); - expect(() => triggerFocus(findDomNode(renderedInstance)), throwsArgumentError); + expect(() => triggerFocus(findDomNode(renderedInstance)/*!*/), throwsArgumentError); expect(flag, isFalse); }); }); diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index cc212257..02ec4ed4 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -27,14 +27,14 @@ main() { group('mount: renders the given instance', () { group('attached to the document', () { group('and unmounts after the test is done', () { - TestJacket jacket; + /*late*/TestJacket jacket; setUp(() { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); }); tearDown(() { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); expect(jacket.isMounted, isFalse); jacket = null; @@ -44,34 +44,34 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode); - expect(document.body.children[0], mountNode); - expect(jacket.isMounted, isTrue); - expect(mountNode.children[0], jacket.getNode()); + expect(document.body/*!*/.children[0], mountNode); + expect(jacket/*!*/.isMounted, isTrue); + expect(mountNode.children[0], jacket/*!*/.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true); - expect(jacket.isMounted, isTrue); - expect(document.body.children[0].children[0], jacket.getNode()); + expect(jacket/*!*/.isMounted, isTrue); + expect(document.body/*!*/.children[0].children[0], jacket/*!*/.getNode()); }); }); group('and does not unmount after the test is done', () { - TestJacket jacket; + /*late*/TestJacket/*!*/ jacket; setUp(() { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); }); tearDown(() { expect(document.body.children, isNotEmpty); - expect(jacket.isMounted, isTrue); + expect(jacket/*!*/.isMounted, isTrue); - jacket.unmount(); + jacket/*!*/.unmount(); - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isFalse); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isFalse); jacket = null; }); @@ -84,32 +84,32 @@ main() { autoTearDown: false ); - expect(document.body.children[0], mountNode); - expect(jacket.isMounted, isTrue); - expect(mountNode.children[0], jacket.getNode()); + expect(document.body/*!*/.children[0], mountNode); + expect(jacket/*!*/.isMounted, isTrue); + expect(mountNode.children[0], jacket/*!*/.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true, autoTearDown: false); - expect(jacket.isMounted, isTrue); - expect(document.body.children[0].children[0], jacket.getNode()); + expect(jacket/*!*/.isMounted, isTrue); + expect(document.body/*!*/.children[0].children[0], jacket/*!*/.getNode()); }); }); }); group('not attached to the document', () { group('and unmounts after the test is done', () { - TestJacket jacket; + /*late*/TestJacket jacket; setUp(() { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); }); tearDown(() { - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isFalse); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isFalse); jacket = null; }); @@ -118,33 +118,33 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), mountNode: mountNode); - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isTrue); - expect(mountNode.children[0], jacket.getNode()); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isTrue); + expect(mountNode.children[0], jacket/*!*/.getNode()); }); test('without the given container', () { jacket = mount(Sample()()); - expect(jacket.isMounted, isTrue); + expect(jacket/*!*/.isMounted, isTrue); }); }); group('and does not unmount after the test is done', () { - TestJacket jacket; + /*late*/TestJacket jacket; setUp(() { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); }); tearDown(() { - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isTrue); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isTrue); - jacket.unmount(); + jacket/*!*/.unmount(); - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isFalse); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isFalse); jacket = null; }); @@ -153,16 +153,16 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), mountNode: mountNode, autoTearDown: false); - expect(document.body.children.isEmpty, isTrue); - expect(jacket.isMounted, isTrue); - expect(mountNode.children[0], jacket.getNode()); + expect(document.body/*!*/.children.isEmpty, isTrue); + expect(jacket/*!*/.isMounted, isTrue); + expect(mountNode.children[0], jacket/*!*/.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), autoTearDown: false); - expect(document.body.children, isEmpty); - expect(jacket.isMounted, isTrue); + expect(document.body/*!*/.children, isEmpty); + expect(jacket/*!*/.isMounted, isTrue); }); }); }); @@ -179,7 +179,7 @@ main() { ); expect(Sample(jacket.getProps()).foo, isFalse); - expect(jacket.getDartInstance().state.bar, isFalse); + expect(jacket.getDartInstance()/*!*/.state.bar, isFalse); }); test('rerender', () { @@ -201,9 +201,9 @@ main() { }); test('setState', () { - jacket.setState(jacket.getDartInstance().newState()..bar = true); + jacket.setState(jacket.getDartInstance()/*!*/.newState()..bar = true); - expect(jacket.getDartInstance().state.bar, isTrue); + expect(jacket.getDartInstance()/*!*/.state.bar, isTrue); }); test('unmount', () { @@ -216,7 +216,7 @@ main() { }); group('TestJacket: DOM component:', () { - Element mountNode; + /*late*/Element mountNode; TestJacket jacket; setUp(() { @@ -266,7 +266,7 @@ main() { }); group('TestJacket: function component:', () { - Element mountNode; + /*late*/Element mountNode; TestJacket jacket; setUp(() { @@ -276,18 +276,18 @@ main() { attachedToDocument: true ); - expect(mountNode.children.single.id, 'foo'); + expect(mountNode/*!*/.children.single.id, 'foo'); }); tearDown(() { - mountNode.remove(); + mountNode/*!*/.remove(); mountNode = null; }); test('rerender', () { jacket.rerender(testFunctionComponent({'id': 'bar'})); - expect(mountNode.children.single.id, 'bar'); + expect(mountNode/*!*/.children.single.id, 'bar'); }); test('getProps throws a StateError', () { diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index e0159ba7..88665784 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -59,37 +59,37 @@ main() { reason: 'The React instance should have been unmounted.' ); - expect(document.body.children, isEmpty, reason: 'All attached mount points should have been removed.'); + expect(document.body/*!*/.children, isEmpty, reason: 'All attached mount points should have been removed.'); }); test('renderAttachedToDocument renders the component into the document', () { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); renderedInstance = renderAttachedToDocument(Wrapper()); - expect(document.body.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); }); test('renderAttachedToDocument renders the component into the document with a given container', () { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); var container = DivElement(); renderedInstance = renderAttachedToDocument(Wrapper(), container: container); - expect(document.body.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); - expect(document.body.children[0], container); + expect(document.body/*!*/.children[0], container); }); }); test('renderAttachedToDocument renders the component into the document and tearDownAttachedNodes cleans them up', () { - expect(document.body.children, isEmpty); + expect(document.body/*!*/.children, isEmpty); var renderedInstance = renderAttachedToDocument(Wrapper(), autoTearDown: false); - expect(document.body.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); tearDownAttachedNodes(); @@ -102,7 +102,7 @@ main() { reason: 'The React instance should have been unmounted.' ); - expect(document.body.children, isEmpty, reason: 'All attached mount points should have been removed.'); + expect(document.body/*!*/.children, isEmpty, reason: 'All attached mount points should have been removed.'); }); group('renderAndGetDom', () { @@ -253,9 +253,9 @@ main() { }); group('getByTestId returns', () { - sharedTests({bool shallow}) { + sharedTests({bool/*?*/ shallow}) { testSpecificRender(ReactElement instance) => - shallow ? renderShallow(instance) : render(instance); + shallow/*!*/ ? renderShallow(instance) : render(instance); group('the single descendant that has the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -461,9 +461,9 @@ main() { }); group('getAllByTestId returns', () { - sharedTests({bool shallow}) { + sharedTests({bool/*?*/ shallow}) { testSpecificRender(ReactElement instance) => - shallow ? renderShallow(instance) : render(instance); + shallow/*!*/ ? renderShallow(instance) : render(instance); group('a list containing the single descendant that have the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -683,7 +683,7 @@ main() { group('getAllComponentsByTestId returns only the Dart components with the matching test ID', () { void sharedExpectations( List allByTestId, - List allComponentsByTestId, + List allComponentsByTestId, ) { final isCompositeCOmponentMatcher = predicate(rtu.isCompositeComponent, 'is composite component'); @@ -750,7 +750,7 @@ main() { group('`data-test-id` html attribute key', () { test('', () { var renderedInstance = render((Nested()..addTestId('value'))()); - var innerNode = findDomNode(renderedInstance).querySelector('[data-test-id~="inner"]'); + var innerNode = findDomNode(renderedInstance)/*!*/.querySelector('[data-test-id~="inner"]'); expect(queryByTestId(renderedInstance, 'value'), innerNode); }); @@ -764,7 +764,7 @@ main() { test('custom html attribute key', () { var renderedInstance = render((Nested()..addTestId('value', key: 'data-custom-id'))()); - var innerNode = findDomNode(renderedInstance).querySelector('[data-test-id~="inner"]'); + var innerNode = findDomNode(renderedInstance)/*!*/.querySelector('[data-test-id~="inner"]'); expect(queryByTestId(renderedInstance, 'value', key: 'data-custom-id'), innerNode); }); @@ -788,7 +788,7 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var innerNode = shadowHostRef.current.shadowRoot.querySelector('[data-test-id~="$searchId"]'); + var innerNode = shadowHostRef.current/*!*/.shadowRoot/*!*/.querySelector('[data-test-id~="$searchId"]'); expect(queryByTestId(jacket.mountNode, searchId, searchInShadowDom: true), innerNode); }); @@ -817,7 +817,7 @@ main() { (Nested()..addTestId('value'))(), (Nested()..addTestId('value'))(), )); - var innerNodes = findDomNode(renderedInstance).querySelectorAll('[data-test-id~="inner"]'); + var innerNodes = findDomNode(renderedInstance)/*!*/.querySelectorAll('[data-test-id~="inner"]'); expect(queryAllByTestId(renderedInstance, 'value'), innerNodes); }); @@ -834,7 +834,7 @@ main() { (Nested()..addTestId('value'))(), (Nested()..addTestId('value'))(), )); - var innerNodes = findDomNode(renderedInstance).querySelectorAll('[data-test-id~="inner"]'); + var innerNodes = findDomNode(renderedInstance)/*!*/.querySelectorAll('[data-test-id~="inner"]'); expect(queryAllByTestId(renderedInstance, 'value'), innerNodes); }); @@ -878,9 +878,9 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var level1 = shadow1Ref.current.shadowRoot.querySelector('.div1'); - var level2 = shadow2Ref.current.shadowRoot.querySelector('.div2'); - var level3 = shadow3Ref.current.shadowRoot.querySelector('.div3'); + var level1 = shadow1Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div1'); + var level2 = shadow2Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div2'); + var level3 = shadow3Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div3'); expect(queryAllByTestId(jacket.mountNode, 'findMe', searchInShadowDom: true), [level1, level2, level3]); }); @@ -919,7 +919,7 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var level1 = shadow1Ref.current.shadowRoot.querySelector('.div1'); + var level1 = shadow1Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div1'); expect(queryAllByTestId(jacket.mountNode, 'findMe', searchInShadowDom: true, shadowDepth: 1), [level1]); }); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index 01a70efa..35ca279a 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -30,7 +30,7 @@ UiFactory ShadowNested = uiForwardRef( useEffect(() { var shadowRootFirstChild = DivElement()..dataset['test-id'] = props.shadowRootFirstChildTestId ?? 'shadowRootFirstChild'; - divRef.current.attachShadow({'mode':'open'}).append(shadowRootFirstChild); + divRef.current/*!*/.attachShadow({'mode':'open'}).append(shadowRootFirstChild); react_dom.render(Fragment()(props.children), shadowRootFirstChild); return () => react_dom.unmountComponentAtNode(shadowRootFirstChild); }, []); diff --git a/test/over_react_test/utils/test_common_component.dart b/test/over_react_test/utils/test_common_component.dart index 8bbfa82b..1505be76 100644 --- a/test/over_react_test/utils/test_common_component.dart +++ b/test/over_react_test/utils/test_common_component.dart @@ -57,7 +57,7 @@ abstract class PropsThatShouldBeForwarded { Map get props; - bool foo; + bool/*?*/ foo; } @PropsMixin() @@ -69,7 +69,7 @@ abstract class PropsThatShouldNotBeForwarded { Map get props; - bool bar; + bool/*?*/ bar; } // AF-3369 This will be removed once the transition to Dart 2 is complete. diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index 43c0d395..2259b24c 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -23,13 +23,13 @@ UiFactory TestCommonRequired = @Props() class _$TestCommonRequiredProps extends UiProps { @nullableRequiredProp - bool foobar; + bool/*?*/ foobar; @requiredProp - bool bar; + bool/*?*/ bar; @nullableRequiredProp - bool defaultFoo; + bool/*?*/ defaultFoo; } @Component() diff --git a/test/over_react_test/validation_util_test.dart b/test/over_react_test/validation_util_test.dart index 9cc9e587..6eb915b2 100644 --- a/test/over_react_test/validation_util_test.dart +++ b/test/over_react_test/validation_util_test.dart @@ -34,7 +34,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings().single, 'message1'); + expect(getValidationWarnings()/*!*/.single, 'message1'); assert(ValidationUtil.warn('message2')); @@ -48,7 +48,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings().single, 'message1'); + expect(getValidationWarnings()/*!*/.single, 'message1'); stopRecordingValidationWarnings(); @@ -94,7 +94,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings().single, 'message1'); + expect(getValidationWarnings()/*!*/.single, 'message1'); clearValidationWarnings(); @@ -103,7 +103,7 @@ main() { assert(ValidationUtil.warn('message2')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings().single, 'message2'); + expect(getValidationWarnings()/*!*/.single, 'message2'); }); }); }, testOn: '!js'); diff --git a/test/over_react_test/zone_render_tests.dart b/test/over_react_test/zone_render_tests.dart index 19bdaff6..2e3a8f84 100644 --- a/test/over_react_test/zone_render_tests.dart +++ b/test/over_react_test/zone_render_tests.dart @@ -21,7 +21,7 @@ main() { }); } -void sharedZoneRenderTests(Function(ReactElement element, {bool autoTearDown}) renderFunction) { +void sharedZoneRenderTests(Function(ReactElement element, {bool/*?*/ autoTearDown}) renderFunction) { group('sharedZoneRenderTests:', () { setUp(() { setComponentZone(Zone.root); From 1e073812289cdd27a15ff3cd8d17a04b46a6d5ef Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Thu, 15 Jun 2023 14:57:59 -0500 Subject: [PATCH 03/22] Run migration --- .../common_component_util.dart | 64 +++++----- .../over_react_test/console_log_utils.dart | 16 +-- lib/src/over_react_test/custom_matchers.dart | 31 ++--- lib/src/over_react_test/dom_util.dart | 4 +- lib/src/over_react_test/jacket.dart | 22 ++-- lib/src/over_react_test/props_meta.dart | 2 +- lib/src/over_react_test/react_util.dart | 79 ++++++------ lib/src/over_react_test/validation_util.dart | 8 +- lib/src/over_react_test/zone_util.dart | 10 +- pubspec.yaml | 3 +- .../common_component_util_test.dart | 32 ++--- .../console_log_utils_test.dart | 10 +- .../over_react_test/custom_matchers_test.dart | 12 +- test/over_react_test/dom_util_test.dart | 22 ++-- test/over_react_test/jacket_test.dart | 112 +++++++++--------- test/over_react_test/react_util_test.dart | 48 ++++---- .../utils/shadow_nested_component.dart | 2 +- .../utils/test_common_component.dart | 4 +- .../test_common_component_required_props.dart | 6 +- .../over_react_test/validation_util_test.dart | 8 +- test/over_react_test/zone_render_tests.dart | 4 +- 21 files changed, 251 insertions(+), 248 deletions(-) diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 77fb4f3a..18a712b5 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -81,16 +81,16 @@ void commonComponentTests(BuilderOnlyUiFactory factory, { bool shouldTestPropForwarding = true, List unconsumedPropKeys = const [], List skippedPropKeys = const [], - List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, - List Function(PropsMetaCollection)/*?*/ getSkippedPropKeys, + List Function(PropsMetaCollection)? getUnconsumedPropKeys, + List Function(PropsMetaCollection)? getSkippedPropKeys, Map nonDefaultForwardingTestProps = const {}, bool shouldTestClassNameMerging = true, bool shouldTestClassNameOverrides = true, bool ignoreDomProps = true, bool shouldTestRequiredProps = true, @Deprecated('This flag is not needed as the test will auto detect the version') - bool/*?*/ isComponent2, - dynamic childrenFactory()/*?*/ + bool? isComponent2, + dynamic childrenFactory()? }) { childrenFactory ??= _defaultChildrenFactory; @@ -132,14 +132,14 @@ Iterable _flatten(Iterable iterable) => /// }); /// } void expectCleanTestSurfaceAtEnd() { - Set nodesBefore; + late Set nodesBefore; setUpAll(() { - nodesBefore = document.body/*!*/.children.toSet(); + nodesBefore = document.body!.children.toSet(); }); tearDownAll(() { - Set nodesAfter = document.body/*!*/.children.toSet(); + Set nodesAfter = document.body!.children.toSet(); var nodesAdded = nodesAfter.difference(nodesBefore).map((element) => element.outerHtml).toList(); expect(nodesAdded, isEmpty, reason: 'tests should leave the test surface clean.'); @@ -161,12 +161,12 @@ void expectCleanTestSurfaceAtEnd() { /// todo make this public again if there's a need to expose it, once the API has stabilized @isTest void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory(), { - @required List unconsumedPropKeys, - @required List skippedPropKeys, - @required List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, - @required List Function(PropsMetaCollection)/*?*/ getSkippedPropKeys, - @required bool ignoreDomProps, - @required Map nonDefaultForwardingTestProps, + required List unconsumedPropKeys, + required List skippedPropKeys, + required List Function(PropsMetaCollection)? getUnconsumedPropKeys, + required List Function(PropsMetaCollection)? getSkippedPropKeys, + required bool ignoreDomProps, + required Map nonDefaultForwardingTestProps, }) { testFunction('forwards unconsumed props as expected', () { // This needs to be retrieved inside a `test`/`setUp`/etc, not inside a group, @@ -335,18 +335,18 @@ void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory() /// Test for prop keys that both are forwarded and exist on the forwarding target's default props. if (isDartComponent(forwardingTarget)) { final forwardingTargetType = (forwardingTarget as ReactElement).type as ReactClass; - Map/*?*/ forwardingTargetDefaults; + Map? forwardingTargetDefaults; switch (forwardingTargetType.dartComponentVersion) { // ignore: invalid_use_of_protected_member case ReactDartComponentVersion.component: // ignore: invalid_use_of_protected_member forwardingTargetDefaults = forwardingTargetType.dartDefaultProps; // ignore: deprecated_member_use break; case ReactDartComponentVersion.component2: // ignore: invalid_use_of_protected_member - forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps); + forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps!); break; } var commonForwardedAndDefaults = propKeysThatShouldNotGetForwarded - .intersection(forwardingTargetDefaults.keys.toSet()); + .intersection(forwardingTargetDefaults!.keys.toSet()); /// Don't count these as unexpected keys in later assertions; we'll verify them within this block. unexpectedKeys.removeAll(commonForwardedAndDefaults); @@ -427,7 +427,7 @@ void testClassNameMerging(BuilderOnlyUiFactory factory, dynamic childrenFactory( ..classNameBlacklist = 'blacklisted-class-1 blacklisted-class-2'; var renderedInstance = render(builder(childrenFactory())); - Iterable forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); + Iterable forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( allOf( @@ -461,7 +461,7 @@ void testClassNameMerging(BuilderOnlyUiFactory factory, dynamic childrenFactory( /// > Related: [testClassNameMerging] @isTestGroup void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactory()) { - Set classesToOverride; + late Set classesToOverride; var error; setUp(() { @@ -477,7 +477,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor // but still fail the test if something goes wrong. try { classesToOverride = getForwardingTargets(reactInstanceWithoutOverrides) - .map((target) => findDomNode(target)/*!*/.classes) + .map((target) => findDomNode(target)!.classes) .expand((CssClassSet classSet) => classSet) .toSet(); } catch(e) { @@ -500,7 +500,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor )(childrenFactory()) ); - Iterable forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); + Iterable forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( hasExactClasses('') ), reason: '$classesToOverride not overridden'); @@ -514,7 +514,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor /// __Note__: All required props must be provided by [factory]. @isTestGroup void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) { - bool isComponent2; + late bool isComponent2; var keyToErrorMessage = {}; var nullableProps = []; @@ -531,7 +531,7 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) isComponent2 = version == ReactDartComponentVersion.component2; var jacket = mount(factory()(childrenFactory()), autoTearDown: false); - var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps; + var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps!; jacket.unmount(); for (var consumedProp in consumedProps) { @@ -580,20 +580,20 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) void component2RequiredPropsTest() { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction/*?*/ originalConsoleError = context['console']['error']; + List consoleErrors = []; + JsFunction? originalConsoleError = context['console']['error']; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); - originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5], + originalConsoleError!.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); final reactComponentFactory = factory().componentFactory as - ReactDartComponentFactoryProxy2/*?*//*!*//*!*/; // ignore: avoid_as + ReactDartComponentFactoryProxy2?/*!*//*!*/; // ignore: avoid_as for (var propKey in requiredProps) { - if (!reactComponentFactory/*!*/.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory!.defaultProps.containsKey(propKey)) { try { mount((factory() @@ -657,21 +657,21 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) } else { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction/*?*//*?*/ originalConsoleError = context['console']['error']; + List consoleErrors = []; + JsFunction?/*?*/ originalConsoleError = context['console']['error']; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); - originalConsoleError/*!*/.apply([message, arg1, arg2, arg3, arg4, arg5], + originalConsoleError!.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); final reactComponentFactory = factory().componentFactory as - ReactDartComponentFactoryProxy2; // ignore: avoid_as + ReactDartComponentFactoryProxy2?; // ignore: avoid_as for (var propKey in nullableProps) { // Props that are defined in the default props map will never not be set. - if (!reactComponentFactory/*!*/.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory!.defaultProps.containsKey(propKey)) { try { mount((factory() ..remove(propKey) diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index 4a25da9d..dccff5ec 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -34,16 +34,16 @@ import 'package:react/react_client/react_interop.dart'; /// props that are not valid, the errors will be caught to allow the test to complete. /// /// To handle asynchronous behavior, see [recordConsoleLogsAsync]. -List recordConsoleLogs( +List recordConsoleLogs( Function() callback, { ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true, }) { - final consoleLogs = []; + final consoleLogs = []; final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); @@ -54,7 +54,7 @@ List recordConsoleLogs( // NOTE: Using console.log or print within this function will cause an infinite // loop when the logType is set to `log`. consoleLogs.add(message); - consoleRefs[config] + consoleRefs[config]! .apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); } @@ -81,16 +81,16 @@ List recordConsoleLogs( /// with the exception being the provided callback should be asynchronous. /// /// Related: [recordConsoleLogs] -FutureOr> recordConsoleLogsAsync( +FutureOr> recordConsoleLogsAsync( Future Function() asyncCallback, { ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true, }) async { - var consoleLogs = []; + var consoleLogs = []; final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); @@ -101,7 +101,7 @@ FutureOr> recordConsoleLogsAsync( // NOTE: Using console.log or print within this function will cause an infinite // loop when the logType is set to `log`. consoleLogs.add(message); - consoleRefs[config]/*!*/ + consoleRefs[config]! .apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); } diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index e0107e39..09cf16e2 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -15,6 +15,7 @@ import 'dart:html'; import 'dart:svg'; +import 'package:collection/collection.dart' show IterableNullableExtension; import 'package:over_react/over_react.dart'; import 'package:matcher/matcher.dart'; import 'package:over_react_test/src/over_react_test/dart_util.dart'; @@ -46,7 +47,7 @@ class ClassNameMatcher extends Matcher { static Iterable getClassIterable(dynamic classNames) { Iterable classes; if (classNames is Iterable) { - classes = classNames.where((className) => className != null).expand(splitSpaceDelimitedString); + classes = classNames.whereNotNull().expand(splitSpaceDelimitedString); } else if (classNames is String) { classes = splitSpaceDelimitedString(classNames); } else { @@ -61,7 +62,7 @@ class ClassNameMatcher extends Matcher { // There's a bug in DDC where, though the docs say `className` should // return `String`, it will return `AnimatedString` for `SvgElement`s. See // https://github.com/dart-lang/sdk/issues/36200. - /*late*/String castClassName; + late String? castClassName; if (className is String) { castClassName = className; } else if (className is AnimatedString) { @@ -114,16 +115,16 @@ class ClassNameMatcher extends Matcher { @override Description describeMismatch(item, Description mismatchDescription, Map matchState, bool verbose) { Set missingClasses = matchState['missingClasses']; - Set/*!*/ unwantedClasses = matchState['unwantedClasses']; - List/*!*/ extraneousClasses = matchState['extraneousClasses']; + Set unwantedClasses = matchState['unwantedClasses']; + List extraneousClasses = matchState['extraneousClasses']; List descriptionParts = []; if (allowExtraneous) { - if (unwantedClasses/*!*/.isNotEmpty) { + if (unwantedClasses!.isNotEmpty) { descriptionParts.add('has unwanted classes: $unwantedClasses'); } } else { - if (extraneousClasses/*!*/.isNotEmpty) { + if (extraneousClasses!.isNotEmpty) { descriptionParts.add('has extraneous classes: $extraneousClasses'); } } @@ -164,7 +165,7 @@ class _HasToStringValue extends CustomMatcher { _HasToStringValue(matcher) : super('Object with toString() value', 'toString()', matcher); @override - featureValueOf(Object/*?*/ item) => item.toString(); + featureValueOf(Object? item) => item.toString(); } class _HasPropMatcher extends CustomMatcher { @@ -187,7 +188,7 @@ class _HasPropMatcher extends CustomMatcher { @override Map featureValueOf(item) { - if (_useDomAttributes(item)) return findDomNode(item)/*!*/.attributes; + if (_useDomAttributes(item)) return findDomNode(item)!.attributes; if (item is react.Component) return item.props; return getProps(item); @@ -269,7 +270,7 @@ class _IsFocused extends Matcher { ..add('is not a valid Element.'); } - if (!document.documentElement/*!*/.contains(item)) { + if (!document.documentElement!.contains(item)) { return mismatchDescription ..add('is not attached to the document, and thus cannot be focused.') ..add(' If testing with React, you can use `renderAttachedToDocument`.'); @@ -314,7 +315,7 @@ Matcher throwsPropError(String propName, [String message = '']) { /// /// __Note__: The [message] is matched rather than the [Error] instance due to Dart's wrapping of all `throw` /// as a [DomException] -Matcher throwsPropError_Required(String propName, [String/*?*/ message = '']) { +Matcher throwsPropError_Required(String propName, [String? message = '']) { return throwsA(anyOf( hasToStringValue('V8 Exception'), /* workaround for https://github.com/dart-lang/sdk/issues/26093 */ hasToStringValue(contains('RequiredPropError: Prop $propName is required. $message'.trim())) @@ -362,10 +363,10 @@ Matcher throwsPropError_Combination(String propName, String prop2Name, [String m /// and pass it to [recordConsoleLogs] to run the function and record the resulting /// logs that are emitted during the function runtime. class _LoggingFunctionMatcher extends CustomMatcher { - _LoggingFunctionMatcher(dynamic matcher, {this.config, String/*?*/ description, String/*?*/ name, bool onlyIfAssertsAreEnabled = false}) + _LoggingFunctionMatcher(dynamic matcher, {this.config, String? description, String? name, bool onlyIfAssertsAreEnabled = false}) : super(description ?? 'emits the logs', name ?? 'logs', _wrapMatcherForSingleLog(matcher, onlyIfAssertsAreEnabled)); - final ConsoleConfiguration/*?*/ config; + final ConsoleConfiguration? config; static dynamic _wrapMatcherForSingleLog(dynamic expected, [bool onlyIfAssertsAreEnabled = false]) { if (onlyIfAssertsAreEnabled && !assertsEnabled()) return anything; @@ -375,7 +376,7 @@ class _LoggingFunctionMatcher extends CustomMatcher { @override featureValueOf(actual) { - var logs = []; + List logs = []; if (actual is List) return actual; @@ -400,7 +401,7 @@ class _LoggingFunctionMatcher extends CustomMatcher { /// caught error. /// /// Related: [logsToConsole], [hasNoLogs] -Matcher hasLog(dynamic expected, {ConsoleConfiguration/*?*/ consoleConfig, bool onlyIfAssertsAreEnabled = false}) => +Matcher hasLog(dynamic expected, {ConsoleConfiguration? consoleConfig, bool onlyIfAssertsAreEnabled = false}) => _LoggingFunctionMatcher(anyElement(contains(expected)), config: consoleConfig, onlyIfAssertsAreEnabled: onlyIfAssertsAreEnabled); /// A Matcher used to compare a list of logs against a provided matcher. @@ -440,7 +441,7 @@ Matcher hasLog(dynamic expected, {ConsoleConfiguration/*?*/ consoleConfig, bool /// ``` /// /// Related: [hasLog], [hasNoLogs] -Matcher logsToConsole(dynamic expected, {ConsoleConfiguration/*?*/ consoleConfig, bool onlyIfAssertsAreEnabled = false}) => +Matcher logsToConsole(dynamic expected, {ConsoleConfiguration? consoleConfig, bool onlyIfAssertsAreEnabled = false}) => _LoggingFunctionMatcher(expected, config: consoleConfig, onlyIfAssertsAreEnabled: onlyIfAssertsAreEnabled); /// A matcher to verify that a callback function does not emit any logs. diff --git a/lib/src/over_react_test/dom_util.dart b/lib/src/over_react_test/dom_util.dart index 35ed7f42..ed2b1e97 100644 --- a/lib/src/over_react_test/dom_util.dart +++ b/lib/src/over_react_test/dom_util.dart @@ -61,7 +61,7 @@ void triggerDocumentClick(Element target) { /// /// Verifies that the [target] element is not a detached node. void triggerDocumentMouseEvent(Element target, String event) { - if (!document.documentElement/*!*/.contains(target)) { + if (!document.documentElement!.contains(target)) { throw ArgumentError.value(target, 'target', 'Target should be attached to the document.'); } @@ -76,7 +76,7 @@ void triggerDocumentMouseEvent(Element target, String event) { /// /// See: . Future triggerFocus(Element target, {Duration timeout = _defaultTriggerTimeout}) { - if (!document.documentElement/*!*/.contains(target)) { + if (!document.documentElement!.contains(target)) { throw ArgumentError.value(target, 'target', 'Target should be attached to the document.'); } diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index 98dee358..ea7d8128 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -46,7 +46,7 @@ import './zone_util.dart'; /// /// To have the instance not automatically unmounted when the test if over set [autoTearDown] to `false`. TestJacket mount(over_react.ReactElement reactElement, { - Element/*?*/ mountNode, + Element? mountNode, bool attachedToDocument = false, bool autoTearDown = true }) { @@ -58,16 +58,16 @@ TestJacket mount(over_react.ReactElement reactElem } /// Provides more a more consistent and easier to use API to test and manipulate a rendered [ReactComponent]. -class TestJacket { +class TestJacket { - TestJacket._(over_react.ReactElement reactElement, {Element/*?*/ mountNode, this.attachedToDocument = false, this.autoTearDown = true}) + TestJacket._(over_react.ReactElement reactElement, {Element? mountNode, this.attachedToDocument = false, this.autoTearDown = true}) : mountNode = mountNode ?? (DivElement() ..style.height = '800px' ..style.width = '800px') { _render(reactElement); } - /* [1] */ Object/*?*/ _renderedInstance; + /* [1] */ Object? _renderedInstance; final Element mountNode; final bool attachedToDocument; final bool autoTearDown; @@ -115,7 +115,7 @@ class TestJacket { /// > ``` /// > queryByTestId(jacket.mountNode, yourTestId) /// > ``` - ReactComponent/*?*/ getInstance() { + ReactComponent? getInstance() { // [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is // a DOM component (Element) - does not throw. The cast to `ReactComponent` - while not "sound", is harmless // since it is an anonymous JS interop class - not a Dart type. @@ -137,7 +137,7 @@ class TestJacket { ''')); } - return _renderedInstance as ReactComponent/*?*/; + return _renderedInstance as ReactComponent?; } /// Returns the props associated with the mounted React composite component instance. @@ -169,7 +169,7 @@ class TestJacket { /// > ``` /// > jacket.mountNode.querySelector(someSelectorThatTargetsTheRootNode); /// > ``` - Element/*?*/ getNode() { + Element? getNode() { if (!_isCompositeComponent && !_isDomComponent) { throw StateError(over_react.unindent(''' getNode() is only supported when the rendered object is a DOM or composite (class based) component. @@ -192,7 +192,7 @@ class TestJacket { /// > If you are rendering a function component using [mount], calling [getDartInstance] will throw a `StateError`. /// > /// > See [getInstance] for more information about this limitation. - T/*?*/ getDartInstance() { + T? getDartInstance() { // [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is // a DOM component (Element) - is to return `null`. While that will most likely cause null exceptions once the // consumer attempts to make a call on the "Dart instance" they have requested - we don't want this change @@ -203,7 +203,7 @@ class TestJacket { 'getDartInstance() is only supported when the rendered object is a composite (class based) component.'); } - return over_react.getDartComponent(_renderedInstance) as T/*?*/; + return over_react.getDartComponent(_renderedInstance) as T?; } /// Returns if the jacket component is mounted or not. @@ -220,13 +220,13 @@ class TestJacket { /// > If you are rendering a function or DOM component using [mount], calling [setState] will throw a `StateError`. /// > /// > See [getInstance] for more information about this limitation. - void setState(newState, [callback()/*?*/]) { + void setState(newState, [callback()?]) { if (!_isCompositeComponent) { throw StateError( 'setState() is only supported when the rendered object is a composite (class based) component.'); } - getDartInstance()/*!*/.setState(newState, callback); + getDartInstance()!.setState(newState, callback); } /// Unmounts the React component instance and cleans up any attached DOM nodes. diff --git a/lib/src/over_react_test/props_meta.dart b/lib/src/over_react_test/props_meta.dart index dcf7d4c2..d3e5b67c 100644 --- a/lib/src/over_react_test/props_meta.dart +++ b/lib/src/over_react_test/props_meta.dart @@ -20,7 +20,7 @@ import 'package:react/react_client/react_interop.dart'; /// /// Returns `null` if [el] does not render a UiComponent2 or does not use the /// new mixin syntax (determined by whether accessing propsMeta throws). -PropsMetaCollection/*?*/ getPropsMeta(ReactElement el) { +PropsMetaCollection? getPropsMeta(ReactElement el) { // ignore: invalid_use_of_protected_member final isComponent2 = ReactDartComponentVersion.fromType(el.type) == '2'; if (!isComponent2) return null; diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index 4ea5cfe7..d68d3023 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -18,6 +18,7 @@ library over_react_test.react_util; import 'dart:collection'; import 'dart:html'; +import 'package:collection/collection.dart' show IterableNullableExtension; import 'package:js/js.dart'; import 'package:over_react/over_react.dart'; import 'package:over_react/component_base.dart' as component_base; @@ -54,9 +55,9 @@ export 'package:over_react/src/util/react_wrappers.dart'; /// [autoTearDown] to false. If [autoTearDown] is set to true once it will, if provided, call [autoTearDownCallback] /// once the component has been unmounted. /* [1] */ render(dynamic component, - {bool/*?*/ autoTearDown = true, - Element/*?*/ container, - Callback/*?*/ autoTearDownCallback}) { + {bool? autoTearDown = true, + Element? container, + Callback? autoTearDownCallback}) { var renderedInstance; component = component is component_base.UiProps ? component() : component; @@ -68,7 +69,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; renderedInstance = react_dom.render(component, container); } - if (autoTearDown/*!*/) { + if (autoTearDown!) { addTearDown(() { unmount(renderedInstance); if (autoTearDownCallback != null) autoTearDownCallback(); @@ -84,7 +85,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; /// [autoTearDown] to false. /// /// See: . -ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Callback/*?*/ autoTearDownCallback}) { +ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Callback? autoTearDownCallback}) { var renderer = react_test_utils.createRenderer(); if (autoTearDown) { addTearDown(() { @@ -106,7 +107,7 @@ ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Cal void unmount(dynamic instanceOrContainerNode) { if (instanceOrContainerNode == null) return; - /*late*/Element containerNode; + late Element? containerNode; if (instanceOrContainerNode is Element) { containerNode = instanceOrContainerNode; @@ -136,7 +137,7 @@ void unmount(dynamic instanceOrContainerNode) { /// > If [component] is a function component, calling [renderAndGetDom] will throw a `StateError`. /// > /// > See `TestJacket.getNode` for more information about this limitation. -Element/*?*/ renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback/*?*/ autoTearDownCallback}) { +Element? renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback? autoTearDownCallback}) { final renderedInstance = render(component, autoTearDown: autoTearDown, autoTearDownCallback: autoTearDownCallback); if (!react_test_utils.isCompositeComponent(renderedInstance) && !react_test_utils.isDOMComponent(renderedInstance)) { @@ -152,8 +153,8 @@ Element/*?*/ renderAndGetDom(dynamic component, {bool autoTearDown = true, Callb /// > If [component] is a function component, calling [renderAndGetComponent] will throw a `StateError`. /// > /// > See `TestJacket.getInstance` for more information about this limitation. -react.Component renderAndGetComponent(dynamic component, - {bool autoTearDown = true, Callback autoTearDownCallback}) { +react.Component? renderAndGetComponent(dynamic component, + {bool autoTearDown = true, Callback? autoTearDownCallback}) { final renderedInstance = render(component, autoTearDown: autoTearDown, autoTearDownCallback: autoTearDownCallback); // [1] Adding an additional check for dom components here because the current behavior when `renderedInstance` is @@ -177,9 +178,9 @@ List _attachedReactContainers = []; /// /// Returns the rendered component. /* [1] */ renderAttachedToDocument(dynamic component, - {bool/*?*/ autoTearDown = true, - Element/*?*/ container, - Callback/*?*/ autoTearDownCallback}) { + {bool? autoTearDown = true, + Element? container, + Callback? autoTearDownCallback}) { container ??= DivElement() // Set arbitrary height and width for container to ensure nothing is cut off. ..style.setProperty('width', '800px') @@ -187,12 +188,12 @@ List _attachedReactContainers = []; setComponentZone(); - document.body/*!*/.append(container); + document.body!.append(container); - if (autoTearDown/*!*/) { + if (autoTearDown!) { addTearDown(() { react_dom.unmountComponentAtNode(container); - container/*!*/.remove(); + container!.remove(); if (autoTearDownCallback != null) autoTearDownCallback(); }); } else { @@ -211,7 +212,7 @@ void tearDownAttachedNodes() { } } -typedef void _EventSimulatorAlias(componentOrNode, [Map/*?*/ eventData]); +typedef void _EventSimulatorAlias(componentOrNode, [Map? eventData]); /// Helper function to simulate clicks final _EventSimulatorAlias click = react_test_utils.Simulate.click; @@ -244,11 +245,11 @@ final _EventSimulatorAlias mouseDown = react_test_utils.Simulate.mouseDown; final _EventSimulatorAlias mouseUp = react_test_utils.Simulate.mouseUp; /// Helper function to simulate mouseEnter events. -final _EventSimulatorAlias mouseEnter = (componentOrNode, [Map/*?*/ eventData = const {}]) => +final _EventSimulatorAlias mouseEnter = (componentOrNode, [Map? eventData = const {}]) => Simulate._mouseEnter(componentOrNode, jsifyAndAllowInterop(eventData)); /// Helper function to simulate mouseLeave events. -final _EventSimulatorAlias mouseLeave = (componentOrNode, [Map/*?*/ eventData = const {}]) => +final _EventSimulatorAlias mouseLeave = (componentOrNode, [Map? eventData = const {}]) => Simulate._mouseLeave(componentOrNode, jsifyAndAllowInterop(eventData)); @JS('React.addons.TestUtils.Simulate') @@ -261,7 +262,7 @@ abstract class Simulate { } /// Returns whether [props] contains [key] with a value set to a space-delimited string containing [value]. -bool _hasTestId(Map props, String key, String/*!*/ value) { +bool _hasTestId(Map props, String key, String value) { var testId = props[key]; return testId != null && splitSpaceDelimitedString(testId.toString()).contains(value); } @@ -296,7 +297,7 @@ bool _hasTestId(Map props, String key, String/*!*/ value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -/* [1] */ getByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { +/* [1] */ getByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { final results = getAllByTestId(root, value, key: key); return results.isEmpty ? null : results.first; } @@ -343,7 +344,7 @@ bool _hasTestId(Map props, String key, String/*!*/ value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -List /* < [1] > */ getAllByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { +List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { if (root is react.Component) root = root.jsThis; if (isValidElement(root)) { @@ -351,9 +352,9 @@ List /* < [1] > */ getAllByTestId(dynamic root, String/*!*/ value, {String key = } return react_test_utils.findAllInRenderedTree(root, allowInterop((descendant) { - Map/*?*/ props; + Map? props; if (react_test_utils.isDOMComponent(descendant)) { - props = findDomNode(descendant)/*!*/.attributes; + props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } @@ -381,10 +382,10 @@ List /* < [1] > */ getAllByTestId(dynamic root, String/*!*/ value, {String key = /// /// // This returns [ `` ] /// getAllComponentsByTestId(root, 'foo') -List getAllComponentsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) => +List getAllComponentsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) => getAllByTestId(root, value, key: key) .map((element) => getDartComponent(element)) // ignore: unnecessary_lambdas - .where((component) => component != null) + .whereNotNull() .toList(); /// Returns the [Element] of the first descendant of [root] that has its [key] prop value set to [value]. @@ -415,7 +416,7 @@ List getAllComponentsByTestId(dynamic root, S /// getComponentRootDomByTestId(renderedInstance, 'value'); // returns the `outer` `
` /// /// Related: [queryByTestId]. -Element/*?*/ getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +Element? getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { return findDomNode(getByTestId(root, value, key: key)); } @@ -450,8 +451,8 @@ Element/*?*/ getComponentRootDomByTestId(dynamic root, String value, {String key /// queryByTestId(renderedInstance, 'value'); // returns the `inner` `
` /// /// Related: [queryAllByTestId], [getComponentRootDomByTestId]. -Element/*?*/ queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int/*?*/ shadowDepth}) { - var results = _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: false, depth: shadowDepth); +Element? queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) { + var results = _findDeep(findDomNode(root)!, _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: false, depth: shadowDepth); return results.isNotEmpty ? results.first : null; } @@ -490,15 +491,15 @@ Element/*?*/ queryByTestId(dynamic root, String value, {String key = defaultTest ///
/// /// queryAllByTestId(renderedInstance, 'value'); // returns both `inner` `
`s -List queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int/*?*/ shadowDepth}) { - return _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: true, depth: shadowDepth); +List queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) { + return _findDeep(findDomNode(root)!, _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: true, depth: shadowDepth); } String _makeTestIdSelector(String value, {String key = defaultTestIdKey}) => '[$key~="$value"]'; -List _findDeep(Node/*!*/ root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int/*?*/ depth}) { +List _findDeep(Node root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int? depth}) { List nodes = []; - void recursiveSeek(Node/*!*/ _root, int _currentDepth) { + void recursiveSeek(Node _root, int _currentDepth) { // The LHS type prevents `rootQuerySelectorAll` from returning `_FrozenElementList>` instead of `` in DDC final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : null; nodes.addAll(rootQuerySelectorAll(itemSelector)); @@ -508,7 +509,7 @@ List _findDeep(Node/*!*/ root, String itemSelector, {bool searchInShado // This method of finding shadow roots may not be performant, but it's good enough for usage in tests. if (searchInShadowDom && (depth == null || _currentDepth < depth)) { var foundShadows = rootQuerySelectorAll('*').where((el) => el.shadowRoot != null).map((el) => el.shadowRoot).toList(); - foundShadows.forEach((shadowRoot) => recursiveSeek(shadowRoot, _currentDepth + 1)); + foundShadows.forEach((shadowRoot) => recursiveSeek(shadowRoot!, _currentDepth + 1)); } } recursiveSeek(root, 0); @@ -518,7 +519,7 @@ List _findDeep(Node/*!*/ root, String itemSelector, {bool searchInShado /// Returns the [react.Component] of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -react.Component/*?*/ getComponentByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { +react.Component? getComponentByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getDartComponent(instance); @@ -530,7 +531,7 @@ react.Component/*?*/ getComponentByTestId(dynamic root, String/*!*/ value, {Stri /// Returns the props of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -Map/*?*/ getPropsByTestId(dynamic root, String/*!*/ value, {String key = defaultTestIdKey}) { +Map? getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getProps(instance); @@ -539,7 +540,7 @@ Map/*?*/ getPropsByTestId(dynamic root, String/*!*/ value, {String key = default return null; } -List _getAllByTestIdShallow(ReactElement/*!*/ root, String/*!*/ value, {String key = defaultTestIdKey}) { +List _getAllByTestIdShallow(ReactElement root, String value, {String key = defaultTestIdKey}) { Iterable flattenChildren(dynamic children) sync* { if (children is Iterable) { yield* children.expand(flattenChildren); @@ -548,7 +549,7 @@ List _getAllByTestIdShallow(ReactElement/*!*/ root, String/*! } } - final matchingDescendants = []; + final matchingDescendants = []; var breadthFirstDescendants = Queue()..add(root); while (breadthFirstDescendants.isNotEmpty) { @@ -575,9 +576,9 @@ List findDescendantsWithProp(/* [1] */ root, dynamic propKey) { return false; } - Map/*?*/ props; + Map? props; if (react_test_utils.isDOMComponent(descendant)) { - props = findDomNode(descendant)/*!*/.attributes; + props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index 0ae9b1da..27d95997 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -160,17 +160,17 @@ void verifyValidationWarning(dynamic warningMatcher) { /// [startRecordingValidationWarnings] was first called. /// /// > Related: [clearValidationWarnings] -List getValidationWarnings() => _validationWarnings?.toList(); +List? getValidationWarnings() => _validationWarnings?.toList(); /// Clears the list of [ValidationUtil.warn]ings that have been recorded since /// [startRecordingValidationWarnings] was first called. /// /// > Related: [getValidationWarnings] void clearValidationWarnings() { - _validationWarnings.clear(); + _validationWarnings!.clear(); } -List/*?*/ _validationWarnings; +List? _validationWarnings; void _recordValidationWarning(String warningMessage) { - _validationWarnings/*!*/.add(warningMessage); + _validationWarnings!.add(warningMessage); } diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index a69ef6bb..6ec539f1 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -17,7 +17,7 @@ import 'dart:async'; import 'package:react/react_client.dart'; import 'package:test/test.dart'; -Zone/*?*/ _zone; +Zone? _zone; /// Validates that [storeZone] was called before [zonedExpect] was. void validateZone() { @@ -28,7 +28,7 @@ void validateZone() { /// Store the specified _(or current if none is specified)_ [zone] /// for use within [zonedExpect]. -void storeZone([Zone/*?*/ zone]) { +void storeZone([Zone? zone]) { if (zone == null) { zone = Zone.current; } @@ -38,10 +38,10 @@ void storeZone([Zone/*?*/ zone]) { /// Calls [expect] in package:test/test.dart in the zone stored in [storeZone]. /// /// Useful for expectations in blocks called in other zones. -void zonedExpect(actual, matcher, {String/*?*/ reason}) { +void zonedExpect(actual, matcher, {String? reason}) { validateZone(); - return _zone/*!*/.run(() { + return _zone!.run(() { expect(actual, matcher, reason: reason); }); } @@ -73,6 +73,6 @@ void zonedExpect(actual, matcher, {String/*?*/ reason}) { /// renderIntoDocument(( /// TestComponent()..onComponentDidMount = shouldPassTest)()); // Passes /// }); -void setComponentZone([Zone/*?*/ zone]) { +void setComponentZone([Zone? zone]) { componentZone = zone ?? Zone.current; } diff --git a/pubspec.yaml b/pubspec.yaml index 11e9c7f4..e29d062f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ version: 2.11.5 description: A library for testing OverReact components homepage: https://github.com/Workiva/over_react_test/ environment: - sdk: ">=2.11.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: js: ^0.6.1+1 @@ -12,6 +12,7 @@ dependencies: over_react: ^4.1.2 react: ^6.0.1 test: ^1.15.7 + collection: ^1.15.0-nullsafety.4 dev_dependencies: build_runner: ^2.1.2 build_test: ^2.1.3 diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index afb030ed..d0e052bb 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -48,7 +48,7 @@ main() { }); group('should skip checking for certain props', () { - final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()())/*!*/; + final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()())!; final consumedKeys = meta.forMixin(new_boilerplate.ShouldNotBeForwardedProps).keys; final skippedKey = consumedKeys.first; @@ -93,7 +93,7 @@ main() { group('does not call `factory` directly within the consuming group', () { void sharedTest( BuilderOnlyUiFactory factory, { - List Function(PropsMetaCollection)/*?*/ getUnconsumedPropKeys, + List Function(PropsMetaCollection)? getUnconsumedPropKeys, }) { var wasFactoryCalled = false; @@ -158,10 +158,10 @@ main() { /// Declares a [group] in which tests declared via [testFunction] are expected to fail /// with an error matching [testFailureMatcher]. @isTestGroup - void expectedFailGroup(String description, void Function() groupBody, {@required dynamic testFailureMatcher}) { + void expectedFailGroup(String description, void Function() groupBody, {required dynamic testFailureMatcher}) { group(description, () { int totalTestCount = 0; - /*late*/List testFailureErrors; + late List testFailureErrors; setUpAll(() => testFailureErrors = []); void testButReAndIgnoreExceptions(name, testBody) { @@ -199,7 +199,7 @@ main() { }); expectedFailGroup('forwards consumed props -', () { - final factory = registerHelperComponent( + final UiProps Function([Map]) factory = registerHelperComponent( propsMeta: testPropsMeta, consumedProps: testPropsMeta.all, render: (component) => (Wrapper()..addAll(component.props))(), @@ -213,7 +213,7 @@ main() { }, testFailureMatcher: contains('Unexpected keys on forwarding target')); expectedFailGroup('does not forward all of the unconsumed props in propsMeta -', () { - var factory = registerHelperComponent( + UiProps Function([Map]) factory = registerHelperComponent( propsMeta: testPropsMeta, consumedProps: [], render: (component) => (Wrapper() @@ -249,10 +249,10 @@ typedef HelperRenderFunction = dynamic Function(CommonHelperComponent component) const UiFactory arbitraryUiFactory = domProps; UiFactory registerHelperComponent({ - @required HelperRenderFunction render, - Map/*?*/ defaultProps, - Iterable/*?*/ consumedProps, - PropsMetaCollection/*?*/ propsMeta, + required HelperRenderFunction render, + Map? defaultProps, + Iterable? consumedProps, + PropsMetaCollection? propsMeta, }) { final factory = registerComponent2(() { return CommonHelperComponent( @@ -263,7 +263,7 @@ UiFactory registerHelperComponent({ ); }); - return ([Map/*?*/ backingMap]) => arbitraryUiFactory(backingMap)..componentFactory = factory; + return ([Map? backingMap]) => arbitraryUiFactory(backingMap)..componentFactory = factory; } class CommonHelperComponent extends UiComponent2 { @@ -273,10 +273,10 @@ class CommonHelperComponent extends UiComponent2 { final HelperRenderFunction renderValue; CommonHelperComponent({ - @required Map/*?*/ defaultPropsValue, - @required Iterable/*?*/ consumedPropsValue, - @required PropsMetaCollection/*?*/ propsMetaValue, - @required this.renderValue, + required Map? defaultPropsValue, + required Iterable? consumedPropsValue, + required PropsMetaCollection? propsMetaValue, + required this.renderValue, }) : defaultPropsValue = defaultPropsValue ?? {}, propsMetaValue = propsMetaValue ?? const PropsMetaCollection({}), @@ -305,7 +305,7 @@ class CommonHelperComponent extends UiComponent2 { @override typedPropsFactoryJs(map) => typedPropsFactory(map); - UiProps _cachedTypedProps; + late UiProps _cachedTypedProps; @override UiProps get props => _cachedTypedProps; diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index 0254f2e2..9eb900ab 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -75,7 +75,7 @@ main() { configuration: errorConfig); expect(logs, hasLength(2)); - expect(logs.firstWhere((log) => log.contains('shouldAlwaysBeFalse')), + expect(logs.firstWhere((log) => log!.contains('shouldAlwaysBeFalse')), contains('set to true')); }); @@ -226,14 +226,14 @@ main() { var jacket = mount(Sample()(), attachedToDocument: true); var logs = await recordConsoleLogsAsync(() async { var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); }, configuration: warnConfig); expect(logs, hasLength(1)); - expect(logs.first/*!*/.contains('I have been clicked'), isTrue); + expect(logs.first!.contains('I have been clicked'), isTrue); }); test('handles errors caused when rendering', () async { @@ -298,7 +298,7 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); @@ -312,7 +312,7 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')/*!*/; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; await Future.delayed(Duration(milliseconds: 5)); triggerDocumentClick(button); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index 9f19ab4e..f3fc4204 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -26,7 +26,7 @@ import './helper_components/sample_component2.dart'; /// Main entry point for CustomMatchers testing main() { group('CustomMatcher', () { - Element testElement; + late Element testElement; setUp(() { testElement = Element.div(); @@ -383,14 +383,14 @@ main() { List allAttachedNodes = []; Element makeAttachedNode() { var node = DivElement()..tabIndex = 1; - document.body/*!*/.append(node); + document.body!.append(node); allAttachedNodes.add(node); return node; } - Element attachedNode; + late Element attachedNode; setUp(() { attachedNode = makeAttachedNode(); @@ -445,7 +445,7 @@ main() { group('LoggingFunctionMatcher', () { group('when passed a List of logs', () { - List logs; + late List logs; setUp(() { logs = [ @@ -607,7 +607,7 @@ main() { group('PropTypeLogMatcher', () { group('when passed a List of logs', () { - List logs; + late List logs; setUp(() { logs = [ @@ -865,7 +865,7 @@ void shouldFail(value, Matcher matcher, expected) { if (expected is String) { expect(_errorString, equalsIgnoringWhitespace(expected)); } else { - expect(_errorString/*!*/.replaceAll(RegExp(r'[\s\n]+'), ' '), expected); + expect(_errorString!.replaceAll(RegExp(r'[\s\n]+'), ' '), expected); } } diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index a3633359..60a43246 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -23,17 +23,17 @@ main() { test('triggerTransitionEnd correctly dispatches a transitionend event', () async { var flag = false; - document.body/*!*/.onTransitionEnd.listen((Event event) { + document.body!.onTransitionEnd.listen((Event event) { flag = true; }); - await triggerTransitionEnd(document.body/*!*/); + await triggerTransitionEnd(document.body!); expect(flag, isTrue); }); group('triggerDocumentClick correctly dispatches a click event', () { - var flag; + late var flag; setUp((){ flag = false; @@ -42,7 +42,7 @@ main() { test('when the target is attached to the document', () { var renderedInstance = renderAttachedToDocument((Dom.div()..onClick = ((_) => flag = true))()); - triggerDocumentClick(findDomNode(renderedInstance)/*!*/); + triggerDocumentClick(findDomNode(renderedInstance)!); expect(flag, isTrue); }); @@ -50,13 +50,13 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onClick = ((_) => flag = true))()); - expect(() => triggerDocumentClick(findDomNode(renderedInstance)/*!*/), throwsArgumentError); + expect(() => triggerDocumentClick(findDomNode(renderedInstance)!), throwsArgumentError); expect(flag, isFalse); }); }); group('triggerDocumentMouseEvent correctly dispatches an event', () { - var flag; + late var flag; setUp((){ flag = false; @@ -65,7 +65,7 @@ main() { test('when the target is attached to the document', () { var renderedInstance = renderAttachedToDocument((Dom.div()..onMouseDown = ((_) => flag = true))()); - triggerDocumentMouseEvent(findDomNode(renderedInstance)/*!*/, 'mousedown'); + triggerDocumentMouseEvent(findDomNode(renderedInstance)!, 'mousedown'); expect(flag, isTrue); }); @@ -73,13 +73,13 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onMouseDown = ((_) => flag = true))()); - expect(() => triggerDocumentMouseEvent(findDomNode(renderedInstance)/*!*/, 'mousedown'), throwsArgumentError); + expect(() => triggerDocumentMouseEvent(findDomNode(renderedInstance)!, 'mousedown'), throwsArgumentError); expect(flag, isFalse); }); }); group('triggerFocus correctly dispatches a focus event', () { - var flag; + late var flag; setUp((){ flag = false; @@ -91,7 +91,7 @@ main() { ..tabIndex = '1' )()); - await triggerFocus(findDomNode(renderedInstance)/*!*/); + await triggerFocus(findDomNode(renderedInstance)!); expect(flag, isTrue); }); @@ -99,7 +99,7 @@ main() { test('and throws when the target is not attached to the document', () { var renderedInstance = render((Dom.div()..onFocus = ((_) => flag = true))()); - expect(() => triggerFocus(findDomNode(renderedInstance)/*!*/), throwsArgumentError); + expect(() => triggerFocus(findDomNode(renderedInstance)!), throwsArgumentError); expect(flag, isFalse); }); }); diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 02ec4ed4..69562e37 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -27,15 +27,15 @@ main() { group('mount: renders the given instance', () { group('attached to the document', () { group('and unmounts after the test is done', () { - /*late*/TestJacket jacket; + late TestJacket? jacket; setUp(() { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); }); tearDown(() { - expect(document.body/*!*/.children, isEmpty); - expect(jacket.isMounted, isFalse); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isFalse); jacket = null; }); @@ -44,34 +44,34 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode); - expect(document.body/*!*/.children[0], mountNode); - expect(jacket/*!*/.isMounted, isTrue); - expect(mountNode.children[0], jacket/*!*/.getNode()); + expect(document.body!.children[0], mountNode); + expect(jacket!.isMounted, isTrue); + expect(mountNode.children[0], jacket!.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true); - expect(jacket/*!*/.isMounted, isTrue); - expect(document.body/*!*/.children[0].children[0], jacket/*!*/.getNode()); + expect(jacket!.isMounted, isTrue); + expect(document.body!.children[0].children[0], jacket!.getNode()); }); }); group('and does not unmount after the test is done', () { - /*late*/TestJacket/*!*/ jacket; + late TestJacket jacket; setUp(() { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); }); tearDown(() { - expect(document.body.children, isNotEmpty); - expect(jacket/*!*/.isMounted, isTrue); + expect(document.body!.children, isNotEmpty); + expect(jacket!.isMounted, isTrue); - jacket/*!*/.unmount(); + jacket!.unmount(); - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isFalse); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isFalse); jacket = null; }); @@ -84,32 +84,32 @@ main() { autoTearDown: false ); - expect(document.body/*!*/.children[0], mountNode); - expect(jacket/*!*/.isMounted, isTrue); - expect(mountNode.children[0], jacket/*!*/.getNode()); + expect(document.body!.children[0], mountNode); + expect(jacket!.isMounted, isTrue); + expect(mountNode.children[0], jacket!.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true, autoTearDown: false); - expect(jacket/*!*/.isMounted, isTrue); - expect(document.body/*!*/.children[0].children[0], jacket/*!*/.getNode()); + expect(jacket!.isMounted, isTrue); + expect(document.body!.children[0].children[0], jacket!.getNode()); }); }); }); group('not attached to the document', () { group('and unmounts after the test is done', () { - /*late*/TestJacket jacket; + late TestJacket? jacket; setUp(() { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); }); tearDown(() { - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isFalse); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isFalse); jacket = null; }); @@ -118,33 +118,33 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), mountNode: mountNode); - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isTrue); - expect(mountNode.children[0], jacket/*!*/.getNode()); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isTrue); + expect(mountNode.children[0], jacket!.getNode()); }); test('without the given container', () { jacket = mount(Sample()()); - expect(jacket/*!*/.isMounted, isTrue); + expect(jacket!.isMounted, isTrue); }); }); group('and does not unmount after the test is done', () { - /*late*/TestJacket jacket; + late TestJacket? jacket; setUp(() { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); }); tearDown(() { - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isTrue); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isTrue); - jacket/*!*/.unmount(); + jacket!.unmount(); - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isFalse); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isFalse); jacket = null; }); @@ -153,23 +153,23 @@ main() { var mountNode = DivElement(); jacket = mount(Sample()(), mountNode: mountNode, autoTearDown: false); - expect(document.body/*!*/.children.isEmpty, isTrue); - expect(jacket/*!*/.isMounted, isTrue); - expect(mountNode.children[0], jacket/*!*/.getNode()); + expect(document.body!.children.isEmpty, isTrue); + expect(jacket!.isMounted, isTrue); + expect(mountNode.children[0], jacket!.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), autoTearDown: false); - expect(document.body/*!*/.children, isEmpty); - expect(jacket/*!*/.isMounted, isTrue); + expect(document.body!.children, isEmpty); + expect(jacket!.isMounted, isTrue); }); }); }); }); group('TestJacket: composite component:', () { - TestJacket jacket; + late TestJacket jacket; setUp(() { var mountNode = DivElement(); @@ -179,7 +179,7 @@ main() { ); expect(Sample(jacket.getProps()).foo, isFalse); - expect(jacket.getDartInstance()/*!*/.state.bar, isFalse); + expect(jacket.getDartInstance()!.state.bar, isFalse); }); test('rerender', () { @@ -201,9 +201,9 @@ main() { }); test('setState', () { - jacket.setState(jacket.getDartInstance()/*!*/.newState()..bar = true); + jacket.setState(jacket.getDartInstance()!.newState()..bar = true); - expect(jacket.getDartInstance()/*!*/.state.bar, isTrue); + expect(jacket.getDartInstance()!.state.bar, isTrue); }); test('unmount', () { @@ -216,8 +216,8 @@ main() { }); group('TestJacket: DOM component:', () { - /*late*/Element mountNode; - TestJacket jacket; + late Element? mountNode; + late TestJacket jacket; setUp(() { mountNode = DivElement(); @@ -226,18 +226,18 @@ main() { attachedToDocument: true ); - expect(mountNode.children.single, isA()); + expect(mountNode!.children.single, isA()); }); tearDown(() { - mountNode.remove(); + mountNode!.remove(); mountNode = null; }); test('rerender', () { jacket.rerender((Dom.span()..id = 'foo')()); - expect(mountNode.children.single.id, 'foo'); + expect(mountNode!.children.single.id, 'foo'); }); test('getProps throws a StateError', () { @@ -245,7 +245,7 @@ main() { }); test('getNode', () { - expect(jacket.getNode(), mountNode.children.single); + expect(jacket.getNode(), mountNode!.children.single); }); test('getDartInstance returns null', () { @@ -266,8 +266,8 @@ main() { }); group('TestJacket: function component:', () { - /*late*/Element mountNode; - TestJacket jacket; + late Element? mountNode; + late TestJacket jacket; setUp(() { mountNode = DivElement(); @@ -276,18 +276,18 @@ main() { attachedToDocument: true ); - expect(mountNode/*!*/.children.single.id, 'foo'); + expect(mountNode!.children.single.id, 'foo'); }); tearDown(() { - mountNode/*!*/.remove(); + mountNode!.remove(); mountNode = null; }); test('rerender', () { jacket.rerender(testFunctionComponent({'id': 'bar'})); - expect(mountNode/*!*/.children.single.id, 'bar'); + expect(mountNode!.children.single.id, 'bar'); }); test('getProps throws a StateError', () { diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index 88665784..c5271f8f 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -59,37 +59,37 @@ main() { reason: 'The React instance should have been unmounted.' ); - expect(document.body/*!*/.children, isEmpty, reason: 'All attached mount points should have been removed.'); + expect(document.body!.children, isEmpty, reason: 'All attached mount points should have been removed.'); }); test('renderAttachedToDocument renders the component into the document', () { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); renderedInstance = renderAttachedToDocument(Wrapper()); - expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body!.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); }); test('renderAttachedToDocument renders the component into the document with a given container', () { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); var container = DivElement(); renderedInstance = renderAttachedToDocument(Wrapper(), container: container); - expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body!.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); - expect(document.body/*!*/.children[0], container); + expect(document.body!.children[0], container); }); }); test('renderAttachedToDocument renders the component into the document and tearDownAttachedNodes cleans them up', () { - expect(document.body/*!*/.children, isEmpty); + expect(document.body!.children, isEmpty); var renderedInstance = renderAttachedToDocument(Wrapper(), autoTearDown: false); - expect(document.body/*!*/.children[0].children.contains(findDomNode(renderedInstance)), isTrue, + expect(document.body!.children[0].children.contains(findDomNode(renderedInstance)), isTrue, reason: 'The component should have been rendered into the container div.'); tearDownAttachedNodes(); @@ -102,7 +102,7 @@ main() { reason: 'The React instance should have been unmounted.' ); - expect(document.body/*!*/.children, isEmpty, reason: 'All attached mount points should have been removed.'); + expect(document.body!.children, isEmpty, reason: 'All attached mount points should have been removed.'); }); group('renderAndGetDom', () { @@ -145,7 +145,7 @@ main() { test('simulates a click on a component with additional event data', () { var flag = false; - SyntheticMouseEvent event; + late SyntheticMouseEvent event; var renderedInstance = render((Dom.div() ..onClick = (evt) { flag = true; @@ -253,9 +253,9 @@ main() { }); group('getByTestId returns', () { - sharedTests({bool/*?*/ shallow}) { + sharedTests({bool? shallow}) { testSpecificRender(ReactElement instance) => - shallow/*!*/ ? renderShallow(instance) : render(instance); + shallow! ? renderShallow(instance) : render(instance); group('the single descendant that has the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -461,9 +461,9 @@ main() { }); group('getAllByTestId returns', () { - sharedTests({bool/*?*/ shallow}) { + sharedTests({bool? shallow}) { testSpecificRender(ReactElement instance) => - shallow/*!*/ ? renderShallow(instance) : render(instance); + shallow! ? renderShallow(instance) : render(instance); group('a list containing the single descendant that have the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -683,7 +683,7 @@ main() { group('getAllComponentsByTestId returns only the Dart components with the matching test ID', () { void sharedExpectations( List allByTestId, - List allComponentsByTestId, + List allComponentsByTestId, ) { final isCompositeCOmponentMatcher = predicate(rtu.isCompositeComponent, 'is composite component'); @@ -750,7 +750,7 @@ main() { group('`data-test-id` html attribute key', () { test('', () { var renderedInstance = render((Nested()..addTestId('value'))()); - var innerNode = findDomNode(renderedInstance)/*!*/.querySelector('[data-test-id~="inner"]'); + var innerNode = findDomNode(renderedInstance)!.querySelector('[data-test-id~="inner"]'); expect(queryByTestId(renderedInstance, 'value'), innerNode); }); @@ -764,7 +764,7 @@ main() { test('custom html attribute key', () { var renderedInstance = render((Nested()..addTestId('value', key: 'data-custom-id'))()); - var innerNode = findDomNode(renderedInstance)/*!*/.querySelector('[data-test-id~="inner"]'); + var innerNode = findDomNode(renderedInstance)!.querySelector('[data-test-id~="inner"]'); expect(queryByTestId(renderedInstance, 'value', key: 'data-custom-id'), innerNode); }); @@ -788,7 +788,7 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var innerNode = shadowHostRef.current/*!*/.shadowRoot/*!*/.querySelector('[data-test-id~="$searchId"]'); + var innerNode = shadowHostRef.current!.shadowRoot!.querySelector('[data-test-id~="$searchId"]'); expect(queryByTestId(jacket.mountNode, searchId, searchInShadowDom: true), innerNode); }); @@ -817,7 +817,7 @@ main() { (Nested()..addTestId('value'))(), (Nested()..addTestId('value'))(), )); - var innerNodes = findDomNode(renderedInstance)/*!*/.querySelectorAll('[data-test-id~="inner"]'); + var innerNodes = findDomNode(renderedInstance)!.querySelectorAll('[data-test-id~="inner"]'); expect(queryAllByTestId(renderedInstance, 'value'), innerNodes); }); @@ -834,7 +834,7 @@ main() { (Nested()..addTestId('value'))(), (Nested()..addTestId('value'))(), )); - var innerNodes = findDomNode(renderedInstance)/*!*/.querySelectorAll('[data-test-id~="inner"]'); + var innerNodes = findDomNode(renderedInstance)!.querySelectorAll('[data-test-id~="inner"]'); expect(queryAllByTestId(renderedInstance, 'value'), innerNodes); }); @@ -878,9 +878,9 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var level1 = shadow1Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div1'); - var level2 = shadow2Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div2'); - var level3 = shadow3Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div3'); + var level1 = shadow1Ref.current!.shadowRoot!.querySelector('.div1'); + var level2 = shadow2Ref.current!.shadowRoot!.querySelector('.div2'); + var level3 = shadow3Ref.current!.shadowRoot!.querySelector('.div3'); expect(queryAllByTestId(jacket.mountNode, 'findMe', searchInShadowDom: true), [level1, level2, level3]); }); @@ -919,7 +919,7 @@ main() { // Let the shadow dom mount (the test components kinda slow since it does it after adding it to the dom.) await pumpEventQueue(); - var level1 = shadow1Ref.current/*!*/.shadowRoot/*!*/.querySelector('.div1'); + var level1 = shadow1Ref.current!.shadowRoot!.querySelector('.div1'); expect(queryAllByTestId(jacket.mountNode, 'findMe', searchInShadowDom: true, shadowDepth: 1), [level1]); }); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index 35ca279a..293a66ea 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -30,7 +30,7 @@ UiFactory ShadowNested = uiForwardRef( useEffect(() { var shadowRootFirstChild = DivElement()..dataset['test-id'] = props.shadowRootFirstChildTestId ?? 'shadowRootFirstChild'; - divRef.current/*!*/.attachShadow({'mode':'open'}).append(shadowRootFirstChild); + divRef.current!.attachShadow({'mode':'open'}).append(shadowRootFirstChild); react_dom.render(Fragment()(props.children), shadowRootFirstChild); return () => react_dom.unmountComponentAtNode(shadowRootFirstChild); }, []); diff --git a/test/over_react_test/utils/test_common_component.dart b/test/over_react_test/utils/test_common_component.dart index 1505be76..a116d3a4 100644 --- a/test/over_react_test/utils/test_common_component.dart +++ b/test/over_react_test/utils/test_common_component.dart @@ -57,7 +57,7 @@ abstract class PropsThatShouldBeForwarded { Map get props; - bool/*?*/ foo; + bool? foo; } @PropsMixin() @@ -69,7 +69,7 @@ abstract class PropsThatShouldNotBeForwarded { Map get props; - bool/*?*/ bar; + bool? bar; } // AF-3369 This will be removed once the transition to Dart 2 is complete. diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index 2259b24c..fd69a28a 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -23,13 +23,13 @@ UiFactory TestCommonRequired = @Props() class _$TestCommonRequiredProps extends UiProps { @nullableRequiredProp - bool/*?*/ foobar; + bool? foobar; @requiredProp - bool/*?*/ bar; + bool? bar; @nullableRequiredProp - bool/*?*/ defaultFoo; + bool? defaultFoo; } @Component() diff --git a/test/over_react_test/validation_util_test.dart b/test/over_react_test/validation_util_test.dart index 6eb915b2..b94f069a 100644 --- a/test/over_react_test/validation_util_test.dart +++ b/test/over_react_test/validation_util_test.dart @@ -34,7 +34,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings()/*!*/.single, 'message1'); + expect(getValidationWarnings()!.single, 'message1'); assert(ValidationUtil.warn('message2')); @@ -48,7 +48,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings()/*!*/.single, 'message1'); + expect(getValidationWarnings()!.single, 'message1'); stopRecordingValidationWarnings(); @@ -94,7 +94,7 @@ main() { assert(ValidationUtil.warn('message1')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings()/*!*/.single, 'message1'); + expect(getValidationWarnings()!.single, 'message1'); clearValidationWarnings(); @@ -103,7 +103,7 @@ main() { assert(ValidationUtil.warn('message2')); expect(getValidationWarnings(), hasLength(1)); - expect(getValidationWarnings()/*!*/.single, 'message2'); + expect(getValidationWarnings()!.single, 'message2'); }); }); }, testOn: '!js'); diff --git a/test/over_react_test/zone_render_tests.dart b/test/over_react_test/zone_render_tests.dart index 2e3a8f84..5a65fab5 100644 --- a/test/over_react_test/zone_render_tests.dart +++ b/test/over_react_test/zone_render_tests.dart @@ -9,7 +9,7 @@ import 'helper_components/sample_component.dart'; main() { group('TestJacket mount', () { - sharedZoneRenderTests(mount); + sharedZoneRenderTests(mount as dynamic Function(ReactElement, {bool? autoTearDown})); }); group('render', () { @@ -21,7 +21,7 @@ main() { }); } -void sharedZoneRenderTests(Function(ReactElement element, {bool/*?*/ autoTearDown}) renderFunction) { +void sharedZoneRenderTests(Function(ReactElement element, {bool? autoTearDown}) renderFunction) { group('sharedZoneRenderTests:', () { setUp(() { setComponentZone(Zone.root); From d3d0c4241aa6f2fbfd821a58335ff5e4504224f9 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Thu, 15 Jun 2023 18:45:39 -0500 Subject: [PATCH 04/22] WIP: Fix CI, Add version pin to force Null safety code gen --- .github/workflows/dart_ci.yml | 16 ----- lib/jacket.dart | 1 + lib/over_react_test.dart | 1 + .../common_component_util.dart | 3 +- .../over_react_test/console_log_utils.dart | 1 + lib/src/over_react_test/custom_matchers.dart | 5 +- lib/src/over_react_test/dart_util.dart | 1 + lib/src/over_react_test/dom_util.dart | 1 + lib/src/over_react_test/jacket.dart | 3 +- lib/src/over_react_test/js_component.dart | 1 + lib/src/over_react_test/props_meta.dart | 1 + lib/src/over_react_test/react_util.dart | 11 ++-- lib/src/over_react_test/test_helpers.dart | 1 + lib/src/over_react_test/validation_util.dart | 1 + .../over_react_test/wrapper_component.dart | 1 + lib/src/over_react_test/zone_util.dart | 1 + test/over_react_test.dart | 1 + .../common_component_util_test.dart | 1 + .../console_log_utils_test.dart | 1 + .../over_react_test/custom_matchers_test.dart | 1 + test/over_react_test/dom_util_test.dart | 1 + .../helper_components/sample_component.dart | 17 ++--- .../helper_components/sample_component2.dart | 3 +- .../sample_function_component.dart | 1 + test/over_react_test/jacket_test.dart | 65 +++++++++---------- test/over_react_test/react_util_test.dart | 1 + .../utils/nested_component.dart | 1 + .../utils/shadow_nested_component.dart | 5 +- .../utils/test_common_component.dart | 1 + .../utils/test_common_component_nested.dart | 1 + .../utils/test_common_component_nested2.dart | 1 + ...test_common_component_new_boilerplate.dart | 9 +-- .../test_common_component_required_props.dart | 1 + ..._component_required_props_commponent2.dart | 7 +- .../over_react_test/validation_util_test.dart | 1 + test/over_react_test/zone_render_tests.dart | 1 + 36 files changed, 91 insertions(+), 78 deletions(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 4e4e6efe..edbef171 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -71,14 +71,6 @@ jobs: name: ddc-test-results@${{ matrix.sdk }} path: reports/${{ matrix.sdk }}/ddc/test-results.json - - name: Report Unit Test Results - uses: dorny/test-reporter@v1 - if: ${{ always() && steps.install.outcome == 'success' }} - with: - name: Unit Test Results (ddc - ${{ matrix.sdk }}) - path: 'reports/${{ matrix.sdk }}/ddc/test-results.json' - reporter: dart-json - test_dart2js: permissions: id-token: write @@ -112,11 +104,3 @@ jobs: with: name: dart2js-test-results@${{ matrix.sdk }} path: reports/${{ matrix.sdk }}/dart2js/test-results.json - - - name: Report Unit Test Results - uses: dorny/test-reporter@v1 - if: ${{ always() && steps.install.outcome == 'success' }} - with: - name: Unit Test Results (dart2js - ${{ matrix.sdk }}) - path: 'reports/${{ matrix.sdk }}/dart2js/test-results.json' - reporter: dart-json diff --git a/lib/jacket.dart b/lib/jacket.dart index ef010982..cdac7242 100644 --- a/lib/jacket.dart +++ b/lib/jacket.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2018 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/over_react_test.dart b/lib/over_react_test.dart index b6c29058..7af7640f 100644 --- a/lib/over_react_test.dart +++ b/lib/over_react_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 18a712b5..87e25ce6 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -542,7 +543,7 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) requiredProps.add(prop.key); } - keyToErrorMessage[prop.key] = prop.errorMessage ?? ''; + keyToErrorMessage[prop.key] = prop.errorMessage; } } }); diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index dccff5ec..4875ed25 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index 09cf16e2..f7c044e5 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -120,11 +121,11 @@ class ClassNameMatcher extends Matcher { List descriptionParts = []; if (allowExtraneous) { - if (unwantedClasses!.isNotEmpty) { + if (unwantedClasses.isNotEmpty) { descriptionParts.add('has unwanted classes: $unwantedClasses'); } } else { - if (extraneousClasses!.isNotEmpty) { + if (extraneousClasses.isNotEmpty) { descriptionParts.add('has extraneous classes: $extraneousClasses'); } } diff --git a/lib/src/over_react_test/dart_util.dart b/lib/src/over_react_test/dart_util.dart index f28ced53..252fa61e 100644 --- a/lib/src/over_react_test/dart_util.dart +++ b/lib/src/over_react_test/dart_util.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 /// Returns whether `assert`s are enabled in the current runtime. /// /// Unless the Dart SDK option to enable `assert`s in dart2js is configured, diff --git a/lib/src/over_react_test/dom_util.dart b/lib/src/over_react_test/dom_util.dart index ed2b1e97..926cdfaf 100644 --- a/lib/src/over_react_test/dom_util.dart +++ b/lib/src/over_react_test/dom_util.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index ea7d8128..6e8d2e31 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -233,7 +234,7 @@ class TestJacket { void unmount() { _isMounted = false; react_util.unmount(_renderedInstance); - mountNode?.remove(); + mountNode.remove(); react_util.tearDownAttachedNodes(); } } diff --git a/lib/src/over_react_test/js_component.dart b/lib/src/over_react_test/js_component.dart index 86a55ebc..06d6dd64 100644 --- a/lib/src/over_react_test/js_component.dart +++ b/lib/src/over_react_test/js_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/props_meta.dart b/lib/src/over_react_test/props_meta.dart index d3e5b67c..c02ccbf9 100644 --- a/lib/src/over_react_test/props_meta.dart +++ b/lib/src/over_react_test/props_meta.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index d68d3023..6657c1bb 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -297,7 +297,7 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -/* [1] */ getByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +/* [1] */ getByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { final results = getAllByTestId(root, value, key: key); return results.isEmpty ? null : results.first; } @@ -344,7 +344,8 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +List /* < [1] > */ getAllByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { + if (value == null || value.toLowerCase() == 'null') return []; if (root is react.Component) root = root.jsThis; if (isValidElement(root)) { @@ -501,7 +502,7 @@ List _findDeep(Node root, String itemSelector, {bool searchInShadowDom List nodes = []; void recursiveSeek(Node _root, int _currentDepth) { // The LHS type prevents `rootQuerySelectorAll` from returning `_FrozenElementList>` instead of `` in DDC - final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : null; + final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : (String s) => []; nodes.addAll(rootQuerySelectorAll(itemSelector)); if (!findMany && nodes.isNotEmpty) { return; @@ -519,7 +520,7 @@ List _findDeep(Node root, String itemSelector, {bool searchInShadowDom /// Returns the [react.Component] of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -react.Component? getComponentByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +react.Component? getComponentByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getDartComponent(instance); @@ -531,7 +532,7 @@ react.Component? getComponentByTestId(dynamic root, String value, {String key = /// Returns the props of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -Map? getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { +Map? getPropsByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getProps(instance); diff --git a/lib/src/over_react_test/test_helpers.dart b/lib/src/over_react_test/test_helpers.dart index 61b41964..a1b4705d 100644 --- a/lib/src/over_react_test/test_helpers.dart +++ b/lib/src/over_react_test/test_helpers.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 import 'dart:async'; import 'package:test/test.dart'; diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index 27d95997..0b1096b4 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/wrapper_component.dart b/lib/src/over_react_test/wrapper_component.dart index c412a117..09ced9a3 100644 --- a/lib/src/over_react_test/wrapper_component.dart +++ b/lib/src/over_react_test/wrapper_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index 6ec539f1..e9d81e64 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test.dart b/test/over_react_test.dart index b99c51c4..4de30204 100644 --- a/test/over_react_test.dart +++ b/test/over_react_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index d0e052bb..23525234 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index 9eb900ab..7ac2c6f3 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index f3fc4204..99236f60 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index 60a43246..1726c4bd 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/helper_components/sample_component.dart b/test/over_react_test/helper_components/sample_component.dart index e6f560fc..6525afef 100644 --- a/test/over_react_test/helper_components/sample_component.dart +++ b/test/over_react_test/helper_components/sample_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 import 'dart:html'; import 'package:over_react/over_react.dart'; @@ -7,21 +8,21 @@ part 'sample_component.over_react.g.dart'; UiFactory Sample = castUiFactory(_$Sample); // ignore: undefined_identifier mixin SampleProps on UiProps { - bool shouldNeverBeNull; + late bool shouldNeverBeNull; - bool shouldAlwaysBeFalse; + late bool shouldAlwaysBeFalse; - bool shouldErrorInRender; + late bool shouldErrorInRender; - bool shouldErrorInMount; + late bool shouldErrorInMount; - bool shouldErrorInUnmount; + late bool shouldErrorInUnmount; - bool addExtraLogAndWarn; + late bool addExtraLogAndWarn; - Function() onComponentDidMount; + Function()? onComponentDidMount; - bool shouldLog; + late bool shouldLog; } class SampleComponent extends UiComponent2 { diff --git a/test/over_react_test/helper_components/sample_component2.dart b/test/over_react_test/helper_components/sample_component2.dart index 2f6a313e..e9799cd1 100644 --- a/test/over_react_test/helper_components/sample_component2.dart +++ b/test/over_react_test/helper_components/sample_component2.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 import 'dart:html'; import 'package:over_react/over_react.dart'; @@ -7,7 +8,7 @@ part 'sample_component2.over_react.g.dart'; UiFactory Sample2 = castUiFactory(_$Sample2); // ignore: undefined_identifier mixin Sample2Props on UiProps { - bool shouldNeverBeNull; + late bool shouldNeverBeNull; } class SampleComponent2 extends UiComponent2 { diff --git a/test/over_react_test/helper_components/sample_function_component.dart b/test/over_react_test/helper_components/sample_function_component.dart index 9e9470c4..7d596b61 100644 --- a/test/over_react_test/helper_components/sample_function_component.dart +++ b/test/over_react_test/helper_components/sample_function_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 69562e37..4893eaaf 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +28,7 @@ main() { group('mount: renders the given instance', () { group('attached to the document', () { group('and unmounts after the test is done', () { - late TestJacket? jacket; + late TestJacket jacket; setUp(() { expect(document.body!.children, isEmpty); @@ -35,9 +36,8 @@ main() { tearDown(() { expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isFalse); + expect(jacket.isMounted, isFalse); - jacket = null; }); test('with the given container', () { @@ -45,15 +45,15 @@ main() { jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode); expect(document.body!.children[0], mountNode); - expect(jacket!.isMounted, isTrue); - expect(mountNode.children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(mountNode.children[0], jacket.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true); - expect(jacket!.isMounted, isTrue); - expect(document.body!.children[0].children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(document.body!.children[0].children[0], jacket.getNode()); }); }); @@ -66,14 +66,13 @@ main() { tearDown(() { expect(document.body!.children, isNotEmpty); - expect(jacket!.isMounted, isTrue); + expect(jacket.isMounted, isTrue); - jacket!.unmount(); + jacket.unmount(); expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isFalse); + expect(jacket.isMounted, isFalse); - jacket = null; }); test('with the given container', () { @@ -85,23 +84,23 @@ main() { ); expect(document.body!.children[0], mountNode); - expect(jacket!.isMounted, isTrue); - expect(mountNode.children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(mountNode.children[0], jacket.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), attachedToDocument: true, autoTearDown: false); - expect(jacket!.isMounted, isTrue); - expect(document.body!.children[0].children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(document.body!.children[0].children[0], jacket.getNode()); }); }); }); group('not attached to the document', () { group('and unmounts after the test is done', () { - late TestJacket? jacket; + late TestJacket jacket; setUp(() { expect(document.body!.children, isEmpty); @@ -109,9 +108,7 @@ main() { tearDown(() { expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isFalse); - - jacket = null; + expect(jacket.isMounted, isFalse); }); test('with the given container', () { @@ -119,14 +116,14 @@ main() { jacket = mount(Sample()(), mountNode: mountNode); expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isTrue); - expect(mountNode.children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(mountNode.children[0], jacket.getNode()); }); test('without the given container', () { jacket = mount(Sample()()); - expect(jacket!.isMounted, isTrue); + expect(jacket.isMounted, isTrue); }); }); @@ -216,7 +213,7 @@ main() { }); group('TestJacket: DOM component:', () { - late Element? mountNode; + late Element mountNode; late TestJacket jacket; setUp(() { @@ -226,18 +223,17 @@ main() { attachedToDocument: true ); - expect(mountNode!.children.single, isA()); + expect(mountNode.children.single, isA()); }); tearDown(() { - mountNode!.remove(); - mountNode = null; + mountNode.remove(); }); test('rerender', () { jacket.rerender((Dom.span()..id = 'foo')()); - expect(mountNode!.children.single.id, 'foo'); + expect(mountNode.children.single.id, 'foo'); }); test('getProps throws a StateError', () { @@ -245,7 +241,7 @@ main() { }); test('getNode', () { - expect(jacket.getNode(), mountNode!.children.single); + expect(jacket.getNode(), mountNode.children.single); }); test('getDartInstance returns null', () { @@ -266,7 +262,7 @@ main() { }); group('TestJacket: function component:', () { - late Element? mountNode; + late Element mountNode; late TestJacket jacket; setUp(() { @@ -276,18 +272,17 @@ main() { attachedToDocument: true ); - expect(mountNode!.children.single.id, 'foo'); + expect(mountNode.children.single.id, 'foo'); }); tearDown(() { - mountNode!.remove(); - mountNode = null; + mountNode.remove(); }); test('rerender', () { jacket.rerender(testFunctionComponent({'id': 'bar'})); - expect(mountNode!.children.single.id, 'bar'); + expect(mountNode.children.single.id, 'bar'); }); test('getProps throws a StateError', () { @@ -319,11 +314,11 @@ main() { UiFactory Sample = castUiFactory(_$Sample); // ignore: undefined_identifier mixin SampleProps on UiProps { - bool foo; + late bool foo; } mixin SampleState on UiState { - bool bar; + late bool bar; } class SampleComponent extends UiStatefulComponent2 { diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index c5271f8f..7263c131 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/nested_component.dart b/test/over_react_test/utils/nested_component.dart index 113dae33..728a7460 100644 --- a/test/over_react_test/utils/nested_component.dart +++ b/test/over_react_test/utils/nested_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index 293a66ea..e4d7fc78 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +21,8 @@ import 'package:over_react/react_dom.dart' as react_dom; part 'shadow_nested_component.over_react.g.dart'; mixin ShadowNestedProps on UiProps { - String shadowRootHostTestId; - String shadowRootFirstChildTestId; + String? shadowRootHostTestId; + String? shadowRootFirstChildTestId; } UiFactory ShadowNested = uiForwardRef( diff --git a/test/over_react_test/utils/test_common_component.dart b/test/over_react_test/utils/test_common_component.dart index a116d3a4..31c193c1 100644 --- a/test/over_react_test/utils/test_common_component.dart +++ b/test/over_react_test/utils/test_common_component.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested.dart b/test/over_react_test/utils/test_common_component_nested.dart index b2535e51..c1d95fd0 100644 --- a/test/over_react_test/utils/test_common_component_nested.dart +++ b/test/over_react_test/utils/test_common_component_nested.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested2.dart b/test/over_react_test/utils/test_common_component_nested2.dart index 056859af..f816cae1 100644 --- a/test/over_react_test/utils/test_common_component_nested2.dart +++ b/test/over_react_test/utils/test_common_component_nested2.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_new_boilerplate.dart b/test/over_react_test/utils/test_common_component_new_boilerplate.dart index 486c0724..cb639b9f 100644 --- a/test/over_react_test/utils/test_common_component_new_boilerplate.dart +++ b/test/over_react_test/utils/test_common_component_new_boilerplate.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,13 +48,13 @@ class TestCommonForwardingComponent extends UiComponent2 TestCommonDomOnlyForwarding = diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index fd69a28a..72ecc3f9 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart index 5b3f095f..eeee1158 100644 --- a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart +++ b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,13 +22,13 @@ UiFactory TestCommonRequired2 = mixin TestCommonRequired2Props on UiProps { @nullableRequiredProp - bool foobar; + bool? foobar; @requiredProp - bool bar; + bool? bar; @nullableRequiredProp - bool defaultFoo; + bool? defaultFoo; } class TestCommonRequired2Component extends diff --git a/test/over_react_test/validation_util_test.dart b/test/over_react_test/validation_util_test.dart index b94f069a..6e549d30 100644 --- a/test/over_react_test/validation_util_test.dart +++ b/test/over_react_test/validation_util_test.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/zone_render_tests.dart b/test/over_react_test/zone_render_tests.dart index 5a65fab5..99081d7e 100644 --- a/test/over_react_test/zone_render_tests.dart +++ b/test/over_react_test/zone_render_tests.dart @@ -1,3 +1,4 @@ +// @dart = 2.14 import 'dart:async'; import 'package:over_react_test/over_react_test.dart'; From 28aa033f9be4de81bc1aad7dbd36c683ff383da5 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Fri, 16 Jun 2023 08:42:12 -0500 Subject: [PATCH 05/22] WIP: Use https for overrides --- pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index e29d062f..3d567471 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,13 +24,13 @@ dependency_overrides: w_common: ^3.0.0 w_flux: git: - url: git@github.com:Workiva/w_flux.git + url: https://github.com/Workiva/w_flux ref: null-safety over_react: git: - url: git@github.com:Workiva/over_react.git + url: https://github.com/Workiva/over_react ref: null-safety react: git: - url: git@github.com:Workiva/react-dart.git + url: https://github.com/Workiva/react-dart ref: null-safety-manual \ No newline at end of file From 14ede659ef20f24903e205ed665a41a286c98cf5 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Fri, 16 Jun 2023 08:47:06 -0500 Subject: [PATCH 06/22] WIP: lang pin change --- lib/jacket.dart | 2 +- lib/over_react_test.dart | 2 +- lib/src/over_react_test/common_component_util.dart | 2 +- lib/src/over_react_test/console_log_utils.dart | 2 +- lib/src/over_react_test/custom_matchers.dart | 2 +- lib/src/over_react_test/dart_util.dart | 2 +- lib/src/over_react_test/dom_util.dart | 2 +- lib/src/over_react_test/jacket.dart | 2 +- lib/src/over_react_test/js_component.dart | 2 +- lib/src/over_react_test/props_meta.dart | 2 +- lib/src/over_react_test/test_helpers.dart | 2 +- lib/src/over_react_test/validation_util.dart | 2 +- lib/src/over_react_test/wrapper_component.dart | 2 +- lib/src/over_react_test/zone_util.dart | 2 +- test/over_react_test.dart | 2 +- test/over_react_test/common_component_util_test.dart | 2 +- test/over_react_test/console_log_utils_test.dart | 2 +- test/over_react_test/custom_matchers_test.dart | 2 +- test/over_react_test/dom_util_test.dart | 2 +- test/over_react_test/helper_components/sample_component.dart | 2 +- test/over_react_test/helper_components/sample_component2.dart | 2 +- .../helper_components/sample_function_component.dart | 2 +- test/over_react_test/jacket_test.dart | 2 +- test/over_react_test/react_util_test.dart | 2 +- test/over_react_test/utils/nested_component.dart | 2 +- test/over_react_test/utils/shadow_nested_component.dart | 2 +- test/over_react_test/utils/test_common_component.dart | 2 +- test/over_react_test/utils/test_common_component_nested.dart | 2 +- test/over_react_test/utils/test_common_component_nested2.dart | 2 +- .../utils/test_common_component_new_boilerplate.dart | 2 +- .../utils/test_common_component_required_props.dart | 2 +- .../utils/test_common_component_required_props_commponent2.dart | 2 +- test/over_react_test/validation_util_test.dart | 2 +- test/over_react_test/zone_render_tests.dart | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/jacket.dart b/lib/jacket.dart index cdac7242..548b4d75 100644 --- a/lib/jacket.dart +++ b/lib/jacket.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2018 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/over_react_test.dart b/lib/over_react_test.dart index 7af7640f..4689229e 100644 --- a/lib/over_react_test.dart +++ b/lib/over_react_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 87e25ce6..9c7eca8e 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index 4875ed25..82f775fb 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index f7c044e5..26f36edc 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/dart_util.dart b/lib/src/over_react_test/dart_util.dart index 252fa61e..1153b53d 100644 --- a/lib/src/over_react_test/dart_util.dart +++ b/lib/src/over_react_test/dart_util.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 /// Returns whether `assert`s are enabled in the current runtime. /// /// Unless the Dart SDK option to enable `assert`s in dart2js is configured, diff --git a/lib/src/over_react_test/dom_util.dart b/lib/src/over_react_test/dom_util.dart index 926cdfaf..b227b20e 100644 --- a/lib/src/over_react_test/dom_util.dart +++ b/lib/src/over_react_test/dom_util.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index 6e8d2e31..1d5c47f7 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/js_component.dart b/lib/src/over_react_test/js_component.dart index 06d6dd64..fe468c06 100644 --- a/lib/src/over_react_test/js_component.dart +++ b/lib/src/over_react_test/js_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/props_meta.dart b/lib/src/over_react_test/props_meta.dart index c02ccbf9..ef481f82 100644 --- a/lib/src/over_react_test/props_meta.dart +++ b/lib/src/over_react_test/props_meta.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/test_helpers.dart b/lib/src/over_react_test/test_helpers.dart index a1b4705d..b8eebf0c 100644 --- a/lib/src/over_react_test/test_helpers.dart +++ b/lib/src/over_react_test/test_helpers.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 import 'dart:async'; import 'package:test/test.dart'; diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index 0b1096b4..f53a9edf 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/wrapper_component.dart b/lib/src/over_react_test/wrapper_component.dart index 09ced9a3..6d38668e 100644 --- a/lib/src/over_react_test/wrapper_component.dart +++ b/lib/src/over_react_test/wrapper_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index e9d81e64..cb757107 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test.dart b/test/over_react_test.dart index 4de30204..1816b22f 100644 --- a/test/over_react_test.dart +++ b/test/over_react_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index 23525234..f10b0277 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index 7ac2c6f3..b9599193 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index 99236f60..21fa13cf 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index 1726c4bd..dd5df1c8 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/helper_components/sample_component.dart b/test/over_react_test/helper_components/sample_component.dart index 6525afef..caa3f3ac 100644 --- a/test/over_react_test/helper_components/sample_component.dart +++ b/test/over_react_test/helper_components/sample_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 import 'dart:html'; import 'package:over_react/over_react.dart'; diff --git a/test/over_react_test/helper_components/sample_component2.dart b/test/over_react_test/helper_components/sample_component2.dart index e9799cd1..8d25c780 100644 --- a/test/over_react_test/helper_components/sample_component2.dart +++ b/test/over_react_test/helper_components/sample_component2.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 import 'dart:html'; import 'package:over_react/over_react.dart'; diff --git a/test/over_react_test/helper_components/sample_function_component.dart b/test/over_react_test/helper_components/sample_function_component.dart index 7d596b61..6c4eb817 100644 --- a/test/over_react_test/helper_components/sample_function_component.dart +++ b/test/over_react_test/helper_components/sample_function_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 4893eaaf..1a66fbaf 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index 7263c131..8ea8480c 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/nested_component.dart b/test/over_react_test/utils/nested_component.dart index 728a7460..fd220158 100644 --- a/test/over_react_test/utils/nested_component.dart +++ b/test/over_react_test/utils/nested_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index e4d7fc78..cda43732 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component.dart b/test/over_react_test/utils/test_common_component.dart index 31c193c1..ad9f89c1 100644 --- a/test/over_react_test/utils/test_common_component.dart +++ b/test/over_react_test/utils/test_common_component.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested.dart b/test/over_react_test/utils/test_common_component_nested.dart index c1d95fd0..53806668 100644 --- a/test/over_react_test/utils/test_common_component_nested.dart +++ b/test/over_react_test/utils/test_common_component_nested.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested2.dart b/test/over_react_test/utils/test_common_component_nested2.dart index f816cae1..93e2e999 100644 --- a/test/over_react_test/utils/test_common_component_nested2.dart +++ b/test/over_react_test/utils/test_common_component_nested2.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_new_boilerplate.dart b/test/over_react_test/utils/test_common_component_new_boilerplate.dart index cb639b9f..0a635607 100644 --- a/test/over_react_test/utils/test_common_component_new_boilerplate.dart +++ b/test/over_react_test/utils/test_common_component_new_boilerplate.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index 72ecc3f9..6f4cd67a 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart index eeee1158..284c1518 100644 --- a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart +++ b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/validation_util_test.dart b/test/over_react_test/validation_util_test.dart index 6e549d30..0519f65c 100644 --- a/test/over_react_test/validation_util_test.dart +++ b/test/over_react_test/validation_util_test.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/zone_render_tests.dart b/test/over_react_test/zone_render_tests.dart index 99081d7e..ff25a9b9 100644 --- a/test/over_react_test/zone_render_tests.dart +++ b/test/over_react_test/zone_render_tests.dart @@ -1,4 +1,4 @@ -// @dart = 2.14 +// @dart = 2.12 import 'dart:async'; import 'package:over_react_test/over_react_test.dart'; From 54e0fbdabeb4b4fff0fe9e159e2c2672c86614a4 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Fri, 16 Jun 2023 15:56:11 -0500 Subject: [PATCH 07/22] WIP: update deps --- pubspec.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3d567471..d5292e0d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,9 +11,11 @@ dependencies: meta: ^1.6.0 over_react: ^4.1.2 react: ^6.0.1 - test: ^1.15.7 + test: ^1.20.0 collection: ^1.15.0-nullsafety.4 + dev_dependencies: + dart_dev: ^4.0.0 build_runner: ^2.1.2 build_test: ^2.1.3 build_web_compilers: ^3.0.0 @@ -22,6 +24,10 @@ dev_dependencies: dependency_overrides: w_common: ^3.0.0 + dart_dev: + git: + ref: fix_up_null_safety + url: https://github.com/Workiva/dart_dev w_flux: git: url: https://github.com/Workiva/w_flux From 84d871cbdc07c8225bec6d9c3645f2eca6107570 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Fri, 16 Jun 2023 15:57:56 -0500 Subject: [PATCH 08/22] WIP: Add 2.18 to matrix --- .github/workflows/dart_ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index edbef171..8eff4959 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, stable, dev ] + sdk: [ 2.13.4, 2.18.7, stable, dev ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 @@ -46,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, stable ] + sdk: [ 2.13.4, 2.18.7, stable ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 @@ -80,7 +80,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, stable ] + sdk: [ 2.13.4, 2.18.7, stable ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 From da29ac50e5f2bb19e0ea959e7a475d4a5f1ab557 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Fri, 16 Jun 2023 16:07:47 -0500 Subject: [PATCH 09/22] WIP: update deps --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index d5292e0d..abc23dd8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,7 @@ dependency_overrides: w_common: ^3.0.0 dart_dev: git: - ref: fix_up_null_safety + ref: fix_up_null_safety_hunter url: https://github.com/Workiva/dart_dev w_flux: git: From d1679d7e226024efdec9bd9b789e7942e442e2d4 Mon Sep 17 00:00:00 2001 From: Hunter Breathat Date: Tue, 20 Jun 2023 13:26:52 -0400 Subject: [PATCH 10/22] Only test against 2.18.7 --- .github/workflows/dart_ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 8eff4959..e4153402 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, 2.18.7, stable, dev ] + sdk: [ 2.18.7 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 @@ -46,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, 2.18.7, stable ] + sdk: [ 2.18.7 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 @@ -80,7 +80,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.13.4, 2.18.7, stable ] + sdk: [ 2.18.7 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 From ee01d19926802fcf2fe262fe647d0444485bc942 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 13 Nov 2023 15:54:07 -0700 Subject: [PATCH 11/22] Point to null-safe react --- pubspec.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index b9f91c4e..2a02fbe5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: matcher: ^0.12.1+4 meta: ^1.8.0 over_react: ^4.1.2 - react: '>=6.0.1 <8.0.0' + react: ^7.0.0 test: ^1.21.1 dev_dependencies: dart_dev: ^4.0.0 @@ -35,7 +35,4 @@ dependency_overrides: git: url: https://github.com/Workiva/over_react ref: null-safety - react: - git: - url: https://github.com/Workiva/react-dart - ref: null-safety-manual + react: ^7.0.0 From 4ac7e8a3bad4ed9a641a05afaa76ff0903da87b6 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 13 Nov 2023 16:15:50 -0700 Subject: [PATCH 12/22] Remove unnecessary overrides --- pubspec.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2a02fbe5..7ea2579c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,12 +27,7 @@ dependency_overrides: git: ref: fix_up_null_safety_hunter url: https://github.com/Workiva/dart_dev - w_flux: - git: - url: https://github.com/Workiva/w_flux - ref: null-safety over_react: git: url: https://github.com/Workiva/over_react ref: null-safety - react: ^7.0.0 From d4197979aa05dc06fc7a52726d9b617b383b3a72 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 09:20:29 -0600 Subject: [PATCH 13/22] Update dependencies --- .github/workflows/dart_ci.yml | 2 +- pubspec.yaml | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 8ede6bb8..1b2548f5 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -46,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7 ] + sdk: [ 2.18.7, 2.19.6 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v0.2 diff --git a/pubspec.yaml b/pubspec.yaml index 7ea2579c..f0d907e7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: react: ^7.0.0 test: ^1.21.1 dev_dependencies: - dart_dev: ^4.0.0 + dart_dev: ^4.1.0 build_runner: ^2.1.2 build_test: ^2.1.3 build_web_compilers: ^3.0.0 @@ -22,12 +22,7 @@ dev_dependencies: pedantic: ^1.8.0 dependency_overrides: - w_common: ^3.0.0 - dart_dev: - git: - ref: fix_up_null_safety_hunter - url: https://github.com/Workiva/dart_dev over_react: git: url: https://github.com/Workiva/over_react - ref: null-safety + ref: v5_wip From dd90164b94e18faac363ced0dc0508ca780183b0 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 10:05:24 -0600 Subject: [PATCH 14/22] Remove @dart comments and fix required prop issue --- lib/jacket.dart | 1 - lib/over_react_test.dart | 1 - lib/src/over_react_test/common_component_util.dart | 5 +---- lib/src/over_react_test/console_log_utils.dart | 1 - lib/src/over_react_test/custom_matchers.dart | 1 - lib/src/over_react_test/dart_util.dart | 1 - lib/src/over_react_test/dom_util.dart | 1 - lib/src/over_react_test/jacket.dart | 1 - lib/src/over_react_test/js_component.dart | 1 - lib/src/over_react_test/props_meta.dart | 1 - lib/src/over_react_test/test_helpers.dart | 1 - lib/src/over_react_test/validation_util.dart | 1 - lib/src/over_react_test/wrapper_component.dart | 1 - lib/src/over_react_test/zone_util.dart | 1 - pubspec.yaml | 3 +-- test/over_react_test.dart | 1 - test/over_react_test/common_component_util_test.dart | 1 - test/over_react_test/console_log_utils_test.dart | 1 - test/over_react_test/custom_matchers_test.dart | 1 - test/over_react_test/dom_util_test.dart | 1 - test/over_react_test/helper_components/sample_component.dart | 1 - .../over_react_test/helper_components/sample_component2.dart | 1 - .../helper_components/sample_function_component.dart | 1 - test/over_react_test/jacket_test.dart | 1 - test/over_react_test/react_util_test.dart | 1 - test/over_react_test/utils/nested_component.dart | 1 - test/over_react_test/utils/shadow_nested_component.dart | 1 - test/over_react_test/utils/test_common_component.dart | 1 - test/over_react_test/utils/test_common_component_nested.dart | 1 - .../over_react_test/utils/test_common_component_nested2.dart | 1 - .../utils/test_common_component_new_boilerplate.dart | 5 ++--- .../utils/test_common_component_required_props.dart | 1 - .../test_common_component_required_props_commponent2.dart | 1 - test/over_react_test/validation_util_test.dart | 1 - test/over_react_test/zone_render_tests.dart | 5 ++--- 35 files changed, 6 insertions(+), 43 deletions(-) diff --git a/lib/jacket.dart b/lib/jacket.dart index 548b4d75..ef010982 100644 --- a/lib/jacket.dart +++ b/lib/jacket.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2018 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/over_react_test.dart b/lib/over_react_test.dart index 4689229e..b6c29058 100644 --- a/lib/over_react_test.dart +++ b/lib/over_react_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 9c7eca8e..5bee3d95 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +17,8 @@ import 'dart:html'; import 'dart:js'; import 'package:meta/meta.dart'; -import 'package:over_react/over_react.dart'; import 'package:over_react/component_base.dart' as component_base; +import 'package:over_react/over_react.dart'; import 'package:over_react_test/over_react_test.dart'; import 'package:over_react_test/src/over_react_test/props_meta.dart'; import 'package:over_react_test/src/over_react_test/test_helpers.dart'; @@ -28,8 +27,6 @@ import 'package:react/react_client/react_interop.dart'; import 'package:react/react_test_utils.dart' as react_test_utils; import 'package:test/test.dart'; -import './custom_matchers.dart'; -import './react_util.dart'; import 'dart_util.dart'; /// Run common component tests around default props, prop forwarding, class name merging, and class name overrides. diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index 82f775fb..dccff5ec 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index 26f36edc..50d25346 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/dart_util.dart b/lib/src/over_react_test/dart_util.dart index 1153b53d..f28ced53 100644 --- a/lib/src/over_react_test/dart_util.dart +++ b/lib/src/over_react_test/dart_util.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 /// Returns whether `assert`s are enabled in the current runtime. /// /// Unless the Dart SDK option to enable `assert`s in dart2js is configured, diff --git a/lib/src/over_react_test/dom_util.dart b/lib/src/over_react_test/dom_util.dart index b227b20e..ed2b1e97 100644 --- a/lib/src/over_react_test/dom_util.dart +++ b/lib/src/over_react_test/dom_util.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index 1d5c47f7..09fdc711 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/js_component.dart b/lib/src/over_react_test/js_component.dart index c87f89d2..7acef9d2 100644 --- a/lib/src/over_react_test/js_component.dart +++ b/lib/src/over_react_test/js_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/props_meta.dart b/lib/src/over_react_test/props_meta.dart index ef481f82..d3e5b67c 100644 --- a/lib/src/over_react_test/props_meta.dart +++ b/lib/src/over_react_test/props_meta.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/test_helpers.dart b/lib/src/over_react_test/test_helpers.dart index b8eebf0c..61b41964 100644 --- a/lib/src/over_react_test/test_helpers.dart +++ b/lib/src/over_react_test/test_helpers.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 import 'dart:async'; import 'package:test/test.dart'; diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index f53a9edf..27d95997 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/wrapper_component.dart b/lib/src/over_react_test/wrapper_component.dart index 6d38668e..c412a117 100644 --- a/lib/src/over_react_test/wrapper_component.dart +++ b/lib/src/over_react_test/wrapper_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index cb757107..6ec539f1 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/pubspec.yaml b/pubspec.yaml index f0d907e7..bb860d7a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,10 +3,9 @@ version: 2.11.7 description: A library for testing OverReact components homepage: https://github.com/Workiva/over_react_test/ environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.13.0 <3.0.0' dependencies: - collection: ^1.15.0-nullsafety.4 js: ^0.6.1+1 matcher: ^0.12.1+4 meta: ^1.8.0 diff --git a/test/over_react_test.dart b/test/over_react_test.dart index 1816b22f..b99c51c4 100644 --- a/test/over_react_test.dart +++ b/test/over_react_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index f10b0277..d0e052bb 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index b9599193..9eb900ab 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index 21fa13cf..f3fc4204 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index dd5df1c8..60a43246 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/helper_components/sample_component.dart b/test/over_react_test/helper_components/sample_component.dart index caa3f3ac..39400423 100644 --- a/test/over_react_test/helper_components/sample_component.dart +++ b/test/over_react_test/helper_components/sample_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 import 'dart:html'; import 'package:over_react/over_react.dart'; diff --git a/test/over_react_test/helper_components/sample_component2.dart b/test/over_react_test/helper_components/sample_component2.dart index 8d25c780..46c0b269 100644 --- a/test/over_react_test/helper_components/sample_component2.dart +++ b/test/over_react_test/helper_components/sample_component2.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 import 'dart:html'; import 'package:over_react/over_react.dart'; diff --git a/test/over_react_test/helper_components/sample_function_component.dart b/test/over_react_test/helper_components/sample_function_component.dart index 6c4eb817..9e9470c4 100644 --- a/test/over_react_test/helper_components/sample_function_component.dart +++ b/test/over_react_test/helper_components/sample_function_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 1a66fbaf..33c45d6f 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index 8ea8480c..c5271f8f 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/nested_component.dart b/test/over_react_test/utils/nested_component.dart index fd220158..113dae33 100644 --- a/test/over_react_test/utils/nested_component.dart +++ b/test/over_react_test/utils/nested_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index cda43732..1a1f6510 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component.dart b/test/over_react_test/utils/test_common_component.dart index ad9f89c1..a116d3a4 100644 --- a/test/over_react_test/utils/test_common_component.dart +++ b/test/over_react_test/utils/test_common_component.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested.dart b/test/over_react_test/utils/test_common_component_nested.dart index 53806668..b2535e51 100644 --- a/test/over_react_test/utils/test_common_component_nested.dart +++ b/test/over_react_test/utils/test_common_component_nested.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_nested2.dart b/test/over_react_test/utils/test_common_component_nested2.dart index 93e2e999..056859af 100644 --- a/test/over_react_test/utils/test_common_component_nested2.dart +++ b/test/over_react_test/utils/test_common_component_nested2.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_new_boilerplate.dart b/test/over_react_test/utils/test_common_component_new_boilerplate.dart index 0a635607..b3a36abd 100644 --- a/test/over_react_test/utils/test_common_component_new_boilerplate.dart +++ b/test/over_react_test/utils/test_common_component_new_boilerplate.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2020 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +38,7 @@ class TestCommonForwardingComponent extends UiComponent2 TestCommonDomOnlyForwarding = diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index 6f4cd67a..fd69a28a 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart index 284c1518..d44a44ef 100644 --- a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart +++ b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2019 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/validation_util_test.dart b/test/over_react_test/validation_util_test.dart index 0519f65c..b94f069a 100644 --- a/test/over_react_test/validation_util_test.dart +++ b/test/over_react_test/validation_util_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 // Copyright 2017 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/over_react_test/zone_render_tests.dart b/test/over_react_test/zone_render_tests.dart index ff25a9b9..19bdaff6 100644 --- a/test/over_react_test/zone_render_tests.dart +++ b/test/over_react_test/zone_render_tests.dart @@ -1,4 +1,3 @@ -// @dart = 2.12 import 'dart:async'; import 'package:over_react_test/over_react_test.dart'; @@ -10,7 +9,7 @@ import 'helper_components/sample_component.dart'; main() { group('TestJacket mount', () { - sharedZoneRenderTests(mount as dynamic Function(ReactElement, {bool? autoTearDown})); + sharedZoneRenderTests(mount); }); group('render', () { @@ -22,7 +21,7 @@ main() { }); } -void sharedZoneRenderTests(Function(ReactElement element, {bool? autoTearDown}) renderFunction) { +void sharedZoneRenderTests(Function(ReactElement element, {bool autoTearDown}) renderFunction) { group('sharedZoneRenderTests:', () { setUp(() { setComponentZone(Zone.root); From d417946fffd2d2ea4713d4b3ccb20ee0a8c87a45 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 12:01:00 -0600 Subject: [PATCH 15/22] Review and cleanup nullability --- .../common_component_util.dart | 35 ++++++------ .../over_react_test/console_log_utils.dart | 4 +- lib/src/over_react_test/custom_matchers.dart | 9 +-- lib/src/over_react_test/jacket.dart | 3 +- lib/src/over_react_test/react_util.dart | 57 +++++++++---------- lib/src/over_react_test/validation_util.dart | 6 ++ lib/src/over_react_test/zone_util.dart | 5 +- 7 files changed, 58 insertions(+), 61 deletions(-) diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index 5bee3d95..d51a82c0 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -23,6 +23,7 @@ import 'package:over_react_test/over_react_test.dart'; import 'package:over_react_test/src/over_react_test/props_meta.dart'; import 'package:over_react_test/src/over_react_test/test_helpers.dart'; import 'package:react/react_client.dart'; +import 'package:react/react_client/js_backed_map.dart'; import 'package:react/react_client/react_interop.dart'; import 'package:react/react_test_utils.dart' as react_test_utils; import 'package:test/test.dart'; @@ -333,18 +334,18 @@ void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory() /// Test for prop keys that both are forwarded and exist on the forwarding target's default props. if (isDartComponent(forwardingTarget)) { final forwardingTargetType = (forwardingTarget as ReactElement).type as ReactClass; - Map? forwardingTargetDefaults; + late Map forwardingTargetDefaults; switch (forwardingTargetType.dartComponentVersion) { // ignore: invalid_use_of_protected_member case ReactDartComponentVersion.component: // ignore: invalid_use_of_protected_member - forwardingTargetDefaults = forwardingTargetType.dartDefaultProps; // ignore: deprecated_member_use + forwardingTargetDefaults = forwardingTargetType.dartDefaultProps ?? {}; // ignore: deprecated_member_use break; case ReactDartComponentVersion.component2: // ignore: invalid_use_of_protected_member - forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps!); + forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps ?? JsMap()); break; } var commonForwardedAndDefaults = propKeysThatShouldNotGetForwarded - .intersection(forwardingTargetDefaults!.keys.toSet()); + .intersection(forwardingTargetDefaults.keys.toSet()); /// Don't count these as unexpected keys in later assertions; we'll verify them within this block. unexpectedKeys.removeAll(commonForwardedAndDefaults); @@ -425,7 +426,7 @@ void testClassNameMerging(BuilderOnlyUiFactory factory, dynamic childrenFactory( ..classNameBlacklist = 'blacklisted-class-1 blacklisted-class-2'; var renderedInstance = render(builder(childrenFactory())); - Iterable forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); + final forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( allOf( @@ -498,7 +499,7 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor )(childrenFactory()) ); - Iterable forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); + final forwardingTargetNodes = getForwardingTargets(reactInstance).map(findDomNode); expect(forwardingTargetNodes, everyElement( hasExactClasses('') ), reason: '$classesToOverride not overridden'); @@ -529,7 +530,7 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) isComponent2 = version == ReactDartComponentVersion.component2; var jacket = mount(factory()(childrenFactory()), autoTearDown: false); - var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps!; + var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps ?? []; jacket.unmount(); for (var consumedProp in consumedProps) { @@ -578,20 +579,20 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) void component2RequiredPropsTest() { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction? originalConsoleError = context['console']['error']; + var consoleErrors = []; + final originalConsoleError = context['console']['error'] as JsFunction; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); - originalConsoleError!.apply([message, arg1, arg2, arg3, arg4, arg5], + originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); final reactComponentFactory = factory().componentFactory as - ReactDartComponentFactoryProxy2?/*!*//*!*/; // ignore: avoid_as + ReactDartComponentFactoryProxy2; // ignore: avoid_as for (var propKey in requiredProps) { - if (!reactComponentFactory!.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory.defaultProps.containsKey(propKey)) { try { mount((factory() @@ -655,21 +656,21 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) } else { PropTypes.resetWarningCache(); - List consoleErrors = []; - JsFunction?/*?*/ originalConsoleError = context['console']['error']; + var consoleErrors = []; + final originalConsoleError = context['console']['error'] as JsFunction; addTearDown(() => context['console']['error'] = originalConsoleError); context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) { consoleErrors.add(message); - originalConsoleError!.apply([message, arg1, arg2, arg3, arg4, arg5], + originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self); }); final reactComponentFactory = factory().componentFactory as - ReactDartComponentFactoryProxy2?; // ignore: avoid_as + ReactDartComponentFactoryProxy2; // ignore: avoid_as for (var propKey in nullableProps) { // Props that are defined in the default props map will never not be set. - if (!reactComponentFactory!.defaultProps.containsKey(propKey)) { + if (!reactComponentFactory.defaultProps.containsKey(propKey)) { try { mount((factory() ..remove(propKey) diff --git a/lib/src/over_react_test/console_log_utils.dart b/lib/src/over_react_test/console_log_utils.dart index dccff5ec..0d0a63a3 100644 --- a/lib/src/over_react_test/console_log_utils.dart +++ b/lib/src/over_react_test/console_log_utils.dart @@ -43,7 +43,7 @@ List recordConsoleLogs( final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); @@ -90,7 +90,7 @@ FutureOr> recordConsoleLogsAsync( final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfiguration.types : [configuration.logType]; - Map consoleRefs = {}; + Map consoleRefs = {}; if (shouldResetPropTypesWarningCache) _resetPropTypeWarningCache(); diff --git a/lib/src/over_react_test/custom_matchers.dart b/lib/src/over_react_test/custom_matchers.dart index 50d25346..7f9abe96 100644 --- a/lib/src/over_react_test/custom_matchers.dart +++ b/lib/src/over_react_test/custom_matchers.dart @@ -17,7 +17,6 @@ import 'dart:svg'; import 'package:collection/collection.dart' show IterableNullableExtension; import 'package:over_react/over_react.dart'; -import 'package:matcher/matcher.dart'; import 'package:over_react_test/src/over_react_test/dart_util.dart'; import 'package:react/react.dart' as react; import 'package:react/react_test_utils.dart' as react_test_utils; @@ -62,7 +61,7 @@ class ClassNameMatcher extends Matcher { // There's a bug in DDC where, though the docs say `className` should // return `String`, it will return `AnimatedString` for `SvgElement`s. See // https://github.com/dart-lang/sdk/issues/36200. - late String? castClassName; + String? castClassName; if (className is String) { castClassName = className; } else if (className is AnimatedString) { @@ -376,17 +375,13 @@ class _LoggingFunctionMatcher extends CustomMatcher { @override featureValueOf(actual) { - List logs = []; - if (actual is List) return actual; if (actual is! Function()) { throw ArgumentError('The actual value must be a callback or a List.'); } - logs = recordConsoleLogs(actual, configuration: config ?? logConfig); - - return logs; + return recordConsoleLogs(actual, configuration: config ?? logConfig); } } diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index 09fdc711..ad69cdc4 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -15,12 +15,11 @@ import 'dart:html'; import 'package:over_react/over_react.dart' as over_react; +import 'package:over_react_test/src/over_react_test/react_util.dart' as react_util; import 'package:react/react.dart' as react; import 'package:react/react_client/react_interop.dart' show ReactComponent; import 'package:react/react_test_utils.dart' as react_test_utils; -import 'package:over_react_test/src/over_react_test/react_util.dart' as react_util; - import './zone_util.dart'; // Notes diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index 6657c1bb..0025fcf5 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -20,13 +20,11 @@ import 'dart:html'; import 'package:collection/collection.dart' show IterableNullableExtension; import 'package:js/js.dart'; -import 'package:over_react/over_react.dart'; import 'package:over_react/component_base.dart' as component_base; +import 'package:over_react/over_react.dart'; import 'package:react/react.dart' as react; -import 'package:react/react_dom.dart' as react_dom; -import 'package:react/react_client.dart'; -import 'package:react/react_client/react_interop.dart'; import 'package:react/react_client/js_interop_helpers.dart'; +import 'package:react/react_dom.dart' as react_dom; import 'package:react/react_test_utils.dart' as react_test_utils; import 'package:test/test.dart'; @@ -55,7 +53,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; /// [autoTearDown] to false. If [autoTearDown] is set to true once it will, if provided, call [autoTearDownCallback] /// once the component has been unmounted. /* [1] */ render(dynamic component, - {bool? autoTearDown = true, + {bool autoTearDown = true, Element? container, Callback? autoTearDownCallback}) { var renderedInstance; @@ -69,7 +67,7 @@ export 'package:over_react/src/util/react_wrappers.dart'; renderedInstance = react_dom.render(component, container); } - if (autoTearDown!) { + if (autoTearDown) { addTearDown(() { unmount(renderedInstance); if (autoTearDownCallback != null) autoTearDownCallback(); @@ -178,29 +176,29 @@ List _attachedReactContainers = []; /// /// Returns the rendered component. /* [1] */ renderAttachedToDocument(dynamic component, - {bool? autoTearDown = true, + {bool autoTearDown = true, Element? container, Callback? autoTearDownCallback}) { - container ??= DivElement() + final containerElement = container ??= DivElement() // Set arbitrary height and width for container to ensure nothing is cut off. ..style.setProperty('width', '800px') ..style.setProperty('height', '800px'); setComponentZone(); - document.body!.append(container); + document.body!.append(containerElement); - if (autoTearDown!) { + if (autoTearDown) { addTearDown(() { - react_dom.unmountComponentAtNode(container); - container!.remove(); + react_dom.unmountComponentAtNode(containerElement); + containerElement.remove(); if (autoTearDownCallback != null) autoTearDownCallback(); }); } else { - _attachedReactContainers.add(container); + _attachedReactContainers.add(containerElement); } - return react_dom.render(component is component_base.UiProps ? component.build() : component, container); + return react_dom.render(component is component_base.UiProps ? component.build() : component, containerElement); } /// Unmounts and removes the mount nodes for components rendered via [renderAttachedToDocument] that are not @@ -297,7 +295,7 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -/* [1] */ getByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { +/* [1] */ getByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { final results = getAllByTestId(root, value, key: key); return results.isEmpty ? null : results.first; } @@ -344,8 +342,7 @@ bool _hasTestId(Map props, String key, String value) { /// /// It is recommended that, instead of setting this [key] prop manually, you should use the /// [UiProps.addTestId] method so the prop is only set in a test environment. -List /* < [1] > */ getAllByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { - if (value == null || value.toLowerCase() == 'null') return []; +List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { if (root is react.Component) root = root.jsThis; if (isValidElement(root)) { @@ -353,13 +350,13 @@ List /* < [1] > */ getAllByTestId(dynamic root, String? value, {String key = def } return react_test_utils.findAllInRenderedTree(root, allowInterop((descendant) { - Map? props; + late Map props; if (react_test_utils.isDOMComponent(descendant)) { props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } - return props != null && _hasTestId(props, key, value); + return _hasTestId(props, key, value); })); } @@ -453,7 +450,7 @@ Element? getComponentRootDomByTestId(dynamic root, String value, {String key = d /// /// Related: [queryAllByTestId], [getComponentRootDomByTestId]. Element? queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) { - var results = _findDeep(findDomNode(root)!, _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: false, depth: shadowDepth); + var results = _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: false, depth: shadowDepth); return results.isNotEmpty ? results.first : null; } @@ -493,14 +490,14 @@ Element? queryByTestId(dynamic root, String value, {String key = defaultTestIdKe /// /// queryAllByTestId(renderedInstance, 'value'); // returns both `inner` `
`s List queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) { - return _findDeep(findDomNode(root)!, _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: true, depth: shadowDepth); + return _findDeep(findDomNode(root), _makeTestIdSelector(value, key: key), searchInShadowDom: searchInShadowDom, findMany: true, depth: shadowDepth); } String _makeTestIdSelector(String value, {String key = defaultTestIdKey}) => '[$key~="$value"]'; -List _findDeep(Node root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int? depth}) { +List _findDeep(Node? root, String itemSelector, {bool searchInShadowDom = false, bool findMany = true, int? depth}) { List nodes = []; - void recursiveSeek(Node _root, int _currentDepth) { + void recursiveSeek(Node? _root, int _currentDepth) { // The LHS type prevents `rootQuerySelectorAll` from returning `_FrozenElementList>` instead of `` in DDC final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : (String s) => []; nodes.addAll(rootQuerySelectorAll(itemSelector)); @@ -509,8 +506,10 @@ List _findDeep(Node root, String itemSelector, {bool searchInShadowDom } // This method of finding shadow roots may not be performant, but it's good enough for usage in tests. if (searchInShadowDom && (depth == null || _currentDepth < depth)) { - var foundShadows = rootQuerySelectorAll('*').where((el) => el.shadowRoot != null).map((el) => el.shadowRoot).toList(); - foundShadows.forEach((shadowRoot) => recursiveSeek(shadowRoot!, _currentDepth + 1)); + var foundShadows = rootQuerySelectorAll('*').where((el) => el.shadowRoot != null).map((el) => el.shadowRoot!).toList(); + for (var shadowRoot in foundShadows) { + recursiveSeek(shadowRoot, _currentDepth + 1); + } } } recursiveSeek(root, 0); @@ -520,7 +519,7 @@ List _findDeep(Node root, String itemSelector, {bool searchInShadowDom /// Returns the [react.Component] of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -react.Component? getComponentByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { +react.Component? getComponentByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getDartComponent(instance); @@ -532,7 +531,7 @@ react.Component? getComponentByTestId(dynamic root, String? value, {String key = /// Returns the props of the first descendant of [root] that has its [key] prop value set to [value]. /// /// Returns null if no descendant has its [key] prop value set to [value]. -Map? getPropsByTestId(dynamic root, String? value, {String key = defaultTestIdKey}) { +Map? getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) { var instance = getByTestId(root, value, key: key); if (instance != null) { return getProps(instance); @@ -577,14 +576,14 @@ List findDescendantsWithProp(/* [1] */ root, dynamic propKey) { return false; } - Map? props; + late Map props; if (react_test_utils.isDOMComponent(descendant)) { props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } - return props != null && props.containsKey(propKey); + return props.containsKey(propKey); })); return descendantsWithProp; diff --git a/lib/src/over_react_test/validation_util.dart b/lib/src/over_react_test/validation_util.dart index 27d95997..1f9a9e3d 100644 --- a/lib/src/over_react_test/validation_util.dart +++ b/lib/src/over_react_test/validation_util.dart @@ -167,10 +167,16 @@ List? getValidationWarnings() => _validationWarnings?.toList(); /// /// > Related: [getValidationWarnings] void clearValidationWarnings() { + if (_validationWarnings == null) { + throw StateError('Need to call startRecordingValidationWarnings() first.'); + } _validationWarnings!.clear(); } List? _validationWarnings; void _recordValidationWarning(String warningMessage) { + if (_validationWarnings == null) { + throw StateError('Need to call startRecordingValidationWarnings() first.'); + } _validationWarnings!.add(warningMessage); } diff --git a/lib/src/over_react_test/zone_util.dart b/lib/src/over_react_test/zone_util.dart index 6ec539f1..d8cb97a2 100644 --- a/lib/src/over_react_test/zone_util.dart +++ b/lib/src/over_react_test/zone_util.dart @@ -29,10 +29,7 @@ void validateZone() { /// Store the specified _(or current if none is specified)_ [zone] /// for use within [zonedExpect]. void storeZone([Zone? zone]) { - if (zone == null) { - zone = Zone.current; - } - _zone = zone; + _zone = zone ?? Zone.current; } /// Calls [expect] in package:test/test.dart in the zone stored in [storeZone]. From e246c3ea5ae19cea15e17b6a645fc5f3ff3af8fa Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 12:23:47 -0600 Subject: [PATCH 16/22] First pass at tests --- .../common_component_util_test.dart | 10 ++-- .../console_log_utils_test.dart | 19 ++++--- .../over_react_test/custom_matchers_test.dart | 1 + test/over_react_test/dom_util_test.dart | 6 +- test/over_react_test/jacket_test.dart | 22 +++---- test/over_react_test/react_util_test.dart | 57 ++----------------- .../utils/shadow_nested_component.dart | 2 +- .../test_common_component_required_props.dart | 2 + ..._component_required_props_commponent2.dart | 2 + 9 files changed, 38 insertions(+), 83 deletions(-) diff --git a/test/over_react_test/common_component_util_test.dart b/test/over_react_test/common_component_util_test.dart index d0e052bb..ff149301 100644 --- a/test/over_react_test/common_component_util_test.dart +++ b/test/over_react_test/common_component_util_test.dart @@ -48,8 +48,8 @@ main() { }); group('should skip checking for certain props', () { - final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()())!; - final consumedKeys = meta.forMixin(new_boilerplate.ShouldNotBeForwardedProps).keys; + final meta = getPropsMeta(new_boilerplate.TestCommonForwarding()()); + final consumedKeys = meta!.forMixin(new_boilerplate.ShouldNotBeForwardedProps).keys; final skippedKey = consumedKeys.first; commonComponentTests( @@ -158,7 +158,7 @@ main() { /// Declares a [group] in which tests declared via [testFunction] are expected to fail /// with an error matching [testFailureMatcher]. @isTestGroup - void expectedFailGroup(String description, void Function() groupBody, {required dynamic testFailureMatcher}) { + void expectedFailGroup(String description, void Function() groupBody, {@required dynamic testFailureMatcher}) { group(description, () { int totalTestCount = 0; late List testFailureErrors; @@ -199,7 +199,7 @@ main() { }); expectedFailGroup('forwards consumed props -', () { - final UiProps Function([Map]) factory = registerHelperComponent( + final factory = registerHelperComponent( propsMeta: testPropsMeta, consumedProps: testPropsMeta.all, render: (component) => (Wrapper()..addAll(component.props))(), @@ -213,7 +213,7 @@ main() { }, testFailureMatcher: contains('Unexpected keys on forwarding target')); expectedFailGroup('does not forward all of the unconsumed props in propsMeta -', () { - UiProps Function([Map]) factory = registerHelperComponent( + var factory = registerHelperComponent( propsMeta: testPropsMeta, consumedProps: [], render: (component) => (Wrapper() diff --git a/test/over_react_test/console_log_utils_test.dart b/test/over_react_test/console_log_utils_test.dart index 9eb900ab..3a13c40f 100644 --- a/test/over_react_test/console_log_utils_test.dart +++ b/test/over_react_test/console_log_utils_test.dart @@ -75,7 +75,7 @@ main() { configuration: errorConfig); expect(logs, hasLength(2)); - expect(logs.firstWhere((log) => log!.contains('shouldAlwaysBeFalse')), + expect(logs.firstWhere((log) => log?.contains('shouldAlwaysBeFalse') ?? false), contains('set to true')); }); @@ -226,14 +226,15 @@ main() { var jacket = mount(Sample()(), attachedToDocument: true); var logs = await recordConsoleLogsAsync(() async { var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); await Future.delayed(Duration(milliseconds: 5)); - triggerDocumentClick(button); + expect(button, isNotNull); + triggerDocumentClick(button!); }, configuration: warnConfig); expect(logs, hasLength(1)); - expect(logs.first!.contains('I have been clicked'), isTrue); + expect(logs.first?.contains('I have been clicked'), isTrue); }); test('handles errors caused when rendering', () async { @@ -298,10 +299,11 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); await Future.delayed(Duration(milliseconds: 5)); - triggerDocumentClick(button); + expect(button, isNotNull); + triggerDocumentClick(button!); }, configuration: logConfig); expect(logs, hasLength(3)); @@ -312,10 +314,11 @@ main() { var jacket = mount((Sample()..addExtraLogAndWarn = true)(), attachedToDocument: true); var button = - queryByTestId(jacket.getInstance(), 'ort_sample_component_button')!; + queryByTestId(jacket.getInstance(), 'ort_sample_component_button'); await Future.delayed(Duration(milliseconds: 5)); - triggerDocumentClick(button); + expect(button, isNotNull); + triggerDocumentClick(button!); }, configuration: warnConfig); expect(logs, hasLength(5)); diff --git a/test/over_react_test/custom_matchers_test.dart b/test/over_react_test/custom_matchers_test.dart index f3fc4204..79cba24c 100644 --- a/test/over_react_test/custom_matchers_test.dart +++ b/test/over_react_test/custom_matchers_test.dart @@ -865,6 +865,7 @@ void shouldFail(value, Matcher matcher, expected) { if (expected is String) { expect(_errorString, equalsIgnoringWhitespace(expected)); } else { + expect(_errorString, isNotNull); expect(_errorString!.replaceAll(RegExp(r'[\s\n]+'), ' '), expected); } } diff --git a/test/over_react_test/dom_util_test.dart b/test/over_react_test/dom_util_test.dart index 60a43246..c313e871 100644 --- a/test/over_react_test/dom_util_test.dart +++ b/test/over_react_test/dom_util_test.dart @@ -33,7 +33,7 @@ main() { }); group('triggerDocumentClick correctly dispatches a click event', () { - late var flag; + var flag; setUp((){ flag = false; @@ -56,7 +56,7 @@ main() { }); group('triggerDocumentMouseEvent correctly dispatches an event', () { - late var flag; + var flag; setUp((){ flag = false; @@ -79,7 +79,7 @@ main() { }); group('triggerFocus correctly dispatches a focus event', () { - late var flag; + var flag; setUp((){ flag = false; diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 33c45d6f..631076e9 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -36,7 +36,6 @@ main() { tearDown(() { expect(document.body!.children, isEmpty); expect(jacket.isMounted, isFalse); - }); test('with the given container', () { @@ -71,7 +70,6 @@ main() { expect(document.body!.children, isEmpty); expect(jacket.isMounted, isFalse); - }); test('with the given container', () { @@ -127,7 +125,7 @@ main() { }); group('and does not unmount after the test is done', () { - late TestJacket? jacket; + late TestJacket jacket; setUp(() { expect(document.body!.children, isEmpty); @@ -135,14 +133,12 @@ main() { tearDown(() { expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isTrue); + expect(jacket.isMounted, isTrue); - jacket!.unmount(); + jacket.unmount(); expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isFalse); - - jacket = null; + expect(jacket.isMounted, isFalse); }); test('with the given container', () { @@ -150,15 +146,15 @@ main() { jacket = mount(Sample()(), mountNode: mountNode, autoTearDown: false); expect(document.body!.children.isEmpty, isTrue); - expect(jacket!.isMounted, isTrue); - expect(mountNode.children[0], jacket!.getNode()); + expect(jacket.isMounted, isTrue); + expect(mountNode.children[0], jacket.getNode()); }); test('without the given container', () { jacket = mount(Sample()(), autoTearDown: false); expect(document.body!.children, isEmpty); - expect(jacket!.isMounted, isTrue); + expect(jacket.isMounted, isTrue); }); }); }); @@ -313,11 +309,11 @@ main() { UiFactory Sample = castUiFactory(_$Sample); // ignore: undefined_identifier mixin SampleProps on UiProps { - late bool foo; + bool? foo; } mixin SampleState on UiState { - late bool bar; + bool? bar; } class SampleComponent extends UiStatefulComponent2 { diff --git a/test/over_react_test/react_util_test.dart b/test/over_react_test/react_util_test.dart index c5271f8f..c70e047b 100644 --- a/test/over_react_test/react_util_test.dart +++ b/test/over_react_test/react_util_test.dart @@ -253,9 +253,9 @@ main() { }); group('getByTestId returns', () { - sharedTests({bool? shallow}) { + sharedTests({required bool shallow}) { testSpecificRender(ReactElement instance) => - shallow! ? renderShallow(instance) : render(instance); + shallow ? renderShallow(instance) : render(instance); group('the single descendant that has the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -427,16 +427,6 @@ main() { expect(descendant, isNull); }); - - test('null if the user searches for a test ID of `null` when the test ID is set to \'null\'', () { - var renderedInstance = testSpecificRender(Wrapper()( - (Test()..addTestId('null'))() - )); - - var descendant = getByTestId(renderedInstance, null); - - expect(descendant, isNull); - }); } group('(rendered component)', () { @@ -461,9 +451,9 @@ main() { }); group('getAllByTestId returns', () { - sharedTests({bool? shallow}) { + sharedTests({required bool shallow}) { testSpecificRender(ReactElement instance) => - shallow! ? renderShallow(instance) : render(instance); + shallow ? renderShallow(instance) : render(instance); group('a list containing the single descendant that have the appropriate value for the `data-test-id` prop key when it is a', () { const String targetFlagProp = 'data-name'; @@ -640,15 +630,6 @@ main() { expect(descendants, isEmpty); }); - test('an empty list if the user searches for a test ID of `null` when the test ID is set to \'null\'', () { - var renderedInstance = testSpecificRender(Wrapper()( - (Test()..addTestId('null'))(), - )); - - var descendants = getAllByTestId(renderedInstance, null); - expect(descendants, isEmpty); - }); - test('without throwing when text nodes are present in the tree', () { var renderedInstance = render(Wrapper()( Dom.div()(), @@ -1029,16 +1010,6 @@ main() { expect(descendant, isNull); }); - - test('null if the user searches for `null` when a test ID is set to \'null\'', () { - var renderedInstance = render(Wrapper()( - (Test()..addTestId('null'))() - )); - - var descendant = getComponentByTestId(renderedInstance, null); - - expect(descendant, isNull); - }); }); group('getComponentByTestId returns', () { @@ -1144,16 +1115,6 @@ main() { expect(descendant, isNull); }); - - test('null if the user searches for `null` when a test ID is set to \'null\'', () { - var renderedInstance = render(Wrapper()( - (Test()..addTestId('null'))() - )); - - var descendant = getComponentByTestId(renderedInstance, null); - - expect(descendant, isNull); - }); }); group('getPropsByTestId returns', () { @@ -1265,16 +1226,6 @@ main() { expect(props, isNull); }); - - test('null if the user searches for `null` when a test ID is set to \'null\'', () { - var renderedInstance = render(Wrapper()( - (Test()..addTestId('null'))() - )); - - var props = getPropsByTestId(renderedInstance, null); - - expect(props, isNull); - }); }); group('findDescendantsWithProp', () { diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index 1a1f6510..290afb2f 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -30,7 +30,7 @@ UiFactory ShadowNested = uiForwardRef( useEffect(() { var shadowRootFirstChild = DivElement()..dataset['test-id'] = props.shadowRootFirstChildTestId ?? 'shadowRootFirstChild'; - divRef.current!.attachShadow({'mode':'open'}).append(shadowRootFirstChild); + divRef.current?.attachShadow({'mode':'open'}).append(shadowRootFirstChild); react_dom.render(Fragment()(props.children), shadowRootFirstChild); return () => react_dom.unmountComponentAtNode(shadowRootFirstChild); }, []); diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index fd69a28a..51f5eb68 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -30,6 +30,8 @@ class _$TestCommonRequiredProps extends UiProps { @nullableRequiredProp bool? defaultFoo; + + // todo add late prop?? } @Component() diff --git a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart index d44a44ef..3eaf0e58 100644 --- a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart +++ b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart @@ -28,6 +28,8 @@ mixin TestCommonRequired2Props on UiProps { @nullableRequiredProp bool? defaultFoo; + + // todo add late prop?? } class TestCommonRequired2Component extends From 66c2cb8e8df793b11941a9dc5fa13f0f06c9a940 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 13:08:27 -0600 Subject: [PATCH 17/22] Fix defaultProps related test failures --- .../helper_components/sample_component.dart | 45 +++++++++---------- .../helper_components/sample_component2.dart | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/test/over_react_test/helper_components/sample_component.dart b/test/over_react_test/helper_components/sample_component.dart index 39400423..5d9fff80 100644 --- a/test/over_react_test/helper_components/sample_component.dart +++ b/test/over_react_test/helper_components/sample_component.dart @@ -7,32 +7,31 @@ part 'sample_component.over_react.g.dart'; UiFactory Sample = castUiFactory(_$Sample); // ignore: undefined_identifier mixin SampleProps on UiProps { - late bool shouldNeverBeNull; + bool? shouldNeverBeNull; - late bool shouldAlwaysBeFalse; + bool? shouldAlwaysBeFalse; - late bool shouldErrorInRender; + bool? shouldErrorInRender; - late bool shouldErrorInMount; + bool? shouldErrorInMount; - late bool shouldErrorInUnmount; + bool? shouldErrorInUnmount; - late bool addExtraLogAndWarn; + bool? addExtraLogAndWarn; Function()? onComponentDidMount; - late bool shouldLog; + bool? shouldLog; } class SampleComponent extends UiComponent2 { - @override - Map get defaultProps => (newProps() - ..shouldAlwaysBeFalse = false - ..shouldErrorInRender = false - ..shouldErrorInMount = false - ..shouldErrorInUnmount = false - ..addExtraLogAndWarn = false - ..shouldLog = true); + // Prop defaults + bool get shouldAlwaysBeFalse => props.shouldAlwaysBeFalse ?? false; + bool get shouldErrorInRender => props.shouldErrorInRender ?? false; + bool get shouldErrorInMount => props.shouldErrorInMount ?? false; + bool get shouldErrorInUnmount => props.shouldErrorInUnmount ?? false; + bool get addExtraLogAndWarn => props.addExtraLogAndWarn ?? false; + bool get shouldLog => props.shouldLog ?? true; @override get propTypes => { @@ -41,7 +40,7 @@ class SampleComponent extends UiComponent2 { return PropError.required(info.propName, 'shouldNeverBeNull is necessary'); } - if (props.shouldLog == false && props.shouldAlwaysBeFalse == false) { + if (shouldLog == false && shouldAlwaysBeFalse == false) { return PropError.combination('shouldLog', 'shouldAlwaysBeFalse', 'logging is required'); } @@ -52,8 +51,8 @@ class SampleComponent extends UiComponent2 { return null; }, keyForProp((p) => p.shouldAlwaysBeFalse): (props, info) { - if (props.shouldAlwaysBeFalse) { - return PropError.value(props.shouldAlwaysBeFalse, info.propName, 'shouldAlwaysBeFalse should never equal true.'); + if (shouldAlwaysBeFalse) { + return PropError.value(shouldAlwaysBeFalse, info.propName, 'shouldAlwaysBeFalse should never equal true.'); } return null; @@ -63,22 +62,22 @@ class SampleComponent extends UiComponent2 { @override componentDidMount() { window.console.warn('Just a lil warning'); - if (props.shouldErrorInMount) throw Error(); + if (shouldErrorInMount) throw Error(); props.onComponentDidMount?.call(); } @override render() { window.console.warn('A second warning'); - if (props.shouldErrorInRender) { + if (shouldErrorInRender) { throw Error(); } else { - if (props.addExtraLogAndWarn) { + if (addExtraLogAndWarn) { window.console.log('Extra Log'); window.console.warn('Extra Warn'); } - if (props.shouldLog) window.console.log('Logging a standard log'); + if (shouldLog) window.console.log('Logging a standard log'); window.console.warn('And a third'); return Dom.div()( (Dom.button() @@ -97,6 +96,6 @@ class SampleComponent extends UiComponent2 { void componentWillUnmount() { super.componentWillUnmount(); - if (props.shouldErrorInUnmount) throw Error(); + if (shouldErrorInUnmount) throw Error(); } } diff --git a/test/over_react_test/helper_components/sample_component2.dart b/test/over_react_test/helper_components/sample_component2.dart index 46c0b269..3c56d124 100644 --- a/test/over_react_test/helper_components/sample_component2.dart +++ b/test/over_react_test/helper_components/sample_component2.dart @@ -7,7 +7,7 @@ part 'sample_component2.over_react.g.dart'; UiFactory Sample2 = castUiFactory(_$Sample2); // ignore: undefined_identifier mixin Sample2Props on UiProps { - late bool shouldNeverBeNull; + bool? shouldNeverBeNull; } class SampleComponent2 extends UiComponent2 { From ba2540c6ee188a060cd6a7fe69b36547a690e9ad Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 28 Dec 2023 13:18:40 -0600 Subject: [PATCH 18/22] Update deps --- pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/pubspec.yaml b/pubspec.yaml index bb860d7a..cc2d4e79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,6 +6,7 @@ environment: sdk: '>=2.13.0 <3.0.0' dependencies: + collection: ^1.15.0 js: ^0.6.1+1 matcher: ^0.12.1+4 meta: ^1.8.0 From 9c39e0bbdbd61040be2b683bd7da0cea6f355804 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 3 Jan 2024 21:32:26 -0600 Subject: [PATCH 19/22] Fix failing tests --- lib/src/over_react_test/react_util.dart | 8 ++++---- .../helper_components/sample_component.dart | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index 0025fcf5..1c7dc441 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -350,13 +350,13 @@ List /* < [1] > */ getAllByTestId(dynamic root, String value, {String key = defa } return react_test_utils.findAllInRenderedTree(root, allowInterop((descendant) { - late Map props; + Map? props; if (react_test_utils.isDOMComponent(descendant)) { props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } - return _hasTestId(props, key, value); + return props != null && _hasTestId(props, key, value); })); } @@ -576,14 +576,14 @@ List findDescendantsWithProp(/* [1] */ root, dynamic propKey) { return false; } - late Map props; + Map? props; if (react_test_utils.isDOMComponent(descendant)) { props = findDomNode(descendant)!.attributes; } else if (react_test_utils.isCompositeComponent(descendant)) { props = getProps(descendant); } - return props.containsKey(propKey); + return props != null && props.containsKey(propKey); })); return descendantsWithProp; diff --git a/test/over_react_test/helper_components/sample_component.dart b/test/over_react_test/helper_components/sample_component.dart index 5d9fff80..22988cee 100644 --- a/test/over_react_test/helper_components/sample_component.dart +++ b/test/over_react_test/helper_components/sample_component.dart @@ -40,7 +40,7 @@ class SampleComponent extends UiComponent2 { return PropError.required(info.propName, 'shouldNeverBeNull is necessary'); } - if (shouldLog == false && shouldAlwaysBeFalse == false) { + if (props.shouldLog == false && (props.shouldAlwaysBeFalse ?? false) == false) { return PropError.combination('shouldLog', 'shouldAlwaysBeFalse', 'logging is required'); } @@ -51,8 +51,8 @@ class SampleComponent extends UiComponent2 { return null; }, keyForProp((p) => p.shouldAlwaysBeFalse): (props, info) { - if (shouldAlwaysBeFalse) { - return PropError.value(shouldAlwaysBeFalse, info.propName, 'shouldAlwaysBeFalse should never equal true.'); + if (props.shouldAlwaysBeFalse ?? false) { + return PropError.value(props.shouldAlwaysBeFalse, info.propName, 'shouldAlwaysBeFalse should never equal true.'); } return null; From 141758397699857cccb508c23e2f6e878f85c496 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 3 Jan 2024 21:35:58 -0600 Subject: [PATCH 20/22] Remove matcher dependency --- pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index cc2d4e79..8984a3e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,6 @@ environment: dependencies: collection: ^1.15.0 js: ^0.6.1+1 - matcher: ^0.12.1+4 meta: ^1.8.0 over_react: ^4.1.2 react: ^7.0.0 From acd2ab768185710fd1e3bbb834ce40d24eef0cd3 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 3 Jan 2024 21:44:15 -0600 Subject: [PATCH 21/22] Clean up --- .../utils/test_common_component_required_props.dart | 2 -- .../utils/test_common_component_required_props_commponent2.dart | 2 -- 2 files changed, 4 deletions(-) diff --git a/test/over_react_test/utils/test_common_component_required_props.dart b/test/over_react_test/utils/test_common_component_required_props.dart index 51f5eb68..fd69a28a 100644 --- a/test/over_react_test/utils/test_common_component_required_props.dart +++ b/test/over_react_test/utils/test_common_component_required_props.dart @@ -30,8 +30,6 @@ class _$TestCommonRequiredProps extends UiProps { @nullableRequiredProp bool? defaultFoo; - - // todo add late prop?? } @Component() diff --git a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart index 3eaf0e58..d44a44ef 100644 --- a/test/over_react_test/utils/test_common_component_required_props_commponent2.dart +++ b/test/over_react_test/utils/test_common_component_required_props_commponent2.dart @@ -28,8 +28,6 @@ mixin TestCommonRequired2Props on UiProps { @nullableRequiredProp bool? defaultFoo; - - // todo add late prop?? } class TestCommonRequired2Component extends From 09ae6d948476b0f9172d2d5c2f3331517ef1907d Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 22 Jan 2024 18:04:54 -0700 Subject: [PATCH 22/22] Address feedback --- .../common_component_util.dart | 6 +- lib/src/over_react_test/jacket.dart | 8 +-- lib/src/over_react_test/react_util.dart | 15 ++-- test/over_react_test/jacket_test.dart | 69 +++++++------------ .../utils/shadow_nested_component.dart | 2 +- 5 files changed, 42 insertions(+), 58 deletions(-) diff --git a/lib/src/over_react_test/common_component_util.dart b/lib/src/over_react_test/common_component_util.dart index d51a82c0..17bf0dfd 100644 --- a/lib/src/over_react_test/common_component_util.dart +++ b/lib/src/over_react_test/common_component_util.dart @@ -337,10 +337,10 @@ void _testPropForwarding(BuilderOnlyUiFactory factory, dynamic childrenFactory() late Map forwardingTargetDefaults; switch (forwardingTargetType.dartComponentVersion) { // ignore: invalid_use_of_protected_member case ReactDartComponentVersion.component: // ignore: invalid_use_of_protected_member - forwardingTargetDefaults = forwardingTargetType.dartDefaultProps ?? {}; // ignore: deprecated_member_use + forwardingTargetDefaults = forwardingTargetType.dartDefaultProps!; // ignore: deprecated_member_use break; case ReactDartComponentVersion.component2: // ignore: invalid_use_of_protected_member - forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps ?? JsMap()); + forwardingTargetDefaults = JsBackedMap.backedBy(forwardingTargetType.defaultProps!); break; } @@ -530,7 +530,7 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory()) isComponent2 = version == ReactDartComponentVersion.component2; var jacket = mount(factory()(childrenFactory()), autoTearDown: false); - var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps ?? []; + var consumedProps = (jacket.getDartInstance() as component_base.UiComponent).consumedProps!; jacket.unmount(); for (var consumedProp in consumedProps) { diff --git a/lib/src/over_react_test/jacket.dart b/lib/src/over_react_test/jacket.dart index ad69cdc4..9af364cf 100644 --- a/lib/src/over_react_test/jacket.dart +++ b/lib/src/over_react_test/jacket.dart @@ -57,7 +57,7 @@ TestJacket mount(over_react.ReactElement reactElem } /// Provides more a more consistent and easier to use API to test and manipulate a rendered [ReactComponent]. -class TestJacket { +class TestJacket { TestJacket._(over_react.ReactElement reactElement, {Element? mountNode, this.attachedToDocument = false, this.autoTearDown = true}) : mountNode = mountNode ?? (DivElement() @@ -114,7 +114,7 @@ class TestJacket { /// > ``` /// > queryByTestId(jacket.mountNode, yourTestId) /// > ``` - ReactComponent? getInstance() { + ReactComponent getInstance() { // [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is // a DOM component (Element) - does not throw. The cast to `ReactComponent` - while not "sound", is harmless // since it is an anonymous JS interop class - not a Dart type. @@ -136,7 +136,7 @@ class TestJacket { ''')); } - return _renderedInstance as ReactComponent?; + return _renderedInstance as ReactComponent; } /// Returns the props associated with the mounted React composite component instance. @@ -202,7 +202,7 @@ class TestJacket { 'getDartInstance() is only supported when the rendered object is a composite (class based) component.'); } - return over_react.getDartComponent(_renderedInstance) as T?; + return over_react.getDartComponent(_renderedInstance); } /// Returns if the jacket component is mounted or not. diff --git a/lib/src/over_react_test/react_util.dart b/lib/src/over_react_test/react_util.dart index 1c7dc441..74da8c84 100644 --- a/lib/src/over_react_test/react_util.dart +++ b/lib/src/over_react_test/react_util.dart @@ -105,7 +105,7 @@ ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Cal void unmount(dynamic instanceOrContainerNode) { if (instanceOrContainerNode == null) return; - late Element? containerNode; + final Element? containerNode; if (instanceOrContainerNode is Element) { containerNode = instanceOrContainerNode; @@ -179,7 +179,7 @@ List _attachedReactContainers = []; {bool autoTearDown = true, Element? container, Callback? autoTearDownCallback}) { - final containerElement = container ??= DivElement() + final containerElement = container ?? DivElement() // Set arbitrary height and width for container to ensure nothing is cut off. ..style.setProperty('width', '800px') ..style.setProperty('height', '800px'); @@ -499,14 +499,21 @@ List _findDeep(Node? root, String itemSelector, {bool searchInShadowDom List nodes = []; void recursiveSeek(Node? _root, int _currentDepth) { // The LHS type prevents `rootQuerySelectorAll` from returning `_FrozenElementList>` instead of `` in DDC - final List Function(String) rootQuerySelectorAll = _root is ShadowRoot ? _root.querySelectorAll : _root is Element ? _root.querySelectorAll : (String s) => []; + final List Function(String) rootQuerySelectorAll; + if ( _root is ShadowRoot) { + rootQuerySelectorAll = _root.querySelectorAll; + } else if (_root is Element) { + rootQuerySelectorAll = _root.querySelectorAll; + } else { + throw Exception('Unhandled node that is neither a ShadowRoot nor an Element: $_root'); + } nodes.addAll(rootQuerySelectorAll(itemSelector)); if (!findMany && nodes.isNotEmpty) { return; } // This method of finding shadow roots may not be performant, but it's good enough for usage in tests. if (searchInShadowDom && (depth == null || _currentDepth < depth)) { - var foundShadows = rootQuerySelectorAll('*').where((el) => el.shadowRoot != null).map((el) => el.shadowRoot!).toList(); + var foundShadows = rootQuerySelectorAll('*').map((el) => el.shadowRoot).whereNotNull().toList(); for (var shadowRoot in foundShadows) { recursiveSeek(shadowRoot, _currentDepth + 1); } diff --git a/test/over_react_test/jacket_test.dart b/test/over_react_test/jacket_test.dart index 631076e9..ea603739 100644 --- a/test/over_react_test/jacket_test.dart +++ b/test/over_react_test/jacket_test.dart @@ -25,56 +25,46 @@ part 'jacket_test.over_react.g.dart'; /// Main entry point for TestJacket testing main() { group('mount: renders the given instance', () { + // Helper method to clean up each test. + void umountJacket(TestJacket jacket) { + jacket.unmount(); + expect(document.body!.children, isEmpty); + expect(jacket.isMounted, isFalse); + } + group('attached to the document', () { group('and unmounts after the test is done', () { - late TestJacket jacket; - setUp(() { expect(document.body!.children, isEmpty); }); - tearDown(() { - expect(document.body!.children, isEmpty); - expect(jacket.isMounted, isFalse); - }); - test('with the given container', () { var mountNode = DivElement(); - jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode); + final jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode); expect(document.body!.children[0], mountNode); expect(jacket.isMounted, isTrue); expect(mountNode.children[0], jacket.getNode()); + umountJacket(jacket); }); test('without the given container', () { - jacket = mount(Sample()(), attachedToDocument: true); + final jacket = mount(Sample()(), attachedToDocument: true); expect(jacket.isMounted, isTrue); expect(document.body!.children[0].children[0], jacket.getNode()); + umountJacket(jacket); }); }); group('and does not unmount after the test is done', () { - late TestJacket jacket; - setUp(() { expect(document.body!.children, isEmpty); }); - tearDown(() { - expect(document.body!.children, isNotEmpty); - expect(jacket.isMounted, isTrue); - - jacket.unmount(); - - expect(document.body!.children, isEmpty); - expect(jacket.isMounted, isFalse); - }); - test('with the given container', () { var mountNode = DivElement(); - jacket = mount(Sample()(), + final jacket = mount(Sample()(), attachedToDocument: true, mountNode: mountNode, autoTearDown: false @@ -83,78 +73,65 @@ main() { expect(document.body!.children[0], mountNode); expect(jacket.isMounted, isTrue); expect(mountNode.children[0], jacket.getNode()); + umountJacket(jacket); }); test('without the given container', () { - jacket = + final jacket = mount(Sample()(), attachedToDocument: true, autoTearDown: false); expect(jacket.isMounted, isTrue); expect(document.body!.children[0].children[0], jacket.getNode()); + umountJacket(jacket); }); }); }); group('not attached to the document', () { group('and unmounts after the test is done', () { - late TestJacket jacket; - setUp(() { expect(document.body!.children, isEmpty); }); - tearDown(() { - expect(document.body!.children, isEmpty); - expect(jacket.isMounted, isFalse); - }); - test('with the given container', () { var mountNode = DivElement(); - jacket = mount(Sample()(), mountNode: mountNode); + final jacket = mount(Sample()(), mountNode: mountNode); expect(document.body!.children, isEmpty); expect(jacket.isMounted, isTrue); expect(mountNode.children[0], jacket.getNode()); + umountJacket(jacket); }); test('without the given container', () { - jacket = mount(Sample()()); + final jacket = mount(Sample()()); expect(jacket.isMounted, isTrue); + umountJacket(jacket); }); }); group('and does not unmount after the test is done', () { - late TestJacket jacket; - setUp(() { expect(document.body!.children, isEmpty); }); - tearDown(() { - expect(document.body!.children, isEmpty); - expect(jacket.isMounted, isTrue); - - jacket.unmount(); - - expect(document.body!.children, isEmpty); - expect(jacket.isMounted, isFalse); - }); - test('with the given container', () { var mountNode = DivElement(); - jacket = mount(Sample()(), mountNode: mountNode, autoTearDown: false); + final jacket = mount(Sample()(), mountNode: mountNode, autoTearDown: false); expect(document.body!.children.isEmpty, isTrue); expect(jacket.isMounted, isTrue); expect(mountNode.children[0], jacket.getNode()); + umountJacket(jacket); }); test('without the given container', () { - jacket = mount(Sample()(), autoTearDown: false); + final jacket = mount(Sample()(), autoTearDown: false); expect(document.body!.children, isEmpty); expect(jacket.isMounted, isTrue); + umountJacket(jacket); }); }); }); diff --git a/test/over_react_test/utils/shadow_nested_component.dart b/test/over_react_test/utils/shadow_nested_component.dart index 290afb2f..1a1f6510 100644 --- a/test/over_react_test/utils/shadow_nested_component.dart +++ b/test/over_react_test/utils/shadow_nested_component.dart @@ -30,7 +30,7 @@ UiFactory ShadowNested = uiForwardRef( useEffect(() { var shadowRootFirstChild = DivElement()..dataset['test-id'] = props.shadowRootFirstChildTestId ?? 'shadowRootFirstChild'; - divRef.current?.attachShadow({'mode':'open'}).append(shadowRootFirstChild); + divRef.current!.attachShadow({'mode':'open'}).append(shadowRootFirstChild); react_dom.render(Fragment()(props.children), shadowRootFirstChild); return () => react_dom.unmountComponentAtNode(shadowRootFirstChild); }, []);