Skip to content

Commit 1360b73

Browse files
AugustinLFthymikee
andauthored
feat(breaking): migrate Flow to TS; remove some deprecated functions and aliases (#881)
* Port types to TS * Fix CI commands * Fix typo in yml file * Address PR comments * Remove aliased accessibility queries * Add flow types * Update build to support TS * Clean up removed aliased queries * Move @babel/plugin-transform-flow-strip-types to test config * Address PR comments * Delete flow tests * Retrigger pipeline * Update src/helpers/timers.ts Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 08915d1 commit 1360b73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1757
-1869
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ jobs:
3434
root: .
3535
paths:
3636
- .
37-
lint-and-flow:
37+
lint-and-typescript:
3838
<<: *defaults
3939
steps:
4040
- attach_workspace:
4141
at: ~/react-native-testing-library
4242
- run: |
4343
yarn lint
44-
yarn flow-check
45-
typescript:
44+
yarn typecheck
45+
flow:
4646
<<: *defaults
4747
steps:
4848
- attach_workspace:
4949
at: ~/react-native-testing-library
5050
- run: |
51-
yarn typescript-check
51+
yarn flow
5252
tests:
5353
<<: *defaults
5454
steps:
@@ -89,10 +89,10 @@ workflows:
8989
build-and-test:
9090
jobs:
9191
- install-dependencies
92-
- lint-and-flow:
92+
- lint-and-typescript:
9393
requires:
9494
- install-dependencies
95-
- typescript:
95+
- flow:
9696
requires:
9797
- install-dependencies
9898
- tests:

.flowconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ node_modules/warning/.*
1919
.*/node_modules/@react-native-community/cli/.*/.*
2020

2121
[include]
22+
.*/typings/
2223

2324
[libs]
2425
node_modules/react-native/interface.js
2526
node_modules/react-native/flow/
2627
flow-typed/
28+
.*/typings/index
2729

2830
[options]
2931
server.max_workers=4

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ test('form submits two answers', () => {
109109
const allQuestions = ['q1', 'q2'];
110110
const mockFn = jest.fn();
111111

112-
const { getAllByA11yLabel, getByText } = render(
112+
const { getAllByLabelText, getByText } = render(
113113
<QuestionsBoard questions={allQuestions} onSubmit={mockFn} />
114114
);
115115

116-
const answerInputs = getAllByA11yLabel('answer input');
116+
const answerInputs = getAllByLabelText('answer input');
117117

118118
fireEvent.changeText(answerInputs[0], 'a1');
119119
fireEvent.changeText(answerInputs[1], 'a2');

babel.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
presets: [
3-
'@babel/preset-flow',
3+
'@babel/preset-typescript',
44
'@babel/preset-react',
55
[
66
'@babel/preset-env',
@@ -13,4 +13,10 @@ module.exports = {
1313
],
1414
],
1515
plugins: ['@babel/plugin-proposal-class-properties'],
16+
env: {
17+
test: {
18+
// https://github.com/react-native-community/upgrade-support/issues/152
19+
plugins: ['@babel/plugin-transform-flow-strip-types'],
20+
},
21+
},
1622
};

package.json

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@testing-library/react-native",
33
"version": "9.1.0",
44
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
5-
"main": "build/index.js",
6-
"typings": "./typings/index.d.ts",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
77
"repository": {
88
"type": "git",
99
"url": "https://www.github.com/callstack/react-native-testing-library.git"
@@ -21,26 +21,31 @@
2121
"files": [
2222
"build/",
2323
"jest-preset/",
24-
"typings/index.d.ts",
24+
"typings/index.flow.js",
2525
"pure.js",
2626
"dont-cleanup-after-each.js"
2727
],
2828
"devDependencies": {
2929
"@babel/cli": "^7.8.4",
3030
"@babel/core": "^7.9.0",
3131
"@babel/plugin-proposal-class-properties": "^7.8.3",
32+
"@babel/plugin-transform-flow-strip-types": "^7.16.0",
3233
"@babel/preset-env": "^7.9.6",
3334
"@babel/preset-flow": "^7.9.0",
3435
"@babel/preset-react": "^7.9.4",
36+
"@babel/preset-typescript": "^7.16.0",
3537
"@callstack/eslint-config": "^11.0.0",
3638
"@release-it/conventional-changelog": "^2.0.0",
3739
"@testing-library/jest-native": "~4.0.2",
40+
"@types/jest": "^27.0.0",
3841
"@types/react": "^17.0.0",
39-
"@types/react-native": "^0.66.5",
42+
"@types/react-native": "^0.66.6",
4043
"@types/react-test-renderer": "^17.0.0",
4144
"babel-jest": "^27.0.0",
4245
"conventional-changelog-cli": "^2.0.11",
46+
"cp-cli": "^2.0.0",
4347
"dedent": "^0.7.0",
48+
"del-cli": "^3.0.1",
4449
"eslint": "^7.0.0",
4550
"flow-bin": "^0.141.0",
4651
"flow-copy-source": "^2.0.9",
@@ -61,25 +66,30 @@
6166
"react-test-renderer": ">=16.0.0"
6267
},
6368
"scripts": {
69+
"clean": "del build",
6470
"test": "jest",
65-
"flow-check": "flow check",
66-
"typescript-check": "tsc --noEmit --skipLibCheck --jsx react ./typings/__tests__/*",
71+
"typecheck": "tsc",
72+
"flow": "flow",
73+
"copy-flowtypes": "cp typings/index.flow.js build",
6774
"lint": "eslint src --cache",
6875
"release": "release-it",
69-
"prepublish": "yarn build && yarn copy-flowtypes",
70-
"copy-flowtypes": "flow-copy-source --ignore __tests__/*.js src build",
71-
"build": "rm -rf build; babel src --out-dir build --ignore 'src/__tests__/*'"
76+
"prepublish": "yarn build",
77+
"build:js": "babel src --out-dir build --extensions \".js,.ts\" --source-maps --ignore \"**/__tests__/**\"",
78+
"build:js:watch": "yarn build:js --watch",
79+
"build:ts": "tsc --build tsconfig.release.json",
80+
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
81+
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
82+
"prepare": "yarn build"
7283
},
7384
"jest": {
7485
"preset": "../jest-preset",
75-
"moduleFileExtensions": [
76-
"js",
77-
"json"
78-
],
7986
"rootDir": "./src",
8087
"testPathIgnorePatterns": [
8188
"timerUtils"
8289
],
83-
"testTimeout": 30000
90+
"testTimeout": 30000,
91+
"transformIgnorePatterns": [
92+
"/node_modules/(?!(@react-native|react-native)/).*/"
93+
]
8494
}
8595
}

0 commit comments

Comments
 (0)