Skip to content

Commit d6265d9

Browse files
suezzoMichał Parkitnythymikee
authored
chore: bump React Native to 0.64 RC (#626)
* chore: bump React Native to 0.64 RC * Snapshot update * Bumped node version to 12 on CI * Removed removed supress_comment syntax from config * codemod types-first * Prettied files after codemod * Added flow types to API returns * don't return null from fireEvent handlers * return ReactTestInstance instead of any * fix render returning any * less anys * less anys * simplify call type * simplify * add Flow to missing files, type debug better Co-authored-by: Michał Parkitny <michal.parkitny@callstack.com> Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 9a9abde commit d6265d9

23 files changed

+924
-1256
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ aliases:
1212

1313
defaults: &defaults
1414
docker:
15-
- image: circleci/node:10
15+
- image: circleci/node:12
1616
working_directory: ~/react-native-testing-library
1717

1818
jobs:

.flowconfig

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ emoji=true
3232
esproposal.optional_chaining=enable
3333
esproposal.nullish_coalescing=enable
3434

35+
well_formed_exports=true
36+
types_first=true
37+
3538
module.file_ext=.js
3639
module.file_ext=.json
3740
module.file_ext=.ios.js
@@ -41,15 +44,6 @@ munge_underscores=true
4144
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
4245
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
4346

44-
suppress_type=$FlowIssue
45-
suppress_type=$FlowFixMe
46-
suppress_type=$FlowFixMeProps
47-
suppress_type=$FlowFixMeState
48-
49-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
50-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
51-
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
52-
5347
[lints]
5448
sketchy-null-number=warn
5549
sketchy-null-mixed=warn

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
"@callstack/eslint-config": "^10.0.0",
3535
"@release-it/conventional-changelog": "^2.0.0",
3636
"@testing-library/jest-native": "~3.4.3",
37-
"@types/react": "^16.9.34",
37+
"@types/react": "^17.0.0",
3838
"@types/react-native": "^0.63.0",
3939
"@types/react-test-renderer": "^17.0.0",
4040
"babel-jest": "^26.0.1",
4141
"conventional-changelog-cli": "^2.0.11",
4242
"dedent": "^0.7.0",
4343
"eslint": "^7.0.0",
44-
"flow-bin": "^0.122.0",
44+
"flow-bin": "^0.137.0",
4545
"flow-copy-source": "^2.0.9",
4646
"jest": "^26.0.1",
47-
"react": "^16.13.1",
48-
"react-native": "^0.63.0-rc.1",
49-
"react-test-renderer": "^16.13.1",
47+
"react": "^17.0.1",
48+
"react-native": "^0.64.0-rc.1",
49+
"react-test-renderer": "^17.0.1",
5050
"release-it": "^14.0.3",
5151
"strip-ansi": "^6.0.0",
5252
"typescript": "^4.0.2"

src/__tests__/__snapshots__/render.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ exports[`debug: shallow 1`] = `
134134
>
135135
not fresh
136136
</Text>
137-
<Component
137+
<TextInput
138138
allowFontScaling={true}
139139
placeholder=\\"Add custom freshness\\"
140140
rejectResponderTermination={true}
141141
testID=\\"bananaCustomFreshness\\"
142142
underlineColorAndroid=\\"transparent\\"
143143
value=\\"Custom Freshie\\"
144144
/>
145-
<Component
145+
<TextInput
146146
allowFontScaling={true}
147147
placeholder=\\"Who inspected freshness?\\"
148148
rejectResponderTermination={true}
@@ -184,15 +184,15 @@ exports[`debug: shallow with message 1`] = `
184184
>
185185
not fresh
186186
</Text>
187-
<Component
187+
<TextInput
188188
allowFontScaling={true}
189189
placeholder=\\"Add custom freshness\\"
190190
rejectResponderTermination={true}
191191
testID=\\"bananaCustomFreshness\\"
192192
underlineColorAndroid=\\"transparent\\"
193193
value=\\"Custom Freshie\\"
194194
/>
195-
<Component
195+
<TextInput
196196
allowFontScaling={true}
197197
placeholder=\\"Who inspected freshness?\\"
198198
rejectResponderTermination={true}

src/__tests__/auto-cleanup-skip.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React from 'react';
23
import { View } from 'react-native';
34

src/__tests__/auto-cleanup.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React from 'react';
23
import { View } from 'react-native';
34
import { render } from '..';

src/act.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// @flow
22
import { act } from 'react-test-renderer';
3+
import type { Thenable } from './types.flow';
34

45
const actMock = (callback: () => void) => {
56
callback();
67
};
78

8-
export default act || actMock;
9+
export default (act || actMock: (callback: () => void) => Thenable);

src/fireEvent.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const invokeEvent = (
8989
const handler = findEventHandler(element, eventName, callsite);
9090

9191
if (!handler) {
92-
return null;
92+
return;
9393
}
9494

9595
let returnValue;
@@ -104,18 +104,20 @@ const invokeEvent = (
104104
const toEventHandlerName = (eventName: string) =>
105105
`on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
106106

107-
const pressHandler = (element: ReactTestInstance) =>
107+
const pressHandler = (element: ReactTestInstance): void =>
108108
invokeEvent(element, 'press', pressHandler);
109-
const changeTextHandler = (element: ReactTestInstance, ...data: Array<any>) =>
110-
invokeEvent(element, 'changeText', changeTextHandler, ...data);
111-
const scrollHandler = (element: ReactTestInstance, ...data: Array<any>) =>
109+
const changeTextHandler = (
110+
element: ReactTestInstance,
111+
...data: Array<any>
112+
): void => invokeEvent(element, 'changeText', changeTextHandler, ...data);
113+
const scrollHandler = (element: ReactTestInstance, ...data: Array<any>): void =>
112114
invokeEvent(element, 'scroll', scrollHandler, ...data);
113115

114116
const fireEvent = (
115117
element: ReactTestInstance,
116118
eventName: string,
117119
...data: Array<any>
118-
) => invokeEvent(element, eventName, fireEvent, ...data);
120+
): void => invokeEvent(element, eventName, fireEvent, ...data);
119121

120122
fireEvent.press = pressHandler;
121123
fireEvent.changeText = changeTextHandler;

src/helpers/a11yAPI.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import makeQuery from './makeQuery';
66
type GetReturn = ReactTestInstance;
77
type GetAllReturn = Array<ReactTestInstance>;
88
type QueryReturn = ReactTestInstance | null;
9-
type QueryAllReturn = Array<ReactTestInstance> | [];
9+
type QueryAllReturn = Array<ReactTestInstance>;
1010
type FindReturn = Promise<GetReturn>;
1111
type FindAllReturn = Promise<GetAllReturn>;
1212

13-
type A11yAPI = {|
13+
export type A11yAPI = {|
1414
// Label
1515
getByA11yLabel: (string | RegExp) => GetReturn,
1616
getByLabelText: (string | RegExp) => GetReturn,
@@ -116,7 +116,7 @@ export function matchObject<T: {}>(prop?: T, matcher: T): boolean {
116116
: false;
117117
}
118118

119-
const a11yAPI = (instance: ReactTestInstance): A11yAPI =>
119+
export const a11yAPI = (instance: ReactTestInstance): A11yAPI =>
120120
({
121121
...makeQuery(
122122
'accessibilityLabel',
@@ -239,5 +239,3 @@ const a11yAPI = (instance: ReactTestInstance): A11yAPI =>
239239
matchObject
240240
)(instance),
241241
}: any);
242-
243-
export default a11yAPI;

src/helpers/debugDeep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import format from './format';
66
*/
77
export default function debugDeep(
88
instance: ?ReactTestRendererJSON,
9-
message?: any = ''
9+
message?: string
1010
) {
1111
if (message) {
1212
console.log(`${message}\n\n`, format(instance));

src/helpers/debugShallow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import format from './format';
88
*/
99
export default function debugShallow(
1010
instance: ReactTestInstance | React.Element<any>,
11-
message?: any
11+
message?: string
1212
) {
1313
const { output } = shallowInternal(instance);
1414

src/helpers/errors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ErrorWithStack extends Error {
1010
}
1111
}
1212

13-
export const createLibraryNotSupportedError = (error: Error) =>
13+
export const createLibraryNotSupportedError = (error: Error): Error =>
1414
new Error(
1515
`Currently the only supported library to search by text is "react-native".\n\n${error.message}`
1616
);
@@ -19,7 +19,7 @@ export const prepareErrorMessage = (
1919
error: Error,
2020
name: ?string,
2121
value: ?mixed
22-
) => {
22+
): string => {
2323
// Strip info about custom predicate
2424
let errorMessage = error.message.replace(
2525
/ matching custom predicate[^]*/gm,
@@ -32,7 +32,7 @@ export const prepareErrorMessage = (
3232
return errorMessage;
3333
};
3434

35-
export const createQueryByError = (error: Error, callsite: Function) => {
35+
export const createQueryByError = (error: Error, callsite: Function): null => {
3636
if (error.message.includes('No instances found')) {
3737
return null;
3838
}

src/helpers/findByAPI.js

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,132 @@ import {
1313
} from './getByAPI';
1414
import { throwRenamedFunctionError } from './errors';
1515

16+
export type FindByAPI = {|
17+
findAllByDisplayValue: (
18+
value: string | RegExp,
19+
waitForOptions?: WaitForOptions
20+
) => Promise<Array<ReactTestInstance>>,
21+
findAllByPlaceholder: () => void,
22+
findAllByPlaceholderText: (
23+
placeholder: string | RegExp,
24+
waitForOptions?: WaitForOptions
25+
) => Promise<Array<ReactTestInstance>>,
26+
findAllByTestId: (
27+
testId: string | RegExp,
28+
waitForOptions?: WaitForOptions
29+
) => Promise<Array<ReactTestInstance>>,
30+
findAllByText: (
31+
text: string | RegExp,
32+
waitForOptions?: WaitForOptions
33+
) => Promise<Array<ReactTestInstance>>,
34+
findByDisplayValue: (
35+
value: string | RegExp,
36+
waitForOptions?: WaitForOptions
37+
) => Promise<ReactTestInstance>,
38+
findByPlaceholder: () => void,
39+
findByPlaceholderText: (
40+
placeholder: string | RegExp,
41+
waitForOptions?: WaitForOptions
42+
) => Promise<ReactTestInstance>,
43+
findByTestId: (
44+
testId: string | RegExp,
45+
waitForOptions?: WaitForOptions
46+
) => Promise<ReactTestInstance>,
47+
findByText: (
48+
text: string | RegExp,
49+
waitForOptions?: WaitForOptions
50+
) => Promise<ReactTestInstance>,
51+
|};
52+
1653
const makeFindQuery = <Text, Result>(
1754
instance: ReactTestInstance,
1855
getQuery: (instance: ReactTestInstance) => (text: Text) => Result,
1956
text: Text,
2057
waitForOptions: WaitForOptions
2158
): Promise<Result> => waitFor(() => getQuery(instance)(text), waitForOptions);
2259

23-
export const findByTestId = (instance: ReactTestInstance) => (
60+
export const findByTestId = (
61+
instance: ReactTestInstance
62+
): ((
63+
testId: string | RegExp,
64+
waitForOptions?: WaitForOptions
65+
) => Promise<ReactTestInstance>) => (
2466
testId: string | RegExp,
2567
waitForOptions: WaitForOptions = {}
2668
) => makeFindQuery(instance, getByTestId, testId, waitForOptions);
2769

28-
export const findAllByTestId = (instance: ReactTestInstance) => (
70+
export const findAllByTestId = (
71+
instance: ReactTestInstance
72+
): ((
73+
testId: string | RegExp,
74+
waitForOptions?: WaitForOptions
75+
) => Promise<Array<ReactTestInstance>>) => (
2976
testId: string | RegExp,
3077
waitForOptions: WaitForOptions = {}
3178
) => makeFindQuery(instance, getAllByTestId, testId, waitForOptions);
3279

33-
export const findByText = (instance: ReactTestInstance) => (
80+
export const findByText = (
81+
instance: ReactTestInstance
82+
): ((
83+
text: string | RegExp,
84+
waitForOptions?: WaitForOptions
85+
) => Promise<ReactTestInstance>) => (
3486
text: string | RegExp,
3587
waitForOptions: WaitForOptions = {}
3688
) => makeFindQuery(instance, getByText, text, waitForOptions);
3789

38-
export const findAllByText = (instance: ReactTestInstance) => (
90+
export const findAllByText = (
91+
instance: ReactTestInstance
92+
): ((
93+
text: string | RegExp,
94+
waitForOptions?: WaitForOptions
95+
) => Promise<Array<ReactTestInstance>>) => (
3996
text: string | RegExp,
4097
waitForOptions: WaitForOptions = {}
4198
) => makeFindQuery(instance, getAllByText, text, waitForOptions);
4299

43-
export const findByPlaceholderText = (instance: ReactTestInstance) => (
100+
export const findByPlaceholderText = (
101+
instance: ReactTestInstance
102+
): ((
103+
placeholder: string | RegExp,
104+
waitForOptions?: WaitForOptions
105+
) => Promise<ReactTestInstance>) => (
44106
placeholder: string | RegExp,
45107
waitForOptions: WaitForOptions = {}
46108
) => makeFindQuery(instance, getByPlaceholderText, placeholder, waitForOptions);
47109

48-
export const findAllByPlaceholderText = (instance: ReactTestInstance) => (
110+
export const findAllByPlaceholderText = (
111+
instance: ReactTestInstance
112+
): ((
113+
placeholder: string | RegExp,
114+
waitForOptions?: WaitForOptions
115+
) => Promise<Array<ReactTestInstance>>) => (
49116
placeholder: string | RegExp,
50117
waitForOptions: WaitForOptions = {}
51118
) =>
52119
makeFindQuery(instance, getAllByPlaceholderText, placeholder, waitForOptions);
53120

54-
export const findByDisplayValue = (instance: ReactTestInstance) => (
121+
export const findByDisplayValue = (
122+
instance: ReactTestInstance
123+
): ((
124+
value: string | RegExp,
125+
waitForOptions?: WaitForOptions
126+
) => Promise<ReactTestInstance>) => (
55127
value: string | RegExp,
56128
waitForOptions: WaitForOptions = {}
57129
) => makeFindQuery(instance, getByDisplayValue, value, waitForOptions);
58130

59-
export const findAllByDisplayValue = (instance: ReactTestInstance) => (
131+
export const findAllByDisplayValue = (
132+
instance: ReactTestInstance
133+
): ((
134+
value: string | RegExp,
135+
waitForOptions?: WaitForOptions
136+
) => Promise<Array<ReactTestInstance>>) => (
60137
value: string | RegExp,
61138
waitForOptions: WaitForOptions = {}
62139
) => makeFindQuery(instance, getAllByDisplayValue, value, waitForOptions);
63140

64-
export const findByAPI = (instance: ReactTestInstance) => ({
141+
export const findByAPI = (instance: ReactTestInstance): FindByAPI => ({
65142
findByTestId: findByTestId(instance),
66143
findByText: findByText(instance),
67144
findByPlaceholderText: findByPlaceholderText(instance),

src/helpers/format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import prettyFormat, { plugins } from 'pretty-format';
33

4-
const format = (input: ?ReactTestRendererJSON) =>
4+
const format = (input: ?ReactTestRendererJSON): typeof prettyFormat =>
55
prettyFormat(input, {
66
plugins: [plugins.ReactTestComponent, plugins.ReactElement],
77
highlight: true,

0 commit comments

Comments
 (0)