Skip to content

Commit 380b59e

Browse files
feat: add reassure testing to control render count
1 parent adc3bc7 commit 380b59e

File tree

8 files changed

+842
-43
lines changed

8 files changed

+842
-43
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules/*
22
yarn.lock
3+
4+
# Reassure performance testing files
5+
.reassure/
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
import React from 'react';
2+
import { measureRenders } from 'reassure';
3+
import { waitFor } from '@testing-library/react-native';
4+
import ConfirmHcaptcha from '../index';
5+
6+
describe('ConfirmHcaptcha Performance Tests', () => {
7+
test('ConfirmHcaptcha initial render performance', async () => {
8+
await measureRenders(
9+
<ConfirmHcaptcha
10+
siteKey="00000000-0000-0000-0000-000000000000"
11+
baseUrl="https://hcaptcha.com"
12+
languageCode="en"
13+
onMessage={() => {}}
14+
/>
15+
);
16+
});
17+
18+
test('ConfirmHcaptcha render with all props', async () => {
19+
await measureRenders(
20+
<ConfirmHcaptcha
21+
size="compact"
22+
siteKey="00000000-0000-0000-0000-000000000000"
23+
passiveSiteKey={false}
24+
baseUrl="https://hcaptcha.com"
25+
languageCode="en"
26+
orientation="portrait"
27+
showLoading={false}
28+
closableLoading={false}
29+
backgroundColor="rgba(0, 0, 0, 0.3)"
30+
loadingIndicatorColor="#999999"
31+
theme="light"
32+
rqdata='{"some": "data"}'
33+
sentry={true}
34+
jsSrc="https://js.hcaptcha.com/1/api.js"
35+
endpoint="https://api.hcaptcha.com"
36+
reportapi="https://accounts.hcaptcha.com"
37+
assethost="https://newassets.hcaptcha.com"
38+
imghost="https://imgs.hcaptcha.com"
39+
host="test-host"
40+
hasBackdrop={true}
41+
useSafeAreaView={true}
42+
debug={{ test: true }}
43+
onMessage={() => {}}
44+
/>
45+
);
46+
});
47+
48+
test('ConfirmHcaptcha modal show/hide performance', async () => {
49+
const TestComponent = () => {
50+
const [show, setShow] = React.useState(false);
51+
52+
return (
53+
<>
54+
<ConfirmHcaptcha
55+
siteKey="00000000-0000-0000-0000-000000000000"
56+
baseUrl="https://hcaptcha.com"
57+
languageCode="en"
58+
onMessage={() => {}}
59+
/>
60+
<button onPress={() => setShow(!show)}>
61+
Toggle Modal
62+
</button>
63+
</>
64+
);
65+
};
66+
67+
await measureRenders(<TestComponent />, {
68+
scenario: async () => {
69+
// Simulate showing and hiding the modal
70+
await waitFor(() => {}, { timeout: 100 });
71+
},
72+
});
73+
});
74+
75+
test('ConfirmHcaptcha render count stability - multiple renders', async () => {
76+
// This test ensures render count doesn't increase with multiple renders
77+
const Component = () => (
78+
<ConfirmHcaptcha
79+
siteKey="00000000-0000-0000-0000-000000000000"
80+
baseUrl="https://hcaptcha.com"
81+
languageCode="en"
82+
onMessage={() => {}}
83+
/>
84+
);
85+
86+
await measureRenders(<Component />, {
87+
runs: 20, // More runs to detect render count issues
88+
warmupRuns: 3,
89+
});
90+
});
91+
92+
test('ConfirmHcaptcha minimal configuration', async () => {
93+
await measureRenders(
94+
<ConfirmHcaptcha
95+
siteKey="00000000-0000-0000-0000-000000000000"
96+
baseUrl="https://hcaptcha.com"
97+
languageCode="en"
98+
onMessage={() => {}}
99+
/>,
100+
{
101+
scenario: async () => {
102+
await waitFor(() => {}, { timeout: 100 });
103+
},
104+
}
105+
);
106+
});
107+
108+
test('ConfirmHcaptcha with safe area view', async () => {
109+
await measureRenders(
110+
<ConfirmHcaptcha
111+
siteKey="00000000-0000-0000-0000-000000000000"
112+
baseUrl="https://hcaptcha.com"
113+
languageCode="en"
114+
useSafeAreaView={true}
115+
onMessage={() => {}}
116+
/>,
117+
{
118+
scenario: async () => {
119+
await waitFor(() => {}, { timeout: 100 });
120+
},
121+
}
122+
);
123+
});
124+
125+
test('ConfirmHcaptcha without safe area view', async () => {
126+
await measureRenders(
127+
<ConfirmHcaptcha
128+
siteKey="00000000-0000-0000-0000-000000000000"
129+
baseUrl="https://hcaptcha.com"
130+
languageCode="en"
131+
useSafeAreaView={false}
132+
onMessage={() => {}}
133+
/>,
134+
{
135+
scenario: async () => {
136+
await waitFor(() => {}, { timeout: 100 });
137+
},
138+
}
139+
);
140+
});
141+
142+
test('ConfirmHcaptcha passive mode', async () => {
143+
await measureRenders(
144+
<ConfirmHcaptcha
145+
siteKey="00000000-0000-0000-0000-000000000000"
146+
baseUrl="https://hcaptcha.com"
147+
languageCode="en"
148+
passiveSiteKey={true}
149+
onMessage={() => {}}
150+
/>,
151+
{
152+
scenario: async () => {
153+
await waitFor(() => {}, { timeout: 100 });
154+
},
155+
}
156+
);
157+
});
158+
159+
test('ConfirmHcaptcha light theme performance', async () => {
160+
await measureRenders(
161+
<ConfirmHcaptcha
162+
siteKey="00000000-0000-0000-0000-000000000000"
163+
baseUrl="https://hcaptcha.com"
164+
languageCode="en"
165+
theme="light"
166+
onMessage={() => {}}
167+
/>,
168+
{
169+
scenario: async () => {
170+
await waitFor(() => {}, { timeout: 100 });
171+
},
172+
}
173+
);
174+
});
175+
176+
test('ConfirmHcaptcha dark theme performance', async () => {
177+
await measureRenders(
178+
<ConfirmHcaptcha
179+
siteKey="00000000-0000-0000-0000-000000000000"
180+
baseUrl="https://hcaptcha.com"
181+
languageCode="en"
182+
theme="dark"
183+
onMessage={() => {}}
184+
/>,
185+
{
186+
scenario: async () => {
187+
await waitFor(() => {}, { timeout: 100 });
188+
},
189+
}
190+
);
191+
});
192+
193+
test('ConfirmHcaptcha contrast theme performance', async () => {
194+
await measureRenders(
195+
<ConfirmHcaptcha
196+
siteKey="00000000-0000-0000-0000-000000000000"
197+
baseUrl="https://hcaptcha.com"
198+
languageCode="en"
199+
theme="contrast"
200+
onMessage={() => {}}
201+
/>,
202+
{
203+
scenario: async () => {
204+
await waitFor(() => {}, { timeout: 100 });
205+
},
206+
}
207+
);
208+
});
209+
});

__tests__/Hcaptcha.perf-test.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import React from 'react';
2+
import { measureRenders } from 'reassure';
3+
import { waitFor } from '@testing-library/react-native';
4+
import Hcaptcha from '../Hcaptcha';
5+
6+
describe('Hcaptcha Performance Tests', () => {
7+
test('Hcaptcha initial render performance', async () => {
8+
await measureRenders(
9+
<Hcaptcha
10+
siteKey="00000000-0000-0000-0000-000000000000"
11+
url="https://hcaptcha.com"
12+
onMessage={() => {}}
13+
/>
14+
);
15+
});
16+
17+
test('Hcaptcha render with all props', async () => {
18+
await measureRenders(
19+
<Hcaptcha
20+
siteKey="00000000-0000-0000-0000-000000000000"
21+
url="https://hcaptcha.com"
22+
size="normal"
23+
languageCode="en"
24+
showLoading={true}
25+
loadingIndicatorColor="#123456"
26+
backgroundColor="rgba(0.1, 0.1, 0.1, 0.4)"
27+
theme="light"
28+
rqdata="{}"
29+
sentry={false}
30+
jsSrc="https://js.hcaptcha.com/1/api.js"
31+
endpoint="https://api.hcaptcha.com"
32+
reportapi="https://accounts.hcaptcha.com"
33+
assethost="https://newassets.hcaptcha.com"
34+
imghost="https://imgs.hcaptcha.com"
35+
host="test-host"
36+
debug={{ test: true }}
37+
orientation="portrait"
38+
phonePrefix="44"
39+
phoneNumber="+441234567890"
40+
onMessage={() => {}}
41+
/>
42+
);
43+
});
44+
45+
test('Hcaptcha render with theme object', async () => {
46+
const customTheme = {
47+
palette: {
48+
mode: 'dark',
49+
primary: { main: '#26C6DA' },
50+
warn: { main: '#FF8A80' },
51+
text: {
52+
heading: '#FAFAFA',
53+
body: '#E0E0E0',
54+
},
55+
},
56+
};
57+
58+
await measureRenders(
59+
<Hcaptcha
60+
siteKey="00000000-0000-0000-0000-000000000000"
61+
url="https://hcaptcha.com"
62+
theme={customTheme}
63+
onMessage={() => {}}
64+
/>
65+
);
66+
});
67+
68+
test('Hcaptcha render count stability - multiple renders', async () => {
69+
// This test ensures render count doesn't increase with multiple renders
70+
const Component = () => (
71+
<Hcaptcha
72+
siteKey="00000000-0000-0000-0000-000000000000"
73+
url="https://hcaptcha.com"
74+
onMessage={() => {}}
75+
/>
76+
);
77+
78+
await measureRenders(<Component />, {
79+
runs: 20, // More runs to detect render count issues
80+
warmupRuns: 3,
81+
});
82+
});
83+
84+
test('Hcaptcha invisible size performance', async () => {
85+
await measureRenders(
86+
<Hcaptcha
87+
siteKey="00000000-0000-0000-0000-000000000000"
88+
url="https://hcaptcha.com"
89+
size="invisible"
90+
onMessage={() => {}}
91+
/>,
92+
{
93+
scenario: async () => {
94+
await waitFor(() => {}, { timeout: 100 });
95+
},
96+
}
97+
);
98+
});
99+
100+
test('Hcaptcha compact size performance', async () => {
101+
await measureRenders(
102+
<Hcaptcha
103+
siteKey="00000000-0000-0000-0000-000000000000"
104+
url="https://hcaptcha.com"
105+
size="compact"
106+
onMessage={() => {}}
107+
/>,
108+
{
109+
scenario: async () => {
110+
await waitFor(() => {}, { timeout: 100 });
111+
},
112+
}
113+
);
114+
});
115+
116+
test('Hcaptcha normal size performance', async () => {
117+
await measureRenders(
118+
<Hcaptcha
119+
siteKey="00000000-0000-0000-0000-000000000000"
120+
url="https://hcaptcha.com"
121+
size="normal"
122+
onMessage={() => {}}
123+
/>,
124+
{
125+
scenario: async () => {
126+
await waitFor(() => {}, { timeout: 100 });
127+
},
128+
}
129+
);
130+
});
131+
});

0 commit comments

Comments
 (0)