Skip to content

Commit 333008f

Browse files
committed
chore: setup test env
1 parent f10a6e0 commit 333008f

File tree

7 files changed

+379
-1767
lines changed

7 files changed

+379
-1767
lines changed

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = {
22
presets: ["module:metro-react-native-babel-preset"],
33
plugins: [
4+
"@babel/plugin-proposal-class-properties",
5+
"@babel/plugin-proposal-private-methods",
46
"react-native-reanimated/plugin",
5-
"inline-dotenv",
67
"@babel/plugin-syntax-dynamic-import",
78
],
89
};

example/expo/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@types/react": "~18.2.14",
5353
"@types/react-native-snap-carousel": "^3.8.5",
5454
"babel-plugin-import-glob": "^2.0.0",
55-
"babel-plugin-inline-dotenv": "^1.6.0",
5655
"babel-plugin-module-resolver": "^4.1.0",
5756
"gh-pages": "^3.2.3",
5857
"react-error-overlay": "6.0.9",

jest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("react-native-reanimated").setUpTests();

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
preset: "react-native",
3+
modulePathIgnorePatterns: [
4+
"example",
5+
"docs",
6+
"assets",
7+
".yarn",
8+
"lib",
9+
".eslintrc",
10+
],
11+
setupFiles: ["./jest-setup.js"],
12+
setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"],
13+
testEnvironment: "node",
14+
transformIgnorePatterns: [],
15+
};

package.json

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
"scripts": {
1515
"gif": "node scripts/makegif.js ./scripts/gif-works-directory",
1616
"test": "jest run src/**/*",
17-
"test:dev": "jest dev src/**/*",
17+
"test:dev": "jest dev src/**/* --watch",
1818
"typescript": "tsc --noEmit",
1919
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
2020
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
2121
"dev": "watch 'yarn prepare' ./src",
2222
"prepare": "bob build",
23-
"release": "yarn prepare && dotenv release-it --no-git.requireUpstream",
24-
"preRelease": "yarn prepare && dotenv release-it --no-git.requireUpstream --preRelease=beta",
2523
"ios": "yarn --cwd exampleExpo ios",
2624
"ios:pretty": "yarn --cwd exampleExpo ios:pretty",
2725
"web": "yarn --cwd exampleExpo web",
@@ -50,22 +48,25 @@
5048
"registry": "https://registry.npmjs.org/"
5149
},
5250
"devDependencies": {
51+
"@babel/plugin-proposal-class-properties": "^7.18.6",
52+
"@babel/plugin-proposal-private-methods": "^7.18.6",
5353
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
5454
"@changesets/changelog-github": "^0.5.0",
5555
"@changesets/cli": "latest",
5656
"@commitlint/config-conventional": "^11.0.0",
5757
"@dohooo/eslint-config": "^0.0.7",
5858
"@react-native-community/eslint-config": "^2.0.0",
59-
"@release-it/conventional-changelog": "^2.0.0",
59+
"@testing-library/jest-native": "^4.0.4",
60+
"@testing-library/react-hooks": "^8.0.0",
61+
"@testing-library/react-native": "^7.1.0",
6062
"@types/jest": "^29.2.5",
6163
"@types/react": "^18.2.15",
6264
"@types/react-native": "^0.66.16",
6365
"@types/react-native-snap-carousel": "^3.8.5",
64-
"babel-plugin-inline-dotenv": "^1.6.0",
66+
"@types/react-test-renderer": "^18.0.7",
6567
"babel-plugin-module-resolver": "^4.1.0",
6668
"commitlint": "^11.0.0",
6769
"cz-conventional-changelog": "^3.3.0",
68-
"dotenv-cli": "^5.1.0",
6970
"eslint": "^8.26.0",
7071
"eslint-config-prettier": "^7.0.0",
7172
"eslint-plugin-prettier": "^3.1.3",
@@ -80,7 +81,7 @@
8081
"react-native-builder-bob": "^0.18.1",
8182
"react-native-gesture-handler": "~2.12.0",
8283
"react-native-reanimated": "~3.3.0",
83-
"release-it": "^14.2.2",
84+
"react-test-renderer": "^18.2.0",
8485
"sponsorkit": "^0.1.3",
8586
"typescript": "^4.0.8",
8687
"watch": "^1.0.2"
@@ -101,14 +102,6 @@
101102
"optional": true
102103
}
103104
},
104-
"jest": {
105-
"preset": "react-native",
106-
"modulePathIgnorePatterns": [
107-
"<rootDir>/exampleExpo/node_modules",
108-
"<rootDir>/exampleBare/node_modules",
109-
"<rootDir>/lib/"
110-
]
111-
},
112105
"husky": {
113106
"hooks": {
114107
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
@@ -120,37 +113,6 @@
120113
"@commitlint/config-conventional"
121114
]
122115
},
123-
"release-it": {
124-
"git": {
125-
"commitMessage": "chore: release ${version}",
126-
"tagName": "v${version}"
127-
},
128-
"npm": {
129-
"publish": true
130-
},
131-
"github": {
132-
"release": true
133-
},
134-
"plugins": {
135-
"@release-it/conventional-changelog": {
136-
"preset": {
137-
"name": "angular",
138-
"types": [
139-
{
140-
"type": "feat",
141-
"section": "Features"
142-
},
143-
{
144-
"type": "fix",
145-
"section": "Bug Fixes"
146-
},
147-
{}
148-
]
149-
},
150-
"infile": "CHANGELOG.md"
151-
}
152-
}
153-
},
154116
"react-native-builder-bob": {
155117
"source": "src",
156118
"output": "lib",

src/components/rnr-demo.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { FC } from "react";
2+
import React from "react";
3+
import Animated, { useAnimatedStyle, useDerivedValue } from "react-native-reanimated";
4+
import renderer from "react-test-renderer";
5+
6+
describe("useSharedValue", () => {
7+
it("retains value on rerender", () => {
8+
const initialValue = 0;
9+
const updatedValue = 1;
10+
11+
interface Props {
12+
key: string
13+
value: number
14+
}
15+
16+
const TestComponent: FC<Props> = (props) => {
17+
const opacity = useDerivedValue(() => props.value, [props.value]);
18+
const animatedStyle = useAnimatedStyle(() => ({
19+
opacity: opacity.value,
20+
}), [opacity]);
21+
22+
return <Animated.View style={animatedStyle} />;
23+
};
24+
25+
// When rendering with initial value
26+
const wrapper = renderer.create(<TestComponent key="box" value={initialValue} />);
27+
28+
expect(
29+
typeof wrapper.root.children[0] !== "string"
30+
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity
31+
: false,
32+
).toBe(initialValue);
33+
34+
// When rendering with updated value
35+
wrapper.update(<TestComponent key="box" value={updatedValue} />);
36+
37+
expect(
38+
typeof wrapper.root.children[0] !== "string"
39+
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity
40+
: false,
41+
).toBe(initialValue);
42+
});
43+
});

0 commit comments

Comments
 (0)