Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test React 18 #968

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ dev_dependencies:
yaml: ^3.1.0
mocktail: ^1.0.3

dependency_overrides:
react:
git:
url: https://github.com/workiva/react-dart.git
ref: react-18-2-0
react_testing_library:
git:
url: https://github.com/workiva/react_testing_library.git
ref: r18
over_react_test:
git:
url: https://github.com/workiva/over_react_test.git
ref: react-18-test

workiva:
core_checks:
version: 1
Expand Down
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: 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