@@ -24,12 +24,10 @@ const REACT_NATIVE_MOCK = {
2424 module.exports = {
2525 platforms: {
2626 ios: {
27- linkConfig: ios.linkConfig,
2827 projectConfig: ios.projectConfig,
2928 dependencyConfig: ios.dependencyConfig,
3029 },
3130 android: {
32- linkConfig: android.linkConfig,
3331 projectConfig: android.projectConfig,
3432 dependencyConfig: android.dependencyConfig,
3533 },
@@ -38,6 +36,21 @@ const REACT_NATIVE_MOCK = {
3836 ` ,
3937} ;
4038
39+ const PLATFORM_MOCK = {
40+ 'node_modules/react-native-os/package.json' : '{}' ,
41+ 'node_modules/react-native-os/react-native.config.js' : `
42+ const os = require("${ iosPath } ");
43+ module.exports = {
44+ platforms: {
45+ os: {
46+ projectConfig: os.projectConfig,
47+ dependencyConfig: os.dependencyConfig,
48+ },
49+ },
50+ };
51+ ` ,
52+ } ;
53+
4154// Removes string from all key/values within an object
4255const removeString = ( config , str ) =>
4356 JSON . parse (
@@ -373,6 +386,70 @@ test('should apply build types from dependency config', async () => {
373386 ) . toMatchSnapshot ( ) ;
374387} ) ;
375388
389+ test ( 'should be able to read multiple platforms from many packages' , async ( ) => {
390+ DIR = getTempDirectory ( 'config_test_apply_dependency_config' ) ;
391+ writeFiles ( DIR , {
392+ ...REACT_NATIVE_MOCK ,
393+ ...PLATFORM_MOCK ,
394+ 'package.json' : `{
395+ "dependencies": {
396+ "react-native": "0.0.1",
397+ "react-native-os": "0.0.1"
398+ }
399+ }` ,
400+ } ) ;
401+ const { platforms} = await loadConfigAsync ( { projectRoot : DIR } ) ;
402+ expect ( removeString ( platforms , DIR ) ) . toMatchInlineSnapshot ( `
403+ Object {
404+ "android": Object {},
405+ "ios": Object {},
406+ "os": Object {},
407+ }
408+ ` ) ;
409+ } ) ;
410+
411+ test ( 'should be able to read only selected platform' , async ( ) => {
412+ DIR = getTempDirectory ( 'config_test_apply_dependency_config' ) ;
413+ writeFiles ( DIR , {
414+ ...REACT_NATIVE_MOCK ,
415+ ...PLATFORM_MOCK ,
416+ 'package.json' : `{
417+ "dependencies": {
418+ "react-native": "0.0.1",
419+ "react-native-os": "0.0.1"
420+ }
421+ }` ,
422+ } ) ;
423+ const { platforms} = await loadConfigAsync ( {
424+ projectRoot : DIR ,
425+ selectedPlatform : 'os' ,
426+ } ) ;
427+ expect ( removeString ( platforms , DIR ) ) . toMatchInlineSnapshot ( `
428+ Object {
429+ "os": Object {},
430+ }
431+ ` ) ;
432+ } ) ;
433+
434+ test ( 'should be able to read no platforms when non-existent selected' , async ( ) => {
435+ DIR = getTempDirectory ( 'config_test_apply_dependency_config' ) ;
436+ writeFiles ( DIR , {
437+ ...REACT_NATIVE_MOCK ,
438+ ...PLATFORM_MOCK ,
439+ 'package.json' : `{
440+ "dependencies": {
441+ "react-native": "0.0.1",
442+ "react-native-os": "0.0.1"
443+ }
444+ }` ,
445+ } ) ;
446+ const { platforms} = await loadConfigAsync ( {
447+ projectRoot : DIR ,
448+ selectedPlatform : 'macos' ,
449+ } ) ;
450+ expect ( removeString ( platforms , DIR ) ) . toMatchInlineSnapshot ( `Object {}` ) ;
451+ } ) ;
452+
376453test ( 'supports dependencies from user configuration with custom build type' , async ( ) => {
377454 DIR = getTempDirectory ( 'config_test_apply_custom_build_config' ) ;
378455 writeFiles ( DIR , {
0 commit comments