From 8d7448e33e4cbf588eb1423b25fee2b32454050e Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 25 Oct 2024 10:40:53 +0200 Subject: [PATCH 1/3] chore: tweak peer deps limits --- package.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 649a6c7e..2442457a 100644 --- a/package.json +++ b/package.json @@ -52,10 +52,10 @@ "redent": "^3.0.0" }, "peerDependencies": { - "jest": ">=28.0.0", - "react": ">=18.3.0", - "react-native": ">=0.75", - "react-test-renderer": ">=18.3.0" + "jest": ">=29.0.0", + "react": ">=18.2.0", + "react-native": ">=0.71", + "react-test-renderer": ">=18.2.0" }, "peerDependenciesMeta": { "jest": { @@ -94,5 +94,8 @@ "publishConfig": { "registry": "https://registry.npmjs.org" }, - "packageManager": "yarn@4.4.0" + "packageManager": "yarn@4.4.0", + "engines": { + "node": ">=18" + } } From 6e038f9ed589bce3b4de3205e306239cf246a3b9 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 25 Oct 2024 10:57:08 +0200 Subject: [PATCH 2/3] chore: sync act implementation with RTL --- src/act.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/act.ts b/src/act.ts index a0516850..940df677 100644 --- a/src/act.ts +++ b/src/act.ts @@ -1,8 +1,10 @@ // 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 +// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/types/index.d.ts +import * as React from 'react'; import { act as reactTestRendererAct } from 'react-test-renderer'; -type ReactAct = typeof reactTestRendererAct; +const reactAct = typeof React.act === 'function' ? React.act : reactTestRendererAct; +type ReactAct = 0 extends 1 & typeof React.act ? typeof reactTestRendererAct : typeof React.act; // See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT declare global { @@ -22,19 +24,13 @@ function withGlobalActEnvironment(actImplementation: ReactAct) { const previousActEnvironment = getIsReactActEnvironment(); setIsReactActEnvironment(true); - // this code is riddled with eslint disabling comments because this doesn't use real promises but eslint thinks we do try { // The return value of `act` is always a thenable. let callbackNeedsToBeAwaited = false; const actResult = actImplementation(() => { const result = callback(); - if ( - result !== null && - typeof result === 'object' && - // @ts-expect-error this should be a promise or thenable - // eslint-disable-next-line promise/prefer-await-to-then - typeof result.then === 'function' - ) { + // @ts-expect-error TS is too strict here + if (result !== null && typeof result === 'object' && typeof result.then === 'function') { callbackNeedsToBeAwaited = true; } return result; @@ -44,15 +40,17 @@ function withGlobalActEnvironment(actImplementation: ReactAct) { const thenable = actResult; return { then: (resolve: (value: never) => never, reject: (value: never) => never) => { - // eslint-disable-next-line + // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then thenable.then( // eslint-disable-next-line promise/always-return (returnValue) => { setIsReactActEnvironment(previousActEnvironment); + // @ts-expect-error resolve(returnValue); }, (error) => { setIsReactActEnvironment(previousActEnvironment); + // @ts-expect-error reject(error); }, ); @@ -71,7 +69,8 @@ function withGlobalActEnvironment(actImplementation: ReactAct) { }; } -const act = withGlobalActEnvironment(reactTestRendererAct) as ReactAct; +// @ts-expect-error +const act = withGlobalActEnvironment(reactAct) as ReactAct; export default act; export { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment }; From 318215324f984c0d2e1215a1e552bfd4c0e19fcb Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 25 Oct 2024 10:59:05 +0200 Subject: [PATCH 3/3] chore: update yarn.lock --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 915a4f92..10a58669 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2603,10 +2603,10 @@ __metadata: strip-ansi: "npm:^6.0.1" typescript: "npm:^5.5.4" peerDependencies: - jest: ">=28.0.0" - react: ">=18.3.0" - react-native: ">=0.75" - react-test-renderer: ">=18.3.0" + jest: ">=29.0.0" + react: ">=18.2.0" + react-native: ">=0.71" + react-test-renderer: ">=18.2.0" peerDependenciesMeta: jest: optional: true