xref: /expo/apps/test-suite/TestModules.js (revision dfd15ebd)
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/Permissions'),
57    require('./tests/ImagePicker'),
58    optionalRequire(() => require('./tests/Image'))
59  );
60
61  // Universally tested APIs
62  modules.push(
63    require('./tests/EASClient'),
64    require('./tests/Random'),
65    require('./tests/Crypto'),
66    require('./tests/KeepAwake'),
67    require('./tests/Blur'),
68    require('./tests/LinearGradient'),
69    require('./tests/HTML'),
70    require('./tests/FirebaseJSSDKCompat'),
71    require('./tests/FirebaseJSSDK'),
72    require('./tests/ImageManipulator'),
73    require('./tests/Clipboard'),
74    optionalRequire(() => require('./tests/SQLite'))
75  );
76
77  if (Platform.OS === 'android') {
78    modules.push(require('./tests/JSC'));
79    modules.push(require('./tests/Hermes'));
80  }
81
82  if (global.DETOX) {
83    modules.push(
84      require('./tests/Contacts'),
85      require('./tests/Haptics'),
86      require('./tests/Localization'),
87      require('./tests/SecureStore'),
88      require('./tests/SMS'),
89      require('./tests/StoreReview'),
90      require('./tests/Notifications')
91    );
92    return modules;
93  }
94
95  if (Platform.OS === 'web') {
96    modules.push(
97      require('./tests/Contacts'),
98      // require('./tests/SVG'),
99      require('./tests/Localization'),
100      require('./tests/Recording'),
101      optionalRequire(() => require('./tests/Notifications')),
102      LocationTestScreen
103    );
104
105    if (browserSupportsWebGL()) {
106      modules.push(optionalRequire(() => require('./tests/GLView')));
107    }
108
109    if (ExponentTest && !ExponentTest.isInCI) {
110      // modules.push(optionalRequire(() => require('./tests/Speech')));
111    }
112    return modules.filter(Boolean);
113  }
114
115  modules.push(
116    optionalRequire(() => require('./tests/Application')),
117    optionalRequire(() => require('./tests/AuthSession')),
118    optionalRequire(() => require('./tests/Device')),
119    optionalRequire(() => require('./tests/GLView')),
120    optionalRequire(() => require('./tests/Haptics')),
121    optionalRequire(() => require('./tests/Localization')),
122    optionalRequire(() => require('./tests/Network')),
123    optionalRequire(() => require('./tests/SecureStore')),
124    optionalRequire(() => require('./tests/Speech')),
125    optionalRequire(() => require('./tests/Recording')),
126    optionalRequire(() => require('./tests/ScreenOrientation')),
127    optionalRequire(() => require('./tests/Notifications')),
128    optionalRequire(() => require('./tests/NavigationBar')),
129    optionalRequire(() => require('./tests/SystemUI'))
130  );
131
132  if (!isDeviceFarm()) {
133    // Popup to request device's location which uses Google's location service
134    modules.push(LocationTestScreen);
135    // Fails to redirect because of malformed URL in published version with release channel parameter
136    modules.push(optionalRequire(() => require('./tests/Linking')));
137    // Has uncontrolled view controllers
138    modules.push(require('./tests/SMS'));
139    // Requires permission
140    modules.push(optionalRequire(() => require('./tests/Contacts')));
141    modules.push(optionalRequire(() => require('./tests/Calendar')));
142    modules.push(optionalRequire(() => require('./tests/CalendarReminders')));
143    modules.push(optionalRequire(() => require('./tests/MediaLibrary')));
144
145    modules.push(optionalRequire(() => require('./tests/Battery')));
146    if (Constants.isDevice) {
147      modules.push(optionalRequire(() => require('./tests/Brightness')));
148    }
149    // Crashes app when mounting component
150    modules.push(optionalRequire(() => require('./tests/Video')));
151    // "sdkUnversionedTestSuite failed: java.lang.NullPointerException: Attempt to invoke interface method
152    // 'java.util.Map expo.modules.interfaces.taskManager.TaskInterface.getOptions()' on a null object reference"
153    modules.push(TaskManagerTestScreen);
154    // Audio tests are flaky in CI due to asynchronous fetching of resources
155    modules.push(optionalRequire(() => require('./tests/Audio')));
156
157    // The Camera tests are flaky on iOS, i.e. they fail randomly
158    if (Constants.isDevice) {
159      modules.push(CameraTestScreen);
160    }
161  }
162  if (Constants.isDevice) {
163    modules.push(optionalRequire(() => require('./tests/Cellular')));
164    modules.push(optionalRequire(() => require('./tests/BarCodeScanner')));
165  }
166  return modules
167    .filter(Boolean)
168    .sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1));
169}
170