Skip to content

Commit

Permalink
fix: use require.resolve in jest-preset (#22972)
Browse files Browse the repository at this point in the history
Summary:
The current way the Jest preset work requires the different files to be in `<rootDir>/node_modules/react-native`. This is not necessarily true - especially in monorepoes.

If we instead do `require.resolve`, we do not need to do `rootDir` replacement in Jest.

Having a JS file as preset has been supported since Jest 23.0.0: jestjs/jest#6185

Changelog:
----------

[General] [Fixed] - use `require.resolve` in `jest-preset`
Pull Request resolved: #22972

Differential Revision: D13662758

Pulled By: hramos

fbshipit-source-id: ca79b5b89d9d05c6fe639b0d88619858e8d05da7
  • Loading branch information
SimenB authored and facebook-github-bot committed Jan 15, 2019
1 parent 1bdb250 commit 991e83f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
41 changes: 41 additions & 0 deletions jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const dir = __dirname;

module.exports = {
haste: {
defaultPlatform: 'ios',
platforms: ['android', 'ios', 'native'],
hasteImplModulePath: require.resolve('./jest/hasteImpl.js'),
providesModuleNodeModules: ['react-native'],
},
moduleFileExtensions: ['js', 'json', 'jsx', 'node', 'ts', 'tsx'],
moduleNameMapper: {
'^React$': require.resolve('react'),
},
modulePathIgnorePatterns: [`${dir}/Libraries/react-native/`],
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
'./jest/assetFileTransformer.js',
),
},
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element)',
],
testMatch: [
'**/__tests__/**/*.(js|ts|tsx)',
'**/?(*.)+(spec|test).(js|ts|tsx)',
],
setupFiles: [require.resolve('./jest/setup.js')],
testEnvironment: 'node',
};
39 changes: 0 additions & 39 deletions jest-preset.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"scripts/launchPackager.command",
"scripts/packager.sh",
"scripts/react-native-xcode.sh",
"jest-preset.json",
"jest-preset.js",
"jest",
"lib",
"rn-get-polyfills.js",
Expand Down

0 comments on commit 991e83f

Please sign in to comment.