| 1 | /** @flow */ |
| 2 | |
| 3 | // This test harness mounts each test app as a separate root to test multi-root applications. |
| 4 | |
| 5 | import * as React from 'react'; |
| 6 | import * as ReactDOM from 'react-dom'; |
| 7 | import ListApp from '../e2e-apps/ListApp'; |
| 8 | import ListAppLegacy from '../e2e-apps/ListAppLegacy'; |
| 9 | import {gte} from 'react-devtools-shared/src/backend/utils'; |
| 10 | |
| 11 | const version = process.env.E2E_APP_REACT_VERSION; |
| 12 | |
| 13 | function mountApp(App: () => React$Node) { |
| 14 | const container = document.createElement('div'); |
| 15 | |
| 16 | (document.body as any as HTMLBodyElement).appendChild(container); |
| 17 | |
| 18 | // $FlowFixMe[prop-missing]: These are removed in 19. |
| 19 | ReactDOM.render(<App />, container); |
| 20 | } |
| 21 | function mountTestApp() { |
| 22 | // ListApp has hooks, which aren't available until 16.8.0 |
| 23 | mountApp(gte(version, '16.8.0') ? ListApp : ListAppLegacy); |
| 24 | } |
| 25 | |
| 26 | mountTestApp(); |
| 27 | |
| 28 | // ReactDOM Test Selector APIs used by Playwright e2e tests |
| 29 | // If they don't exist, we mock them |
| 30 | window.parent.REACT_DOM_APP = { |
| 31 | createTestNameSelector: name => `[data-testname="${name}"]`, |
| 32 | findAllNodes: (container, nodes) => |
| 33 | container.querySelectorAll(nodes.join(' ')), |
| 34 | ...ReactDOM, |
| 35 | }; |