Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit e276226

Browse files
SimenBaleclarson
authored andcommitted
fix: use require.resolve in jest-preset (#22972)
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
1 parent c85ad37 commit e276226

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

jest-preset.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const dir = __dirname;
13+
14+
module.exports = {
15+
haste: {
16+
defaultPlatform: 'ios',
17+
platforms: ['android', 'ios', 'native'],
18+
hasteImplModulePath: require.resolve('./jest/hasteImpl.js'),
19+
providesModuleNodeModules: ['react-native'],
20+
},
21+
moduleFileExtensions: ['js', 'json', 'jsx', 'node', 'ts', 'tsx'],
22+
moduleNameMapper: {
23+
'^React$': require.resolve('react'),
24+
},
25+
modulePathIgnorePatterns: [`${dir}/Libraries/react-native/`],
26+
transform: {
27+
'^.+\\.(js|ts|tsx)$': 'babel-jest',
28+
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
29+
'./jest/assetFileTransformer.js',
30+
),
31+
},
32+
transformIgnorePatterns: [
33+
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element)',
34+
],
35+
testMatch: [
36+
'**/__tests__/**/*.(js|ts|tsx)',
37+
'**/?(*.)+(spec|test).(js|ts|tsx)',
38+
],
39+
setupFiles: [require.resolve('./jest/setup.js')],
40+
testEnvironment: 'node',
41+
};

jest-preset.json

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

0 commit comments

Comments
 (0)