Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions packages/cli/src/tools/config/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ const removeString = (config, str) =>
beforeEach(() => {
cleanup(DIR);
jest.resetModules();
jest.clearAllMocks();
});

afterEach(() => cleanup(DIR));

test('should have a valid structure by default', () => {
writeFiles(DIR, {
'package.json': `{
"react-native": {
"reactNativePath": "."
}
'react-native.config.js': `module.exports = {
reactNativePath: "."
}`,
});
const config = loadConfig(DIR);
Expand All @@ -59,14 +58,13 @@ test('should return dependencies from package.json', () => {
test('should read a config of a dependency and use it to load other settings', () => {
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'node_modules/react-native-test/package.json': `{
"react-native": {
"dependency": {
"platforms": {
"ios": {
"project": "./customLocation/customProject.xcodeproj"
}
'node_modules/react-native-test/react-native.config.js': `module.exports = {
dependency: {
platforms: {
ios: {
project: "./customLocation/customProject.xcodeproj"
}
}
}
Expand All @@ -87,11 +85,10 @@ test('should read a config of a dependency and use it to load other settings', (
test('should merge project configuration with default values', () => {
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
'node_modules/react-native-test/package.json': `{
"react-native": {
"dependency": {
"assets": ["foo", "baz"]
}
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/react-native.config.js': `module.exports = {
dependency: {
assets: ["foo", "baz"]
}
}`,
'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj':
Expand All @@ -100,18 +97,18 @@ test('should merge project configuration with default values', () => {
"dependencies": {
"react-native": "0.0.1",
"react-native-test": "0.0.1"
},
"react-native": {
"reactNativePath": ".",
"dependencies": {
"react-native-test": {
"platforms": {
"ios": {
"sourceDir": "./abc"
}
},
"assets": ["foo"]
}
}
}`,
'react-native.config.js': `module.exports = {
reactNativePath: ".",
dependencies: {
"react-native-test": {
platforms: {
ios: {
sourceDir: "./abc"
}
},
assets: ["foo"]
}
}
}`,
Expand Down Expand Up @@ -266,3 +263,22 @@ test('should skip packages that have invalid configuration', () => {
expect(dependencies).toMatchSnapshot('dependencies config');
expect(spy.mock.calls[0][0]).toMatchSnapshot('logged warning');
});

test('does not use restricted "react-native" key to resolve config from package.json', () => {
jest.resetModules();

writeFiles(DIR, {
'node_modules/react-native-netinfo/package.json': `{
"react-native": "src/index.js"
}`,
'package.json': `{
"dependencies": {
"react-native-netinfo": "0.0.1"
}
}`,
});
const spy = jest.spyOn(logger, 'warn');
const {dependencies} = loadConfig(DIR);
expect(dependencies).toHaveProperty('react-native-netinfo');
expect(spy).not.toHaveBeenCalled();
});
2 changes: 1 addition & 1 deletion packages/cli/src/tools/config/readConfigFromDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {logger} from '@react-native-community/cli-tools';
/**
* Places to look for the new configuration
*/
const searchPlaces = ['react-native.config.js', 'package.json'];
const searchPlaces = ['react-native.config.js'];

/**
* Reads a project configuration as defined by the user in the current
Expand Down