Skip to content

Commit 0e4adb3

Browse files
authored
Merge pull request #9 from kapral18/docs/add-default-hidden-case
feat: add defaultHidden performance tests and update README
2 parents d3bc2a7 + 46750cd commit 0e4adb3

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ visible bottleneck for the CI/CD pipeline.
5959

6060
Here are the preliminary results from CI agent vs local m3 pro run:
6161

62-
<img src="./assets/SCR-20241116-quak.png" width="100%" />
62+
<img src="./assets/SCR-20241116-quak.png" width="100%" alt="Preliminary results" />
63+
64+
## Default hidden case
65+
66+
Following the classic [discussion](https://github.com/testing-library/dom-testing-library/issues/552) about slow selectors in RTL, we also tested the recommendation to use `configure({ defaultHidden: true })` to speed up the selectors. The results further prove
67+
that there is negligible algorithmic perf difference in performance between the selectors when the defaultHidden is set to true on a fast modern laptop and even more so on a slower CI agent.
68+
69+
**CI agent results**
70+
<img src="./assets/ci_hidden_true_before_after.png" width="100%" alt="CI agent results" />
71+
72+
**Local macbook results**
73+
<img src="./assets/macbook_hidden_true_before_after.png" width="100%" alt="Local macbook results" />
343 KB
Loading
335 KB
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview",
11-
"test": "jest"
11+
"test:default": "jest src/App.test.tsx",
12+
"test:default:hidden": "jest src/App.defaultHidden.test.tsx"
1213
},
1314
"dependencies": {
1415
"react": "^18.3.1",

src/App.defaultHidden.test.tsx

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { configure } from "@testing-library/dom";
2+
import { waitFor, render, screen } from "@testing-library/react";
3+
import userEvent from "@testing-library/user-event";
4+
5+
import App from "./App";
6+
7+
configure({ defaultHidden: true });
8+
9+
const components = [
10+
{
11+
name: "Simple",
12+
component: <App iterations={2} />,
13+
iterations: 2,
14+
depth: 1,
15+
},
16+
{
17+
name: "Medium",
18+
component: <App iterations={5} />,
19+
iterations: 5,
20+
depth: 3,
21+
},
22+
{
23+
name: "Complex",
24+
component: <App iterations={10} />,
25+
iterations: 10,
26+
depth: 5,
27+
},
28+
];
29+
30+
describe.each(components)(
31+
"Perf testing $name component with iterations complexity if '$iterations' and depth complexity of '$depth'",
32+
({ component, iterations }) => {
33+
beforeEach(() => {
34+
render(component);
35+
});
36+
37+
it("getByRole selector performance", async () => {
38+
for (const index of Array.from({ length: iterations }).keys()) {
39+
const button = screen.getByRole("button", {
40+
name: `Button label ${index}`,
41+
});
42+
await userEvent.click(button);
43+
await waitFor(() =>
44+
expect(
45+
screen.getByRole("paragraph", {
46+
name: `Service label ${index}`,
47+
}),
48+
),
49+
);
50+
}
51+
});
52+
53+
it("getByLabelText selector performance", async () => {
54+
for (const index of Array.from({ length: iterations }).keys()) {
55+
const button = screen.getByLabelText(`Button label ${index}`);
56+
await userEvent.click(button);
57+
await waitFor(() =>
58+
expect(screen.getByLabelText(`Service label ${index}`)),
59+
);
60+
}
61+
});
62+
63+
it("getByPlaceholderText selector performance", async () => {
64+
for (const index of Array.from({ length: iterations }).keys()) {
65+
const input = screen.getByPlaceholderText(
66+
`Button input placeholder ${index}`,
67+
);
68+
await userEvent.click(input);
69+
await waitFor(() =>
70+
expect(
71+
screen.getByPlaceholderText(
72+
`Service textarea placeholder ${index}`,
73+
),
74+
),
75+
);
76+
}
77+
});
78+
79+
it("getByText selector performance", async () => {
80+
for (const index of Array.from({ length: iterations }).keys()) {
81+
const button = screen.getByText(`Button text ${index}`);
82+
await userEvent.click(button);
83+
await waitFor(() =>
84+
expect(screen.getByText(`Service text ${index}`)).toBeInTheDocument(),
85+
);
86+
}
87+
});
88+
89+
it("getByDisplayValue selector performance", async () => {
90+
for (const index of Array.from({ length: iterations }).keys()) {
91+
const input = screen.getByDisplayValue(`Button input value ${index}`);
92+
await userEvent.click(input);
93+
await waitFor(() =>
94+
expect(screen.getByDisplayValue(`Service textarea value ${index}`)),
95+
);
96+
}
97+
});
98+
99+
it("getByAltText selector performance", async () => {
100+
for (const index of Array.from({ length: iterations }).keys()) {
101+
const img = screen.getByAltText(`Button image alt ${index}`);
102+
await userEvent.click(img);
103+
await waitFor(() =>
104+
expect(
105+
screen.getByAltText(`Service image alt ${index}`),
106+
).toBeInTheDocument(),
107+
);
108+
}
109+
});
110+
111+
it("getByTitle selector performance", async () => {
112+
for (const index of Array.from({ length: iterations }).keys()) {
113+
const button = screen.getByTitle(`Button title ${index}`);
114+
await userEvent.click(button);
115+
await waitFor(() =>
116+
expect(
117+
screen.getByTitle(`Service title ${index}`),
118+
).toBeInTheDocument(),
119+
);
120+
}
121+
});
122+
123+
it("getByTestId selector performance", async () => {
124+
for (const index of Array.from({ length: iterations }).keys()) {
125+
const button = screen.getByTestId(`button-test-id-${index}`);
126+
await userEvent.click(button);
127+
await waitFor(() =>
128+
expect(
129+
screen.getByTestId(`button-test-id-${index}`),
130+
).toBeInTheDocument(),
131+
);
132+
}
133+
});
134+
},
135+
);

0 commit comments

Comments
 (0)