Skip to content

Commit 7823d77

Browse files
chore: cleanup examples (#79)
1 parent 042082c commit 7823d77

28 files changed

+213
-211
lines changed

examples/native-cli/src/AsyncComponent.perf-test.tsx renamed to examples/native-cli/src/AsyncComponent.perf.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AsyncComponent } from './AsyncComponent';
66

77
jest.setTimeout(600_000);
88

9-
test('RN CLI - AsyncComponent 10 runs', async () => {
9+
test('RN CLI - AsyncComponent (10 runs)', async () => {
1010
const scenario = async () => {
1111
const button = screen.getByText('Action');
1212

@@ -18,7 +18,7 @@ test('RN CLI - AsyncComponent 10 runs', async () => {
1818
await measureRenders(<AsyncComponent />, { scenario, runs: 10 });
1919
});
2020

21-
test('RN CLI - AsyncComponent 50 runs', async () => {
21+
test('RN CLI - AsyncComponent (50 runs)', async () => {
2222
const scenario = async () => {
2323
const button = screen.getByText('Action');
2424

examples/native-cli/src/AsyncComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { View, Text, Pressable } from 'react-native';
3-
import { SlowList } from './SlowList';
3+
import { TestList } from './TestList';
44

55
export function AsyncComponent() {
66
const [count, setCount] = React.useState(0);
@@ -17,7 +17,7 @@ export function AsyncComponent() {
1717

1818
<Text>Count: {count}</Text>
1919

20-
<SlowList count={200} />
20+
<TestList count={200} />
2121
</View>
2222
);
2323
}

examples/native-cli/src/SlowList.perf-test.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/native-cli/src/SlowList.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import { jest, test } from '@jest/globals';
3+
import { measureRenders } from 'reassure';
4+
import { TestList } from './TestList';
5+
6+
jest.setTimeout(60_000);
7+
8+
test('RN CLI - TestList (100 items)', async () => {
9+
await measureRenders(<TestList count={100} />);
10+
});

examples/native-cli/src/SlowList.test.tsx renamed to examples/native-cli/src/TestList.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import * as React from 'react';
12
import { render, screen } from '@testing-library/react-native';
23
import { expect, test } from '@jest/globals';
3-
import { SlowList } from './SlowList';
4+
import { TestList } from './TestList';
45

5-
test('SlowList', () => {
6-
render(<SlowList count={10} />);
6+
test('TestList', () => {
7+
render(<TestList count={10} />);
78

89
const items = screen.getAllByText(/Item/i);
910
expect(items).toHaveLength(10);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react';
2+
import { View, Text } from 'react-native';
3+
4+
interface TestListProps {
5+
count: number;
6+
}
7+
8+
export const TestList = ({ count }: TestListProps) => {
9+
const data = Array.from({ length: count }, (_, index) => index);
10+
11+
return (
12+
<View>
13+
{data.map(item => (
14+
<ListItem key={item} title={`Item ${item}`} />
15+
))}
16+
</View>
17+
);
18+
};
19+
20+
interface ListItemProps {
21+
title: string;
22+
}
23+
24+
const ListItem = ({ title }: ListItemProps) => {
25+
// Uncomment to introduce a performance issue
26+
// const [, forceRender] = React.useState<{}>();
27+
// React.useEffect(() => {
28+
// forceRender({});
29+
// }, [title]);
30+
31+
return (
32+
<View>
33+
<Text>{title}</Text>
34+
</View>
35+
);
36+
};

examples/native-expo/src/AsyncComponent.perf-test.tsx renamed to examples/native-expo/src/AsyncComponent.perf.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AsyncComponent } from './AsyncComponent';
66

77
jest.setTimeout(600_000);
88

9-
test('RN Expo - AsyncComponent 10 runs', async () => {
9+
test('React Native - Expo - AsyncComponent (10 runs)', async () => {
1010
const scenario = async () => {
1111
const button = screen.getByText('Action');
1212

@@ -18,7 +18,7 @@ test('RN Expo - AsyncComponent 10 runs', async () => {
1818
await measureRenders(<AsyncComponent />, { scenario, runs: 10 });
1919
});
2020

21-
test('RN Expo - AsyncComponent 50 runs', async () => {
21+
test('React Native - Expo - AsyncComponent (50 runs)', async () => {
2222
const scenario = async () => {
2323
const button = screen.getByText('Action');
2424

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as React from 'react';
22
import { View, Text, Pressable } from 'react-native';
3-
import { SlowList } from './SlowList';
3+
import { TestList } from './TestList';
44

55
export function AsyncComponent() {
66
const [count, setCount] = React.useState(0);
77

88
const handlePress = () => {
9-
setTimeout(() => setCount(c => c + 1), 10);
9+
setTimeout(() => setCount((c) => c + 1), 10);
1010
};
1111

1212
return (
@@ -17,7 +17,7 @@ export function AsyncComponent() {
1717

1818
<Text>Count: {count}</Text>
1919

20-
<SlowList count={200} />
20+
<TestList count={200} />
2121
</View>
2222
);
2323
}

examples/native-expo/src/SlowList.perf-test.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)