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

Fix test --coverage errors related to TS #8

Merged
merged 16 commits into from
Oct 25, 2018
Merged
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
jest-setup.js
coverage/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# VSCode
.vscode/
tsconfig.json
jsconfig.json

# Xcode
Expand Down Expand Up @@ -51,3 +50,6 @@ android/keystores/debug.keystore

# Build
dist/

# Code coverage files
coverage/
32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
],
"react-native": "src/index.js",
"scripts": {
"pretest": "yarn lint && yarn build",
"test": "jest",
"lint": "eslint .",
"format": "eslint . --fix",
"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__/**'",
"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__/**'",
"tsc": "tsc",
"build": "yarn babel && yarn tsc",
"prepare": "yarn build",
"release": "release-it"
},
Expand Down Expand Up @@ -59,34 +62,49 @@
"eslint": "^4.12.1",
"eslint-config-satya164": "^1.0.1",
"eslint-plugin-react-native-globals": "^0.1.0",
"husky": "^0.14.3",
"husky": "^1.1.2",
"jest": "^22.1.3",
"jest-expo": "^30.0.0",
"prettier": "^1.8.2",
"react": "16.3.1",
"react-dom": "16.3.1",
"react-native": "^0.55.4",
"react-test-renderer": "16.3.1",
"release-it": "^7.6.1"
"release-it": "^7.6.1",
"ts-jest": "^23.10.4",
"typescript": "^3.1.3"
},
"peerDependencies": {
"react": "*"
},
"jest": {
"preset": "react-native",
"testRegex": "/__tests__/[^/]+-test\\.js$",
"testRegex": "/__tests__/[^/]+-test\\.(js|tsx)?$",
satya164 marked this conversation as resolved.
Show resolved Hide resolved
"setupFiles": [
"<rootDir>/jest-setup.js"
],
"coveragePathIgnorePatterns": [
"jest-setup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"modulePathIgnorePatterns": [
"<rootDir>/example/"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
]
"globals": {
"ts-jest": {
"tsConfig": "./tsconfig.test.json",
"diagnostics": {
"ignoreCodes": [
151001

This comment was marked as abuse.

This comment was marked as abuse.

]
}
}
}
},
"prettier": {
"trailingComma": "es5",
Expand Down
2 changes: 1 addition & 1 deletion src/getChildNavigation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getChildEventSubscriber from './getChildEventSubscriber';
import getChildRouter from './getChildRouter';
import getChildRouter from './getChildRouter.ts';
import getNavigationActionCreators from './routers/getNavigationActionCreators';
import getChildrenNavigationCache from './getChildrenNavigationCache';

Expand Down
2 changes: 1 addition & 1 deletion src/getChildRouter.js → src/getChildRouter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function getChildRouter(router, routeName) {
export default function getChildRouter(router: any, routeName: string) {
if (router.childRouters && router.childRouters[routeName]) {
return router.childRouters[routeName];
}
Expand Down
11 changes: 0 additions & 11 deletions src/routers/KeyGenerator.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/routers/KeyGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let uniqueBaseId: string = `id-${Date.now()}`;
let uuidCount: number = 0;

export function _TESTING_ONLY_normalize_keys(): void {
uniqueBaseId = 'id';
uuidCount = 0;
}

export function generateKey(): string {
return `${uniqueBaseId}-${uuidCount++}`;
}
2 changes: 1 addition & 1 deletion src/routers/StackRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import getScreenForRouteName from './getScreenForRouteName';
import StateUtils from '../StateUtils';
import validateRouteConfigMap from './validateRouteConfigMap';
import invariant from '../utils/invariant';
import { generateKey } from './KeyGenerator';
import { generateKey } from './KeyGenerator.ts';
import { createPathParser } from './pathUtils';

function behavesLikePushAction(action) {
Expand Down
2 changes: 1 addition & 1 deletion src/routers/__tests__/PathHandling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SwitchRouter from '../SwitchRouter';
import StackRouter from '../StackRouter';
import TabRouter from '../TabRouter';
import NavigationActions from '../../NavigationActions';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator.ts';

beforeEach(() => {
_TESTING_ONLY_normalize_keys();
Expand Down
2 changes: 1 addition & 1 deletion src/routers/__tests__/Routers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TabRouter from '../TabRouter';
import SwitchRouter from '../SwitchRouter';

import NavigationActions from '../../NavigationActions';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator.ts';

beforeEach(() => {
_TESTING_ONLY_normalize_keys();
Expand Down
2 changes: 1 addition & 1 deletion src/routers/__tests__/StackRouter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import StackRouter from '../StackRouter';
import StackActions from '../StackActions';
import NavigationActions from '../../NavigationActions';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator';
import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator.ts';

beforeEach(() => {
_TESTING_ONLY_normalize_keys();
Expand Down
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "es2015",
"target": "esnext",
"lib": ["dom", "es2015", "es2016"],
"sourceMap": false,
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"declaration": true,
"pretty": true,
"jsx": "react-native",
"noEmitHelpers": true,
"importHelpers": true,
"strict": true,
"outDir": "dist",
"declarationDir": "./types",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"typeAcquisition": {
"enable": true,
"include": ["prop-types", "react", "react-native"]
}
}
7 changes: 7 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"sourceMap": true
}
}
15 changes: 15 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "tslint:recommended",
"rules": {
"arrow-parens": [true, "ban-single-arg-parens"],
"arrow-return-shorthand": [true, "multiline"],
"trailing-comma": false,
"quotemark": {
"options": [
"single",
"avoid-escape"
]
},
"object-literal-sort-keys": false
}
}
Loading