Skip to content

Instantly share code, notes, and snippets.

@lidio601
Last active October 2, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidio601/159585b8540627471784de23a797b1fd to your computer and use it in GitHub Desktop.
Save lidio601/159585b8540627471784de23a797b1fd to your computer and use it in GitHub Desktop.
React Native app starter kit
# ensure right cli is installed
npm uninstall -g react-native-cli
npm i -g @react-native-community/cli
# create app from template
APPNAME=myapp
npx react-native init ${APPNAME} --template react-native-template-typescript
cd ${APPNAME}
# setup tslint
yarn add -D @types/react tslint tslint-eslint-rules tslint-react tslint-config-prettier
echo -e "{\n\
\"extends\": [\n\
\"tslint:recommended\",\n\
\"tslint-eslint-rules\",\n\
\"tslint-react\",\n\
\"tslint-config-prettier\"\n\
],\n\
\"jsRules\": {},\n\
\"rules\": {\n\
\"interface-name\": false,\n\
\"jsx-no-lambda\": false,\n\
\"object-literal-sort-keys\": false,\n\
\"quotemark\": [true, \"single\", \"jsx-double\"]\n\
}\n\
}" > tslint.json
echo -e "--- package.json 2019-10-02 23:03:28.000000000 +1300\n\
+++ package.json 2019-10-02 23:05:17.000000000 +1300\n\
@@ -6,7 +6,8 @@\n\
\"android\": \"react-native run-android\",\n\
\"ios\": \"react-native run-ios\",\n\
\"start\": \"react-native start\",\n\
- \"test\": \"jest\"\n\
+ \"test\": \"jest\",\n\
+ \"lint\": \"tslint --project tsconfig.json\"\n\
},\n\
\"dependencies\": {\n\
\"react\": \"16.9.0\",\n\
" | patch
# setup ts-jest
yarn add -D ts-jest
echo -e "{\n\
\"extends\": \"./tsconfig\",\n\
\"compilerOptions\": {\n\
\"jsx\": \"react\",\n\
\"module\": \"commonjs\"\n\
}\n\
}" > tsconfig.jest.json
echo -e "--- package.json 2019-10-02 23:22:50.000000000 +1300\n\
+++ package.json 2019-10-02 23:23:46.000000000 +1300\n\
@@ -41,6 +41,16 @@\n\
\"jsx\",\n\
\"json\",\n\
\"node\"\n\
- ]\n\
+ ],\n\
+ \"transform\": {\n\
+ \"^.+\\\\.js$\": \"<rootDir>/node_modules/react-native/jest/preprocessor.js\",\n\
+ \"\\\\.(ts|tsx)$\": \"ts-jest\"\n\
+ },\n\
+ \"globals\": {\n\
+ \"ts-jest\": {\n\
+ \"tsConfig\": \"tsconfig.jest.json\"\n\
+ }\n\
+ },\n\
+ \"testRegex\": \"(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx|js)$\"\n\
}\n\
}" | patch
echo -e "// Add 'export' to fake this being a module to silence TSLint.\n\
export const add = (a: number, b: number) => a + b;\n\
describe(\"add\", () => {\n\
it(\"should add two numbers\", () => {\n\
expect(add(1, 1)).toEqual(2);\n\
});\n\
});" > sample.test.ts
# react native UI testing
yarn add -D react-native-testing-library
echo -e "import React from \"react\";\n\
import { render } from \"react-native-testing-library\";\n\
import App from \"./App\";\n\
\n\
const createTestProps = (props?: object) => ({\n\
...props\n\
});\n\
\n\
describe(\"App\", () => {\n\
const props = createTestProps();\n\
const { getByText } = render(<App {...props} />);\n\
\n\
it(\"should render a welcome\", () => {\n\
expect(getByText(/welcome/i)).toBeDefined();\n\
});\n\
});" > App.test.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment