import * as React from 'react'; import * as ReactDOMClient from 'react-dom/client'; import { BrowserRouter as Router, Routes, Route, Link } from 'react-router'; import * as DomTestingLibrary from '@testing-library/dom'; import TestViewer from './TestViewer'; const fixtures = []; const importFixtures = require.context('./fixtures', true, /\.(js|ts|tsx)$/, 'lazy'); importFixtures.keys().forEach((path) => { // require.context contains paths for module alias imports and relative imports if (!path.startsWith('.')) { return; } const [suite, name] = path .replace('./', '') .replace(/\.\w+$/, '') .split('/'); fixtures.push({ path, suite: `e2e/${suite}`, name, Component: React.lazy(() => importFixtures(path)), }); }); function App() { function computeIsDev() { if (window.location.hash === '#dev') { return true; } if (window.location.hash === '#no-dev') { return false; } return process.env.NODE_ENV === 'development'; } const [isDev, setDev] = React.useState(computeIsDev); React.useEffect(() => { function handleHashChange() { setDev(computeIsDev()); } window.addEventListener('hashchange', handleHashChange); return () => { window.removeEventListener('hashchange', handleHashChange); }; }, []); function computePath(fixture) { return `/${fixture.suite}/${fixture.name}`; } return ( {fixtures.map((fixture) => { const path = computePath(fixture); const FixtureComponent = fixture.Component; if (FixtureComponent === undefined) { console.warn('Missing `Component` ', fixture); return null; } return ( } /> ); })} ); } const container = document.getElementById('react-root'); const children = ; const root = ReactDOMClient.createRoot(container); root.render(children); window.DomTestingLibrary = DomTestingLibrary; window.elementToString = function elementToString(element) { if ( element != null && (element.nodeType === element.ELEMENT_NODE || element.nodeType === element.DOCUMENT_NODE) ) { return window.DomTestingLibrary.prettyDOM(element, undefined, { highlight: true, maxDepth: 1, }); } return String(element); };