Skip to content

Commit 16b868d

Browse files
Merge pull request #84 from Workiva/FED-3528-r18-dual-support
FED-3528 React 18 dual support
2 parents 0cd5d78 + a70fe88 commit 16b868d

29 files changed

+67713
-25481
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,46 @@ jobs:
2929
- name: Check formatting
3030
run: dart format . -l 120 --set-exit-if-changed
3131

32+
js-bundle:
33+
name: Build JS bundle
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version: 20
40+
41+
- name: Install dependencies
42+
run: npm install
43+
working-directory: ./js_src
44+
45+
- name: Build JS bundle
46+
run: npm run build
47+
working-directory: ./js_src
48+
49+
- name: Check for untracked API changes
50+
run: git diff --exit-code
51+
3252
test-unit:
3353
runs-on: ubuntu-latest
34-
name: unit tests (${{ matrix.release-mode && 'release' || 'dev' }})
54+
name: unit tests - React ${{ matrix.react }} (${{ matrix.release-mode && 'release' || 'dev' }})
3555
strategy:
3656
fail-fast: false
3757
matrix:
58+
react: [ 17, 18 ]
3859
release-mode: [true, false]
3960
steps:
4061
- uses: actions/checkout@v4
4162
- uses: dart-lang/setup-dart@v1
4263
with:
4364
sdk: 2.19.6
4465

66+
- name: Switch to React 17 Test HTML
67+
if: ${{ matrix.react == 17 }}
68+
run: |
69+
mv test/unit/unit_test_template.html test/unit/unit_test_template-old.html
70+
mv test/unit/unit_test_template-react17.html test/unit/unit_test_template.html
71+
4572
- name: Install dependencies
4673
run: dart pub get
4774
timeout-minutes: 2
@@ -54,5 +81,5 @@ jobs:
5481
args+=(--release)
5582
fi
5683
57-
dart run build_runner test "${args[@]}" -- -P concurrent-tests
58-
dart run build_runner test "${args[@]}" -- -P non-concurrent-tests
84+
dart run build_runner test "${args[@]}" -- -P concurrent-tests --preset=react${{ matrix.react }}
85+
dart run build_runner test "${args[@]}" -- -P non-concurrent-tests --preset=react${{ matrix.react }}

build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ targets:
44
build_web_compilers|entrypoint:
55
# These are globs for the entrypoints you want to compile.
66
generate_for:
7+
- example/**
78
- test/**.browser_test.dart
89
options:
910
# List any dart2js specific args here, or omit it.

dart_test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ presets:
2121
include_tags: run-alone
2222
concurrency: 1
2323
file: test/unit/user_event/type_test.dart
24+
25+
react18:
26+
exclude_tags: react-17
27+
28+
react17:
29+
exclude_tags: react-18

example/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<title>RTL - React 18</title>
6+
<script src="packages/react/js/react.dev.js"></script>
7+
<script src="packages/react_testing_library/js/react-testing-library.js"></script>
8+
</head>
9+
<body>
10+
<script defer src="main.js"></script>
11+
<script defer src="main.dart.js"></script>
12+
</body>
13+
</html>

example/main.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:react/react.dart' as react;
2+
import 'package:react_testing_library/react_testing_library.dart';
3+
import 'package:react_testing_library/user_event.dart';
4+
5+
main() {
6+
final content = react.button({
7+
'onClick': (_) {
8+
print('clicked');
9+
throw TestException('intentionally thrown during onClick');
10+
},
11+
}, 'Hello World');
12+
final view = render(content, autoTearDown: false);
13+
final button = view.getByRole('button', name: 'Hello World');
14+
try {
15+
UserEvent.click(button);
16+
} catch (e) {
17+
print('Caught exception $e');
18+
}
19+
}
20+
21+
class TestException implements Exception {
22+
final String message;
23+
24+
TestException(this.message);
25+
26+
@override
27+
String toString() => 'TestException: $message';
28+
}

example/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log('window.React.version', window.React.version);
2+
console.log('window.rtl', window.rtl);

js_src/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The underlying JS source for react_testing_library
2+
3+
The generated JS bundle is outputted in `lib/js/react-testing-library.js`.
4+
5+
To update it, run:
6+
7+
```
8+
npm run build
9+
```

0 commit comments

Comments
 (0)