1'use strict'; 2 3import { Platform, NativeModules } from 'react-native'; 4import Constants from 'expo-constants'; 5 6const { ExponentTest } = NativeModules; 7 8function browserSupportsWebGL() { 9 try { 10 const canvas = document.createElement('canvas'); 11 return ( 12 !!window.WebGLRenderingContext && 13 (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')) 14 ); 15 } catch (e) { 16 return false; 17 } 18} 19 20// List of all modules for tests. Each file path must be statically present for 21// the packager to pick them all up. 22export function getTestModules() { 23 if (Platform.OS === 'web') { 24 const modules = [ 25 require('./tests/Import1'), 26 require('./tests/Crypto'), 27 require('./tests/Random'), 28 ]; 29 30 if (browserSupportsWebGL()) { 31 modules.push(require('./tests/GLView')); 32 } 33 return modules; 34 } 35 36 const modules = [ 37 require('./tests/Basic'), 38 require('./tests/Import1'), 39 require('./tests/Import2'), 40 require('./tests/Import3'), 41 require('./tests/Asset'), 42 require('./tests/Constants'), 43 require('./tests/Crypto'), 44 require('./tests/FileSystem'), 45 require('./tests/GLView'), 46 require('./tests/Haptics'), 47 require('./tests/Localization'), 48 require('./tests/Recording'), 49 require('./tests/ScreenOrientation'), 50 require('./tests/SecureStore'), 51 require('./tests/Segment'), 52 require('./tests/Speech'), 53 require('./tests/SQLite'), 54 require('./tests/Random'), 55 require('./tests/Payments'), 56 require('./tests/AdMobInterstitial'), 57 require('./tests/AdMobBanner'), 58 require('./tests/AdMobPublisherBanner'), 59 require('./tests/AdMobRewarded'), 60 require('./tests/FBBannerAd'), 61 ]; 62 if (ExponentTest && !ExponentTest.isInCI) { 63 // Invalid placementId in CI (all tests fail) 64 modules.push(require('./tests/FBNativeAd')); 65 // Requires interaction (sign in popup) 66 modules.push(require('./tests/GoogleSignIn')); 67 // Popup to request device's location which uses Google's location service 68 modules.push(require('./tests/Location')); 69 // Fails to redirect because of malformed URL in published version with release channel parameter 70 modules.push(require('./tests/Linking')); 71 // Requires permission 72 modules.push(require('./tests/Calendar')); 73 modules.push(require('./tests/Contacts')); 74 modules.push(require('./tests/Permissions')); 75 modules.push(require('./tests/MediaLibrary')); 76 modules.push(require('./tests/Notifications')); 77 if (Constants.isDevice) modules.push(require('./tests/Brightness')); 78 // Crashes app when mounting component 79 modules.push(require('./tests/Video')); 80 // "sdkUnversionedTestSuite failed: java.lang.NullPointerException: Attempt to invoke interface method 81 // 'java.util.Map org.unimodules.interfaces.taskManager.TaskInterface.getOptions()' on a null object reference" 82 modules.push(require('./tests/TaskManager')); 83 // Audio tests are flaky in CI due to asynchronous fetching of resources 84 modules.push(require('./tests/Audio')); 85 // The Camera tests are flaky on iOS, i.e. they fail randomly 86 if (Constants.isDevice && Platform.OS === 'android') modules.push(require('./tests/Camera')); 87 } 88 if (Platform.OS === 'android') modules.push(require('./tests/JSC')); 89 if (Constants.isDevice) { 90 modules.push(require('./tests/BarCodeScanner')); 91 } 92 return modules; 93} 94 95export async function acceptPermissionsAndRunCommandAsync(fn) { 96 if (!ExponentTest) { 97 return await fn(); 98 } 99 100 const results = await Promise.all([ 101 ExponentTest.action({ 102 selectorType: 'text', 103 selectorValue: 'Allow', 104 actionType: 'click', 105 delay: 1000, 106 timeout: 100, 107 }), 108 fn(), 109 ]); 110 111 return results[1]; 112} 113 114export async function shouldSkipTestsRequiringPermissionsAsync() { 115 if (!ExponentTest || !ExponentTest.shouldSkipTestsRequiringPermissionsAsync) { 116 return false; 117 } 118 return ExponentTest.shouldSkipTestsRequiringPermissionsAsync(); 119} 120