Skip to content

Commit

Permalink
Merge pull request #973 from Workiva/test-react-18-prep
Browse files Browse the repository at this point in the history
FED-3274 React 18 Prep
  • Loading branch information
btr-rmconsole-2[bot] authored Feb 4, 2025
2 parents 5c028ef + 4d54896 commit 471dccf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
7 changes: 3 additions & 4 deletions test/over_react/component/context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void main() {
});
});

group('experimental calculateChangeBits argument functions correctly', () {
group('experimental calculateChangeBits argument does not throw when used (has no effect in React 18)', () {
late Ref<ContextProviderWrapperComponent?> providerRef;
int? consumerEvenValue;
int? consumerOddValue;
Expand Down Expand Up @@ -243,15 +243,14 @@ void main() {
});

test('on value updates', () {
// Test common behavior between React 17 (calculateChangedBits working)
// and React 18 (it having no effect).
providerRef.current!.increment();
expect(consumerEvenValue, 2);
expect(consumerOddValue, 1);
providerRef.current!.increment();
expect(consumerEvenValue, 2);
expect(consumerOddValue, 3);
providerRef.current!.increment();
expect(consumerEvenValue, 4);
expect(consumerOddValue, 3);
});
});
});
Expand Down
24 changes: 12 additions & 12 deletions test/over_react/component/error_boundary/shared_stack_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:html';

import 'package:meta/meta.dart';
import 'package:over_react/over_react.dart' hide ErrorBoundary;
import 'package:react_testing_library/react_testing_library.dart' as rtl;
import 'package:over_react/react_dom.dart' as react_dom;
import 'package:over_react/components.dart';
import 'package:test/test.dart';

Expand All @@ -27,17 +29,15 @@ void sharedErrorBoundaryStackTests() {
void expectRenderErrorWithComponentName(ReactElement element,
{required String expectedComponentName}) {
final capturedInfos = <ReactErrorInfo>[];
expect(() {
rtl.render((ErrorBoundary()
..shouldLogErrors = false
..onComponentDidCatch = (error, info) {
capturedInfos.add(info);
})(element));
// Use prints as an easy way to swallow `print` calls and
// prevent RTL from forwarding console errors to the test output,
// since React error boundary logging is pretty noisy.
// TODO instead, disable logging in this rtl.render call once that option is available: FED-1641
}, prints(anything));
final mountNode = DivElement();
// Use react_dom.render instead of RTL to avoid errors on React 18 about
// `act` being used in prod builds.
react_dom.render((ErrorBoundary()
..shouldLogErrors = false
..onComponentDidCatch = (error, info) {
capturedInfos.add(info);
})(element), mountNode);
addTearDown(() => react_dom.unmountComponentAtNode(mountNode));

expect(capturedInfos, hasLength(1),
reason: 'test setup check; should have captured a single component error');
Expand Down
6 changes: 0 additions & 6 deletions tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1605,12 +1605,6 @@ Iterable<Union<Identifier, NamedType>> resolvedReferencesWithin(AstNode node) sy
}
}

extension on NamedType {
// NamedType.element is added in analyzer 5.11.0; we can't resolve to that version in Dart 2.18,
// so we'll add it here so we don't have to go back through and change it later.
Element? get element => name.staticElement;
}

enum HookTypeWithStableMethods { stateHook, reducerHook, transitionHook }

abstract class HookConstants {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:over_react_analyzer_plugin/src/diagnostic/analyzer_debug_helper.dart';
import 'package:over_react_analyzer_plugin/src/diagnostic_contributor.dart';
import 'package:over_react_analyzer_plugin/src/util/ast_util.dart';
import 'package:over_react_analyzer_plugin/src/util/pretty_print.dart';
import 'package:over_react_analyzer_plugin/src/util/prop_declarations/props_set_by_factory.dart';
import 'package:over_react_analyzer_plugin/src/util/prop_forwarding/forwarded_props.dart';
import 'package:over_react_analyzer_plugin/src/util/util.dart';
import 'package:over_react_analyzer_plugin/src/util/weak_map.dart';

import '../fluent_interface_util.dart';
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzer_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ publish_to: none
description: Dart analyzer plugin for OverReact
repository: https://github.com/Workiva/over_react/tree/master/tools/analyzer_plugin
environment:
sdk: '>=2.17.0 <3.0.0'
sdk: '>=2.19.0 <3.0.0'
dependencies:
analyzer: ^5.1.0
analyzer: ^5.11.0
analyzer_plugin: ^0.11.0
collection: ^1.15.0-nullsafety.4
meta: ^1.16.0
Expand Down
4 changes: 3 additions & 1 deletion tools/analyzer_plugin/tool/doc_generation_utils/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class ContributorVisitor extends RecursiveElementVisitor<void> {
void visitClassElement(ClassElement element) {
for (final config in _configs) {
if (!element.isOrIsSubtypeOfElementFromPackage(
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) continue;
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) {
continue;
}

final annotatedFields = element.fields
.where((f) => f.metadata.any((a) => a.element!.thisOrAncestorOfType<ClassElement>()?.name == 'DocsMeta'));
Expand Down

0 comments on commit 471dccf

Please sign in to comment.