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: facebook/react-native#22972

Differential Revision: D13662758

Pulled By: hramos

fbshipit-source-id: ca79b5b89d9d05c6fe639b0d88619858e8d05da7
  • Loading branch information
SimenB authored and aleclarson committed Nov 15, 2019
1 parent c85ad37 commit e276226
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 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',
};
26 changes: 0 additions & 26 deletions jest-preset.json

This file was deleted.

0 comments on commit e276226

Please sign in to comment.