xref: /expo/apps/test-suite/TestModules.js (revision 86fe77d4)
1'use strict';
2
3import Constants from 'expo-constants';
4import { Platform } from 'expo-modules-core';
5
6import ExponentTest from './ExponentTest';
7import { isDeviceFarm } from './utils/Environment';
8
9function browserSupportsWebGL() {
10  try {
11    const canvas = document.createElement('canvas');
12    return (
13      !!window.WebGLRenderingContext &&
14      (canvas.getContext('webgl') || canvas.getContext('experimental-webgl'))
15    );
16  } catch {
17    return false;
18  }
19}
20
21function optionalRequire(requirer) {
22  try {
23    return requirer();
24  } catch {
25    // eslint-disable-next-line
26    return;
27  }
28}
29
30// Both Location and TaskManager test suites define tasks in TaskManager.
31// Since tasks can only be defined during initialization phase (not as a result
32// of calling some function when the application is running, but rather in global scope),
33// we need to trigger code execution of these modules here (not in `getTestModules`
34// which is called in one of the components).
35const LocationTestScreen = optionalRequire(() => require('./tests/Location'));
36const TaskManagerTestScreen = optionalRequire(() => require('./tests/TaskManager'));
37// I have a hunch that optionalRequire doesn't work when *not* in global scope
38// since I had to move Camera screen import here too to get rid of an error
39// caused by missing native module.
40const CameraTestScreen = optionalRequire(() => require('./tests/Camera'));
41
42// List of all modules for tests. Each file path must be statically present for
43// the packager to pick them all up.
44export function getTestModules() {
45  const modules = [
46    // Sanity
47    require('./tests/Basic'),
48  ];
49
50  // Expo core modules should run everywhere
51  modules.push(
52    require('./tests/Asset'),
53    require('./tests/Constants'),
54    require('./tests/FileSystem'),
55    require('./tests/Font'),
56    require('./tests/ImagePicker'),
57    optionalRequire(() => require('./tests/Image'))
58  );
59
60  // Universally tested APIs
61  modules.push(
62    require('./tests/EASClient'),
63    require('./tests/Random'),
64    require('./tests/Crypto'),
65    require('./tests/KeepAwake'),
66    require('./tests/Blur'),
67    require('./tests/LinearGradient'),
68    require('./tests/HTML'),
69    require('./tests/FirebaseJSSDKCompat'),
70    require('./tests/FirebaseJSSDK'),
71    require('./tests/ImageManipulator'),
72    require('./tests/Clipboard'),
73    optionalRequire(() => require('./tests/SQLite'))
74  );
75
76  if (Platform.OS === 'android') {
77    modules.push(require('./tests/JSC'));
78    modules.push(require('./tests/Hermes'));
79  }
80
81  if (global.DETOX) {
82    modules.push(
83      require('./tests/Contacts'),
84      require('./tests/Haptics'),
85      require('./tests/Localization'),
86      require('./tests/SecureStore'),
87      require('./tests/SMS'),
88      require('./tests/StoreReview'),
89      require('./tests/Notifications')
90    );
91    return modules;
92  }
93
94  if (Platform.OS === 'web') {
95    modules.push(
96      require('./tests/Contacts'),
97      // require('./tests/SVG'),
98      require('./tests/Localization'),
99      require('./tests/Recording'),
100      optionalRequire(() => require('./tests/Notifications')),
101      LocationTestScreen
102    );
103
104    if (browserSupportsWebGL()) {
105      modules.push(optionalRequire(() => require('./tests/GLView')));
106    }
107
108    if (ExponentTest && !ExponentTest.isInCI) {
109      // modules.push(optionalRequire(() => require('./tests/Speech')));
110    }
111    return modules.filter(Boolean);
112  }
113
114  modules.push(
115    optionalRequire(() => require('./tests/Application')),
116    optionalRequire(() => require('./tests/AuthSession')),
117    optionalRequire(() => require('./tests/Device')),
118    optionalRequire(() => require('./tests/GLView')),
119    optionalRequire(() => require('./tests/Haptics')),
120    optionalRequire(() => require('./tests/Localization')),
121    optionalRequire(() => require('./tests/Network')),
122    optionalRequire(() => require('./tests/SecureStore')),
123    optionalRequire(() => require('./tests/Speech')),
124    optionalRequire(() => require('./tests/Recording')),
125    optionalRequire(() => require('./tests/ScreenOrientation')),
126    optionalRequire(() => require('./tests/Notifications')),
127    optionalRequire(() => require('./tests/NavigationBar')),
128    optionalRequire(() => require('./tests/SystemUI'))
129  );
130
131  if (!isDeviceFarm()) {
132    // Popup to request device's location which uses Google's location service
133    modules.push(LocationTestScreen);
134    // Fails to redirect because of malformed URL in published version with release channel parameter
135    modules.push(optionalRequire(() => require('./tests/Linking')));
136    // Has uncontrolled view controllers
137    modules.push(require('./tests/SMS'));
138    // Requires permission
139    modules.push(optionalRequire(() => require('./tests/Contacts')));
140    modules.push(optionalRequire(() => require('./tests/Calendar')));
141    modules.push(optionalRequire(() => require('./tests/CalendarReminders')));
142    modules.push(optionalRequire(() => require('./tests/MediaLibrary')));
143
144    modules.push(optionalRequire(() => require('./tests/Battery')));
145    if (Constants.isDevice) {
146      modules.push(optionalRequire(() => require('./tests/Brightness')));
147    }
148    // Crashes app when mounting component
149    modules.push(optionalRequire(() => require('./tests/Video')));
150    // "sdkUnversionedTestSuite failed: java.lang.NullPointerException: Attempt to invoke interface method
151    // 'java.util.Map expo.modules.interfaces.taskManager.TaskInterface.getOptions()' on a null object reference"
152    modules.push(TaskManagerTestScreen);
153    // Audio tests are flaky in CI due to asynchronous fetching of resources
154    modules.push(optionalRequire(() => require('./tests/Audio')));
155
156    // The Camera tests are flaky on iOS, i.e. they fail randomly
157    if (Constants.isDevice) {
158      modules.push(CameraTestScreen);
159    }
160  }
161  if (Constants.isDevice) {
162    modules.push(optionalRequire(() => require('./tests/Cellular')));
163    modules.push(optionalRequire(() => require('./tests/BarCodeScanner')));
164  }
165  return modules
166    .filter(Boolean)
167    .sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1));
168}
169