Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 27ed333

Browse files
authored
Merge pull request #8 from horacioh/feature/typescript
Fix test --coverage errors related to TS
2 parents a4da6ff + f67807b commit 27ed333

15 files changed

Lines changed: 330 additions & 1288 deletions

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/
33
jest-setup.js
4+
coverage/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# VSCode
99
.vscode/
10-
tsconfig.json
1110
jsconfig.json
1211

1312
# Xcode
@@ -51,3 +50,6 @@ android/keystores/debug.keystore
5150

5251
# Build
5352
dist/
53+
54+
# Code coverage files
55+
coverage/

package.json

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
],
1212
"react-native": "src/index.js",
1313
"scripts": {
14+
"pretest": "yarn lint && yarn build",
1415
"test": "jest",
1516
"lint": "eslint .",
1617
"format": "eslint . --fix",
17-
"build": "babel --no-babelrc --plugins=transform-es2015-block-scoping,transform-es2015-modules-commonjs,transform-react-jsx,transform-class-properties,transform-object-rest-spread,transform-flow-strip-types src --copy-files --out-dir dist --ignore '**/__tests__/**'",
18+
"babel": "babel --no-babelrc --plugins=transform-es2015-block-scoping,transform-es2015-modules-commonjs,transform-react-jsx,transform-class-properties,transform-object-rest-spread,transform-flow-strip-types src --copy-files --out-dir dist --ignore '**/__tests__/**'",
19+
"tsc": "tsc",
20+
"build": "yarn babel && yarn tsc",
1821
"prepare": "yarn build",
1922
"release": "release-it"
2023
},
@@ -59,34 +62,49 @@
5962
"eslint": "^4.12.1",
6063
"eslint-config-satya164": "^1.0.1",
6164
"eslint-plugin-react-native-globals": "^0.1.0",
62-
"husky": "^0.14.3",
65+
"husky": "^1.1.2",
6366
"jest": "^22.1.3",
6467
"jest-expo": "^30.0.0",
6568
"prettier": "^1.8.2",
6669
"react": "16.3.1",
6770
"react-dom": "16.3.1",
6871
"react-native": "^0.55.4",
6972
"react-test-renderer": "16.3.1",
70-
"release-it": "^7.6.1"
73+
"release-it": "^7.6.1",
74+
"ts-jest": "^23.10.4",
75+
"typescript": "^3.1.3"
7176
},
7277
"peerDependencies": {
7378
"react": "*"
7479
},
7580
"jest": {
7681
"preset": "react-native",
77-
"testRegex": "/__tests__/[^/]+-test\\.js$",
82+
"testRegex": "/__tests__/[^/]+-test\\.(js|tsx)?$",
7883
"setupFiles": [
7984
"<rootDir>/jest-setup.js"
8085
],
8186
"coveragePathIgnorePatterns": [
8287
"jest-setup.js"
8388
],
89+
"transformIgnorePatterns": [
90+
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
91+
],
92+
"transform": {
93+
"^.+\\.tsx?$": "ts-jest"
94+
},
8495
"modulePathIgnorePatterns": [
8596
"<rootDir>/example/"
8697
],
87-
"transformIgnorePatterns": [
88-
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
89-
]
98+
"globals": {
99+
"ts-jest": {
100+
"tsConfig": "./tsconfig.test.json",
101+
"diagnostics": {
102+
"ignoreCodes": [
103+
151001
104+
]
105+
}
106+
}
107+
}
90108
},
91109
"prettier": {
92110
"trailingComma": "es5",

src/getChildNavigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import getChildEventSubscriber from './getChildEventSubscriber';
2-
import getChildRouter from './getChildRouter';
2+
import getChildRouter from './getChildRouter.ts';
33
import getNavigationActionCreators from './routers/getNavigationActionCreators';
44
import getChildrenNavigationCache from './getChildrenNavigationCache';
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function getChildRouter(router, routeName) {
1+
export default function getChildRouter(router: any, routeName: string) {
22
if (router.childRouters && router.childRouters[routeName]) {
33
return router.childRouters[routeName];
44
}

src/routers/KeyGenerator.js

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

src/routers/KeyGenerator.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let uniqueBaseId: string = `id-${Date.now()}`;
2+
let uuidCount: number = 0;
3+
4+
export function _TESTING_ONLY_normalize_keys(): void {
5+
uniqueBaseId = 'id';
6+
uuidCount = 0;
7+
}
8+
9+
export function generateKey(): string {
10+
return `${uniqueBaseId}-${uuidCount++}`;
11+
}

src/routers/StackRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getScreenForRouteName from './getScreenForRouteName';
55
import StateUtils from '../StateUtils';
66
import validateRouteConfigMap from './validateRouteConfigMap';
77
import invariant from '../utils/invariant';
8-
import { generateKey } from './KeyGenerator';
8+
import { generateKey } from './KeyGenerator.ts';
99
import { createPathParser } from './pathUtils';
1010

1111
function behavesLikePushAction(action) {

src/routers/__tests__/PathHandling-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SwitchRouter from '../SwitchRouter';
66
import StackRouter from '../StackRouter';
77
import TabRouter from '../TabRouter';
88
import NavigationActions from '../../NavigationActions';
9-
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';
9+
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator.ts';
1010

1111
beforeEach(() => {
1212
_TESTING_ONLY_normalize_keys();

src/routers/__tests__/Routers-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import TabRouter from '../TabRouter';
77
import SwitchRouter from '../SwitchRouter';
88

99
import NavigationActions from '../../NavigationActions';
10-
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';
10+
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator.ts';
1111

1212
beforeEach(() => {
1313
_TESTING_ONLY_normalize_keys();

0 commit comments

Comments
 (0)