mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
[v13] chore: remove react 16 & 17 code (#1602)
* chore: remove React 16 & 17 code chore: remove more chore: react version 18.3.1 docs: migration guide * refactor: finish merge
This commit is contained in:
committed by
Maciej Jastrzębski
parent
398f09a1c9
commit
b797cf4cc5
+3
-4
@@ -26,7 +26,6 @@
|
||||
"clean": "del build",
|
||||
"test": "jest",
|
||||
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
||||
"test:react-17": "scripts/test_react_17",
|
||||
"typecheck": "tsc",
|
||||
"flow": "flow",
|
||||
"copy-flowtypes": "cp typings/index.flow.js build",
|
||||
@@ -58,9 +57,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"jest": ">=28.0.0",
|
||||
"react": ">=16.8.0",
|
||||
"react-native": ">=0.59",
|
||||
"react-test-renderer": ">=16.8.0"
|
||||
"react": ">=18.2.0",
|
||||
"react-native": ">=0.73",
|
||||
"react-test-renderer": ">=18.2.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"jest": {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cp yarn.lock yarn.lock.backup
|
||||
cp package.json package.json.backup
|
||||
|
||||
yarn add -D react@17.0.2 react-test-renderer@17.0.2 react-native@0.68.3 --ignore-scripts
|
||||
yarn test:ci --collectCoverage=false
|
||||
|
||||
mv package.json.backup package.json
|
||||
mv yarn.lock.backup yarn.lock
|
||||
|
||||
yarn --ignore-scripts
|
||||
+1
-4
@@ -1,7 +1,6 @@
|
||||
// This file and the act() implementation is sourced from react-testing-library
|
||||
// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js
|
||||
import { act as reactTestRendererAct } from 'react-test-renderer';
|
||||
import { checkReactVersionAtLeast } from './react-versions';
|
||||
|
||||
type ReactAct = typeof reactTestRendererAct;
|
||||
|
||||
@@ -72,9 +71,7 @@ function withGlobalActEnvironment(actImplementation: ReactAct) {
|
||||
};
|
||||
}
|
||||
|
||||
const act: ReactAct = checkReactVersionAtLeast(18, 0)
|
||||
? (withGlobalActEnvironment(reactTestRendererAct) as ReactAct)
|
||||
: reactTestRendererAct;
|
||||
const act = withGlobalActEnvironment(reactTestRendererAct) as ReactAct;
|
||||
|
||||
export default act;
|
||||
export { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };
|
||||
|
||||
+10
-26
@@ -1,8 +1,7 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import act, { getIsReactActEnvironment, setReactActEnvironment } from '../act';
|
||||
import { getIsReactActEnvironment, setReactActEnvironment } from '../act';
|
||||
import { flushMicroTasks } from '../flush-micro-tasks';
|
||||
import { checkReactVersionAtLeast } from '../react-versions';
|
||||
|
||||
/**
|
||||
* Run given async callback with temporarily disabled `act` environment and flushes microtasks queue.
|
||||
@@ -11,30 +10,15 @@ import { checkReactVersionAtLeast } from '../react-versions';
|
||||
* @returns Result of the callback
|
||||
*/
|
||||
export async function wrapAsync<Result>(callback: () => Promise<Result>): Promise<Result> {
|
||||
if (checkReactVersionAtLeast(18, 0)) {
|
||||
const previousActEnvironment = getIsReactActEnvironment();
|
||||
setReactActEnvironment(false);
|
||||
const previousActEnvironment = getIsReactActEnvironment();
|
||||
setReactActEnvironment(false);
|
||||
|
||||
try {
|
||||
const result = await callback();
|
||||
// Flush the microtask queue before restoring the `act` environment
|
||||
await flushMicroTasks();
|
||||
return result;
|
||||
} finally {
|
||||
setReactActEnvironment(previousActEnvironment);
|
||||
}
|
||||
try {
|
||||
const result = await callback();
|
||||
// Flush the microtask queue before restoring the `act` environment
|
||||
await flushMicroTasks();
|
||||
return result;
|
||||
} finally {
|
||||
setReactActEnvironment(previousActEnvironment);
|
||||
}
|
||||
|
||||
if (!checkReactVersionAtLeast(16, 9)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Wrapping with act for react version 16.9 to 17.x
|
||||
let result: Result;
|
||||
await act(async () => {
|
||||
result = await callback();
|
||||
});
|
||||
|
||||
// Either we have result or `callback` threw error
|
||||
return result!;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ Migration to React Native Testing Library version 13 from version 12.x.
|
||||
|
||||
# Breaking changes
|
||||
|
||||
## Supported React and React Native versions
|
||||
|
||||
This version supports only React 19 and corresponding React Native versions. If you use React 18 or 19, please use latest of v12 versions.
|
||||
|
||||
[Note: at the moment there is no React Native for React 19, and React 19 is still in beta, so we use React 18.3 for the time being].
|
||||
|
||||
## Removed deprecated \*ByAccessibilityState queries
|
||||
|
||||
This deprecated query has been removed as is typically too general to give meaningful results. Use one of the following options:
|
||||
|
||||
Reference in New Issue
Block a user