Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored DevTools test shell for e2e #22968

Merged
merged 1 commit into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,9 +8,11 @@ test.describe('Testing Todo-List App', () => {
let page, frameElementHandle, frame;
test.beforeAll(async ({browser}) => {
page = await browser.newPage();
await page.goto('http://localhost:8080/', {waitUntil: 'domcontentloaded'});
await page.waitForSelector('iframe#target');
frameElementHandle = await page.$('#target');
await page.goto('http://localhost:8080/e2e.html', {
waitUntil: 'domcontentloaded',
});
await page.waitForSelector('iframe#iframe');
frameElementHandle = await page.$('#iframe');
frame = await frameElementHandle.contentFrame();
});

Expand Down Expand Up @@ -42,7 +44,7 @@ test.describe('Testing Todo-List App', () => {
for (let i = 1; i <= countOfItems; ++i) {
await page.click('[class^=ToggleContent]', {delay: 100});
await frame.click(`.listitem:nth-child(${i})`, {delay: 50});
await page.waitForSelector('span.Value___tNzum');
await page.waitForSelector('span[class^=Value]');
const text = await page.innerText('span[class^=Value]');
await expect(text).toEqual(listItemsProps[i]);
}
Expand Down
40 changes: 40 additions & 0 deletions packages/react-devtools-shell/e2e.html
@@ -0,0 +1,40 @@
<!doctype html>
<html>
<head>
<meta charset="utf8">
<title>React DevTools</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
font-size: 12px;
line-height: 1.5;
}
#iframe {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 50vh;
}
#devtools {
position: absolute;
bottom: 0;
left: 0;
width: 100vw;
height: 50vh;
}
</style>
</head>
<body>
<iframe id="iframe"></iframe>
<div id="devtools"></div>
<script src="dist/e2e-devtools.js"></script>
</body>
</html>
Expand Up @@ -48,8 +48,9 @@
<button id="mountButton">Unmount test app</button>
<div class="optionsRowSpacer">&nbsp;</div>
<span>
<a href="https://react-devtools-experimental-chrome.now.sh/">Chrome extension</a>
<a href="https://react-devtools-experimental-firefox.now.sh/">Firefox extension</a>
<a href="/multi.html">multi DevTools</a>
|
<a href="/e2e.html">e2e tests</a>
</span>
</div>

Expand Down
4 changes: 1 addition & 3 deletions packages/react-devtools-shell/package.json
Expand Up @@ -3,9 +3,7 @@
"name": "react-devtools-shell",
"version": "0.0.0",
"scripts": {
"start": "yarn start:app",
"start:app": "cross-env NODE_ENV=development cross-env TARGET=local webpack-dev-server --open-page app.html",
"start:multi": "cross-env NODE_ENV=development cross-env TARGET=local webpack-dev-server --open-page multi.html"
"start": "cross-env NODE_ENV=development cross-env TARGET=local webpack-dev-server"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the app.html file to index.html and added a small nav bar up top so we can get rid of these separate targets.

},
"dependencies": {
"immutable": "^4.0.0-rc.12",
Expand Down
20 changes: 20 additions & 0 deletions packages/react-devtools-shell/src/e2e/app.js
@@ -0,0 +1,20 @@
/** @flow */

// This test harness mounts each test app as a separate root to test multi-root applications.

import {createElement} from 'react';
import {
// $FlowFixMe Flow does not yet know about createRoot()
createRoot,
} from 'react-dom';
import ToDoList from '../app/ToDoList';

const container = document.createElement('div');

((document.body: any): HTMLBodyElement).appendChild(container);

// TODO We may want to parameterize this app
// so that it can load things other than just ToDoList.

const root = createRoot(container);
root.render(createElement(ToDoList));
34 changes: 34 additions & 0 deletions packages/react-devtools-shell/src/e2e/devtools.js
@@ -0,0 +1,34 @@
import * as React from 'react';
import {createRoot} from 'react-dom';
import {
activate as activateBackend,
initialize as initializeBackend,
} from 'react-devtools-inline/backend';
import {initialize as createDevTools} from 'react-devtools-inline/frontend';

function inject(contentDocument, sourcePath, callback) {
const script = contentDocument.createElement('script');
script.onload = callback;
script.src = sourcePath;

((contentDocument.body: any): HTMLBodyElement).appendChild(script);
}

function init(appIframe, devtoolsContainer, appSource) {
const {contentDocument, contentWindow} = appIframe;

initializeBackend(contentWindow);

const DevTools = createDevTools(contentWindow);

inject(contentDocument, appSource, () => {
createRoot(devtoolsContainer).render(<DevTools />);
});

activateBackend(contentWindow);
}

const iframe = document.getElementById('iframe');
const devtoolsContainer = document.getElementById('devtools');

init(iframe, devtoolsContainer, 'dist/e2e-app.js');
2 changes: 2 additions & 0 deletions packages/react-devtools-shell/webpack.config.js
Expand Up @@ -44,6 +44,8 @@ const config = {
entry: {
'app-index': './src/app/index.js',
'app-devtools': './src/app/devtools.js',
'e2e-app': './src/e2e/app.js',
'e2e-devtools': './src/e2e/devtools.js',
'multi-left': './src/multi/left.js',
'multi-devtools': './src/multi/devtools.js',
'multi-right': './src/multi/right.js',
Expand Down