1/* global page, browser */ 2import { setDefaultOptions } from 'expect-puppeteer'; 3 4import config from '../jest-puppeteer.config'; 5import { expectResults } from './utils/report'; 6 7const TESTS = [ 8 'Basic', 9 'Asset', 10 'AuthSession', 11 'Constants', 12 'FileSystem', 13 'Font', 14 'Permissions', 15 'Localization', 16 'SecureStore', 17 'Contacts', 18 'Random', 19 'Crypto', 20 'Blur', 21 'LinearGradient', 22 'KeepAwake', 23 'HTML', 24 'FirebaseCore', 25 'FirebaseAnalytics', 26 // Overridding permissions doesn't work in headless mode 27 // see https://github.com/puppeteer/puppeteer/issues/3279 28 !config.launch.headless && 'expo-notifications', 29 // 'Haptics', 30 // 'SecureStore', 31].filter(t => t); 32 33// This is how long we allocate for the actual tests to be run after the test screen has mounted. 34const MIN_TIME = 50000; 35const RENDER_MOUNTING_TIMEOUT = 700; 36 37setDefaultOptions({ 38 timeout: MIN_TIME * 1.5, 39}); 40 41beforeAll(async () => { 42 const context = browser.defaultBrowserContext(); 43 await context.overridePermissions(config.url, ['notifications']); 44}); 45 46function matchID(id, ...props) { 47 return expect(page).toMatchElement(`div[data-testid="${id}"]`, ...props); 48} 49 50describe('test-suite', () => { 51 TESTS.map(testName => { 52 it( 53 `passes ${testName}`, 54 async () => { 55 /// Pause the timeout 56 // await jestPuppeteer.debug(); 57 58 await page.goto(`${config.url}/test-suite/run?tests=${testName}`, { 59 timeout: MIN_TIME, 60 }); 61 62 // Ensure the app linked to the testing screen (give it 100ms for navigation mounting) 63 await matchID('test_suite_container', { visible: true, timeout: RENDER_MOUNTING_TIMEOUT }); 64 // Wait for the final result to be rendered. This means all the tests have finished. 65 await matchID('test_suite_final_results', { visible: true, timeout: MIN_TIME }); 66 // Get the DOM element matching the testID prop. 67 // This text will contain the final results (parity with native) 68 const element = await page.$(`div[data-testid="test_suite_final_results"]`); 69 // Read the text contents and parse them as JSON 70 const input = await (await element.getProperty('textContent')).jsonValue(); 71 72 // Parse, expect, and print the results of our tests 73 expectResults({ 74 testName, 75 input, 76 }); 77 }, 78 // Add some extra time for page content loading (page.goto) and parsing the DOM 79 (MIN_TIME + RENDER_MOUNTING_TIMEOUT) * 1.2 80 ); 81 }); 82}); 83