From 921ee09587cdc33c48d6b018939efac18bddd3e6 Mon Sep 17 00:00:00 2001 From: Jed Mao Date: Fri, 27 Apr 2018 10:57:07 -0500 Subject: [PATCH] Fix "npm test" on Windows 10 (#4066) * Fix Windows * update prettier * Explain need for assetsTransformer in comment --- .eslintrc | 4 +--- assetsTransformer.js | 12 ++++++++++++ flow/react-navigation.js | 15 ++++++++------- package.json | 15 +++++++++------ src/__tests__/NavigationContainer-test.js | 1 - src/views/Header/Header.js | 4 +++- 6 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 assetsTransformer.js diff --git a/.eslintrc b/.eslintrc index 68700da1..05229531 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,9 +42,7 @@ "react/forbid-prop-types": "warn", "react/prop-types": "off", "react/require-default-props": "off", - "react/no-unused-prop-types": "off", - }, - "settings": { + "react/no-unused-prop-types": "off" }, "parserOptions": { "ecmaVersion": 6, diff --git a/assetsTransformer.js b/assetsTransformer.js new file mode 100644 index 00000000..4af49e37 --- /dev/null +++ b/assetsTransformer.js @@ -0,0 +1,12 @@ +/** + * This file is needed to hijack asset imports so that test files don't attempt + * to import them as JavaScript modules. + * See https://github.com/facebook/jest/issues/2663#issuecomment-317109798 + */ +const path = require('path'); + +module.exports = { + process(src, filename, config, options) { + return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; + }, +}; diff --git a/flow/react-navigation.js b/flow/react-navigation.js index c63994ef..73a038d2 100644 --- a/flow/react-navigation.js +++ b/flow/react-navigation.js @@ -488,13 +488,14 @@ declare module 'react-navigation' { goBack: (routeKey?: ?string) => boolean, dismiss: () => boolean, navigate: ( - routeName: | string - | { - routeName: string, - params?: NavigationParams, - action?: NavigationNavigateAction, - key?: string, - }, + routeName: + | string + | { + routeName: string, + params?: NavigationParams, + action?: NavigationNavigateAction, + key?: string, + }, params?: NavigationParams, action?: NavigationNavigateAction ) => boolean, diff --git a/package.json b/package.json index de04207f..31da6280 100644 --- a/package.json +++ b/package.json @@ -48,17 +48,17 @@ "babel-preset-react-native": "^2.1.0", "codecov": "^2.2.0", "eslint": "^4.2.0", - "eslint-config-prettier": "^2.3.0", + "eslint-config-prettier": "^2.9.0", "eslint-plugin-import": "^2.7.0", "eslint-plugin-jsx-a11y": "^6.0.2", - "eslint-plugin-prettier": "^2.1.2", + "eslint-plugin-prettier": "^2.6.0", "eslint-plugin-react": "^7.1.0", "husky": "^0.14.3", "jest": "^22.1.3", "jest-expo": "^25.1.0", "lint-staged": "^4.2.1", - "prettier": "^1.5.3", - "prettier-eslint": "^6.4.2", + "prettier": "^1.12.1", + "prettier-eslint": "^8.8.1", "react": "16.2.0", "react-native": "^0.52.0", "react-native-vector-icons": "^4.2.0", @@ -67,7 +67,7 @@ "jest": { "notify": true, "preset": "react-native", - "testRegex": "./src/.*\\-test\\.js$", + "testRegex": "/__tests__/[^/]+-test\\.js$", "setupFiles": [ "/jest-setup.js" ], @@ -82,8 +82,11 @@ "coveragePathIgnorePatterns": [ "jest-setup.js" ], + "moduleNameMapper": { + "\\.png$": "/assetsTransformer.js" + }, "modulePathIgnorePatterns": [ - "examples" + "/examples/" ], "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|react-navigation-deprecated-tab-navigator)" diff --git a/src/__tests__/NavigationContainer-test.js b/src/__tests__/NavigationContainer-test.js index 2aee356d..55d0bedf 100644 --- a/src/__tests__/NavigationContainer-test.js +++ b/src/__tests__/NavigationContainer-test.js @@ -1,5 +1,4 @@ import React from 'react'; -import 'react-native'; import { StyleSheet, View } from 'react-native'; import renderer from 'react-test-renderer'; diff --git a/src/views/Header/Header.js b/src/views/Header/Header.js index b6766ab2..9f31bd4f 100644 --- a/src/views/Header/Header.js +++ b/src/views/Header/Header.js @@ -24,7 +24,9 @@ const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56; const getAppBarHeight = isLandscape => { return Platform.OS === 'ios' - ? isLandscape && !Platform.isPad ? 32 : 44 + ? isLandscape && !Platform.isPad + ? 32 + : 44 : 56; };