Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with React 19 RC.1 and adjust tests accordingly #12140

Merged
merged 60 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
110e5e3
bump react to 19 rc.1
phryneas Nov 18, 2024
3226c83
patch `REACT_FALLBACK_THROTTLE_MS`
phryneas Nov 25, 2024
db33a3b
swap sync usages of `render` to their async counterparts
phryneas Nov 26, 2024
2a7df4f
bump dep
phryneas Nov 26, 2024
1f6af4f
adjust delay and `REACT_FALLBACK_THROTTLE_MS`
phryneas Nov 26, 2024
7da06c2
fix up a bunch of tests
phryneas Nov 26, 2024
102d382
fixup
phryneas Nov 26, 2024
dbb4f7b
disable patch until all tests work
phryneas Nov 26, 2024
3c83984
add delay to all mocks I could find
phryneas Nov 26, 2024
b84508b
more rendercounts
phryneas Nov 26, 2024
d04889f
down to one failing `useSuspenseQuery` test...
phryneas Nov 27, 2024
cccfae9
`useSuspenseQuery` not failing anymore
phryneas Nov 27, 2024
ca0a751
add this to a lot more test files
phryneas Nov 27, 2024
203aaaa
useBackgroundQuery
phryneas Nov 27, 2024
670eafe
useQuery
phryneas Nov 27, 2024
3f1a659
fix up async calls
phryneas Nov 28, 2024
bcf52df
disable act environment for all render stream tests
phryneas Nov 28, 2024
852e33e
remove & forbid wrong act calls
phryneas Nov 28, 2024
651a3d2
simplify lint rules
phryneas Nov 28, 2024
0ae48ce
undo for a second
phryneas Nov 28, 2024
1d0c877
slow down a few select tests
phryneas Nov 28, 2024
f02f1a2
work around one weird test
phryneas Nov 28, 2024
4e8253c
format
phryneas Nov 28, 2024
b1af798
use modern version of testing library for React 17
phryneas Nov 28, 2024
c7b13af
remove patch
phryneas Nov 28, 2024
8a4738a
fix most React 17 tests
phryneas Nov 29, 2024
a7d9f66
Merge branch 'main' into pr/react-19-rc.1
phryneas Nov 29, 2024
161c540
update RRSTL
phryneas Nov 29, 2024
ddcf14c
undo some React17 specific changes
phryneas Nov 29, 2024
cf5ebd7
inline actAsync
phryneas Nov 29, 2024
b6c8fae
inline `renderAsync`
phryneas Nov 29, 2024
a608302
inline `renderHookAsync`
phryneas Nov 29, 2024
2e937e6
revert `@testing-library/react` to npm
phryneas Nov 29, 2024
bc34409
adjust patch
phryneas Nov 29, 2024
4394675
forgot an import
phryneas Nov 29, 2024
34a6051
don't use `userEventWithoutAct`
phryneas Dec 2, 2024
3842150
bump
phryneas Dec 2, 2024
5ff137e
bump delay a bit
phryneas Dec 2, 2024
71bab96
remove `disableActWarnings` tool
phryneas Dec 2, 2024
99bc011
await rerender
phryneas Dec 2, 2024
763d65b
missing actAsync
phryneas Dec 2, 2024
5aa78f1
some more type updates
phryneas Dec 2, 2024
92a8250
some more act calls
phryneas Dec 2, 2024
c9d918a
don't patch React
phryneas Dec 2, 2024
5cf5930
`actAsync` for React 17
phryneas Dec 2, 2024
eb9b49f
actAsync -> act
phryneas Dec 2, 2024
e29c31d
update dep
phryneas Dec 2, 2024
09240a7
fix React 17 specific act quirk
phryneas Dec 2, 2024
28b705e
remove `renderToRenderStream`
phryneas Dec 3, 2024
35e3f7f
enable `@typescript-eslint/no-floating-promises` lint rule
phryneas Dec 3, 2024
c58a07d
some more await/void
phryneas Dec 3, 2024
56b1bb9
update rrstl dependency
phryneas Dec 4, 2024
4087349
remove unneccessary await - oops
phryneas Dec 4, 2024
a81e42e
PR feedback
phryneas Dec 4, 2024
1e5fdea
Update src/testing/internal/scenarios/index.ts
phryneas Dec 4, 2024
6d308a7
Update src/testing/internal/rtl/actAsync.ts
phryneas Dec 4, 2024
a3d4455
Update src/testing/internal/rtl/renderAsync.ts
phryneas Dec 4, 2024
0247ac7
fix typo
phryneas Dec 4, 2024
143609b
Merge branch 'main' into pr/react-19-rc.1
phryneas Dec 4, 2024
1507630
make overriding intentional via an argument
phryneas Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ workflows:
- "@types/[email protected] @types/[email protected]"
- "@types/react@17 @types/react-dom@17"
- "@types/react@18 @types/react-dom@18"
- "@types/react@npm:[email protected].0 @types/react-dom@npm:[email protected].0"
- "@types/react@npm:[email protected].1 @types/react-dom@npm:[email protected].1"
- "typescript@next"
security-scans:
jobs:
Expand Down
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
"rules": {
"testing-library/prefer-user-event": "error",
"testing-library/no-wait-for-multiple-assertions": "off",
"local-rules/require-using-disposable": "error"
"local-rules/require-using-disposable": "error",
"local-rules/require-disable-act-environment": "error",
"local-rules/forbid-act-in-disabled-act-environment": "error",
"@typescript-eslint/no-floating-promises": "warn"
}
}
],
Expand Down
1 change: 0 additions & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const standardReact17Config = {
"^react-dom$": "react-dom-17",
"^react-dom/server$": "react-dom-17/server",
"^react-dom/test-utils$": "react-dom-17/test-utils",
"^@testing-library/react$": "@testing-library/react-12",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

},
};

Expand Down
56 changes: 56 additions & 0 deletions eslint-local-rules/forbid-act-in-disabled-act-environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { rule } from "./forbid-act-in-disabled-act-environment";
import { ruleTester } from "./testSetup";

ruleTester.run("forbid-act-in-disabled-act-environment", rule, {
valid: [
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
act(() => {})
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
actAsync(() => {})
}
`,
],
invalid: [
`
() => {
using _disabledAct = disableActEnvironment();
act(() => {})
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
actAsync(() => {})
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
() => {
act(() => {})
}
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
() => {
actAsync(() => {})
}
}
`,
].map((code) => ({
code,
errors: [{ messageId: "forbiddenActInNonActEnvironment" }],
})),
});
63 changes: 63 additions & 0 deletions eslint-local-rules/forbid-act-in-disabled-act-environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ESLintUtils } from "@typescript-eslint/utils";

export const rule = ESLintUtils.RuleCreator.withoutDocs({
create(context) {
let depth = 1;
let disabledDepth: number | false = false;

function EnterFn() {
depth++;
}
function ExitFn() {
depth--;
if (disabledDepth !== false && disabledDepth > depth) {
disabledDepth = false;
}
}

return {
CallExpression(node) {
const directCallee =
node.callee.type === "Identifier" ? node.callee
: node.callee.type === "MemberExpression" ? node.callee.property
: null;

if (
directCallee?.type === "Identifier" &&
directCallee.name === "disableActEnvironment"
) {
if (disabledDepth === false) {
disabledDepth = depth;
}
}

if (
directCallee?.type === "Identifier" &&
(directCallee.name === "act" || directCallee.name === "actAsync")
) {
if (disabledDepth !== false) {
context.report({
messageId: "forbiddenActInNonActEnvironment",
node: node,
});
}
}
},
ArrowFunctionExpression: EnterFn,
FunctionExpression: EnterFn,
FunctionDeclaration: EnterFn,
"ArrowFunctionExpression:exit": ExitFn,
"FunctionExpression:exit": ExitFn,
"FunctionDeclaration:exit": ExitFn,
};
},
meta: {
messages: {
forbiddenActInNonActEnvironment:
"`act` should not be called in a `disableActEnvironment`.",
},
type: "problem",
schema: [],
},
defaultOptions: [],
});
4 changes: 4 additions & 0 deletions eslint-local-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ require("ts-node").register({

module.exports = {
"require-using-disposable": require("./require-using-disposable").rule,
"require-disable-act-environment":
require("./require-disable-act-environment").rule,
"forbid-act-in-disabled-act-environment":
require("./forbid-act-in-disabled-act-environment").rule,
};
120 changes: 120 additions & 0 deletions eslint-local-rules/require-disable-act-environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { rule } from "./require-disable-act-environment";
import { ruleTester } from "./testSetup";

ruleTester.run("require-disable-act-environment", rule, {
valid: [
`
() => {
using _disabledAct = disableActEnvironment();
const { takeRender } = someCall()
const {} = takeRender()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
const {} = renderStream.takeRender()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
const { takeSnapshot } = someCall()
const {} = takeSnapshot()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
const {} = renderStream.takeSnapshot()
}
`,
`
using _disabledAct = disableActEnvironment();
() => {
const { takeRender } = someCall()
const {} = takeRender()
}
`,
`
using _disabledAct = disableActEnvironment();
() => {
const {} = renderStream.takeRender()
}
`,
`
using _disabledAct = disableActEnvironment();
() => {
const { takeSnapshot } = someCall()
const {} = takeSnapshot()
}
`,
`
using _disabledAct = disableActEnvironment();
() => {
const {} = renderStream.takeSnapshot()
}
`,
],
invalid: [
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
const { takeRender } = someCall()
takeRender()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
renderStream.takeRender()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
const { takeSnapshot } = someCall()
takeSnapshot()
}
`,
`
() => {
using _disabledAct = disableActEnvironment();
}
() => {
renderStream.takeSnapshot()
}
`,
`
() => {
const { takeRender } = someCall()
takeRender()
}
`,
`
() => {
renderStream.takeRender()
}
`,
`
() => {
const { takeSnapshot } = someCall()
takeSnapshot()
}
`,
`
() => {
renderStream.takeSnapshot()
}
`,
].map((code) => ({
code,
errors: [{ messageId: "missingDisableActEnvironment" }],
})),
});
83 changes: 83 additions & 0 deletions eslint-local-rules/require-disable-act-environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ESLintUtils, ASTUtils } from "@typescript-eslint/utils";
import type { TSESTree as AST } from "@typescript-eslint/types";

type Fn =
| AST.FunctionDeclaration
| AST.ArrowFunctionExpression
| AST.FunctionExpression;

export const rule = ESLintUtils.RuleCreator.withoutDocs({
create(context) {
let depth = 1;
let disabledDepth: number | false = false;

function EnterFn() {
depth++;
}
function ExitFn() {
depth--;
if (disabledDepth !== false && disabledDepth > depth) {
disabledDepth = false;
}
}

return {
CallExpression(node) {
const directCallee =
node.callee.type === "Identifier" ? node.callee
: node.callee.type === "MemberExpression" ? node.callee.property
: null;

if (
directCallee?.type === "Identifier" &&
directCallee.name === "disableActEnvironment"
) {
if (disabledDepth === false) {
disabledDepth = depth;
}
}

if (
directCallee?.type === "Identifier" &&
(directCallee.name === "takeRender" ||
directCallee.name === "takeSnapshot")
) {
if (disabledDepth === false) {
context.report({
messageId: "missingDisableActEnvironment",
node: node,
});
}
}
},
ArrowFunctionExpression: EnterFn,
FunctionExpression: EnterFn,
FunctionDeclaration: EnterFn,
"ArrowFunctionExpression:exit": ExitFn,
"FunctionExpression:exit": ExitFn,
"FunctionDeclaration:exit": ExitFn,
};
},
meta: {
messages: {
missingDisableActEnvironment:
"Tests using a render stream should call `disableActEnvironment`.",
},
type: "problem",
schema: [],
},
defaultOptions: [],
});

function findParentFunction(node: AST.Node): Fn | undefined {
let parentFunction: AST.Node | undefined = node;
while (
parentFunction != null &&
parentFunction.type !== "FunctionDeclaration" &&
parentFunction.type !== "FunctionExpression" &&
parentFunction.type !== "ArrowFunctionExpression"
) {
parentFunction = parentFunction.parent;
}
return parentFunction;
}
Loading
Loading