DevTools] e2e Regression Testing App (#24619)
This PR adds an e2e regression app to the react-devtools-shell package. This app: * Has an app.js and an appLegacy.js entrypoint because apps prior to React 18 need to use ReactDOM.render. These files will create and render multiple test apps (though they currently only render the List) * Moved the ListApp out of the e2e folder and into an e2e-apps folder so that both e2e and e2e-regression can use the same test apps * Creates a ListAppLegacy app because prior to React 16.8 hooks didn't exist. * Added a devtools file for the e2e-regression * Modifies the webpack config so that the e2e-regression React app can use different a different React version than DevTools
This commit is contained in:
parent
1328ff70cd
commit
3133dfa6ee
|
@ -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-regression.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -51,6 +51,7 @@
|
|||
<a href="/multi.html">multi DevTools</a>
|
||||
|
|
||||
<a href="/e2e.html">e2e tests</a>
|
||||
<a href="/e2e-regression.html">e2e regression tests</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"immutable": "^4.0.0-rc.12",
|
||||
"react-native-web": "0.0.0-26873b469"
|
||||
"react-native-web": "0.0.0-26873b469",
|
||||
"semver": "^6.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.1",
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export default function App() {
|
||||
return <List />;
|
||||
}
|
||||
|
||||
class List extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
items: ['one', 'two', 'three'],
|
||||
};
|
||||
}
|
||||
|
||||
addItem = () => {
|
||||
if (this.inputRef && this.inputRef.value) {
|
||||
this.setState({items: [...this.state.items, this.inputRef.value]});
|
||||
this.inputRef.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<input
|
||||
data-testname="AddItemInput"
|
||||
value={this.state.text}
|
||||
onChange={this.onInputChange}
|
||||
ref={c => (this.inputRef = c)}
|
||||
/>
|
||||
<button data-testname="AddItemButton" onClick={this.addItem}>
|
||||
Add Item
|
||||
</button>
|
||||
<ul data-testname="List">
|
||||
{this.state.items.map((label, index) => (
|
||||
<ListItem key={index} label={label} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function ListItem({label}) {
|
||||
return <li data-testname="ListItem">{label}</li>;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/** @flow */
|
||||
|
||||
// This test harness mounts each test app as a separate root to test multi-root applications.
|
||||
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import {gte} from 'semver';
|
||||
import ListApp from '../e2e-apps/ListApp';
|
||||
import ListAppLegacy from '../e2e-apps/ListAppLegacy';
|
||||
const version = process.env.E2E_APP_REACT_VERSION;
|
||||
|
||||
function mountApp(App) {
|
||||
const container = document.createElement('div');
|
||||
|
||||
((document.body: any): HTMLBodyElement).appendChild(container);
|
||||
|
||||
ReactDOM.render(<App />, container);
|
||||
}
|
||||
function mountTestApp() {
|
||||
// ListApp has hooks, which aren't available until 16.8.0
|
||||
mountApp(gte(version, '16.8.0') ? ListApp : ListAppLegacy);
|
||||
}
|
||||
|
||||
mountTestApp();
|
||||
|
||||
// ReactDOM Test Selector APIs used by Playwright e2e tests
|
||||
// If they don't exist, we mock them
|
||||
window.parent.REACT_DOM_APP = {
|
||||
createTestNameSelector: name => `[data-testname="${name}"]`,
|
||||
findAllNodes: (container, nodes) =>
|
||||
container.querySelectorAll(nodes.join(' ')),
|
||||
...ReactDOM,
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
/** @flow */
|
||||
|
||||
// This test harness mounts each test app as a separate root to test multi-root applications.
|
||||
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import {createRoot} from 'react-dom/client';
|
||||
import ListApp from '../e2e-apps/ListApp';
|
||||
|
||||
function mountApp(App) {
|
||||
const container = document.createElement('div');
|
||||
|
||||
((document.body: any): HTMLBodyElement).appendChild(container);
|
||||
|
||||
const root = createRoot(container);
|
||||
root.render(<App />);
|
||||
}
|
||||
function mountTestApp() {
|
||||
mountApp(ListApp);
|
||||
}
|
||||
|
||||
mountTestApp();
|
||||
|
||||
// ReactDOM Test Selector APIs used by Playwright e2e tests
|
||||
window.parent.REACT_DOM_APP = ReactDOM;
|
|
@ -0,0 +1,54 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import {createRoot} from 'react-dom/client';
|
||||
import {
|
||||
activate as activateBackend,
|
||||
initialize as initializeBackend,
|
||||
} from 'react-devtools-inline/backend';
|
||||
import {initialize as createDevTools} from 'react-devtools-inline/frontend';
|
||||
|
||||
// This is a pretty gross hack to make the runtime loaded named-hooks-code work.
|
||||
// TODO (Webpack 5) Hoepfully we can remove this once we upgrade to Webpack 5.
|
||||
// $FlowFixMer
|
||||
__webpack_public_path__ = '/dist/'; // eslint-disable-line no-undef
|
||||
|
||||
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
|
||||
function hookNamesModuleLoaderFunction() {
|
||||
return import('react-devtools-inline/hookNames');
|
||||
}
|
||||
|
||||
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, () => {
|
||||
// $FlowFixMe Flow doesn't know about createRoot() yet.
|
||||
createRoot(devtoolsContainer).render(
|
||||
<DevTools
|
||||
hookNamesModuleLoaderFunction={hookNamesModuleLoaderFunction}
|
||||
showTabBar={true}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
activateBackend(contentWindow);
|
||||
}
|
||||
|
||||
const iframe = document.getElementById('iframe');
|
||||
const devtoolsContainer = document.getElementById('devtools');
|
||||
|
||||
init(iframe, devtoolsContainer, 'dist/e2e-app-regression.js');
|
||||
|
||||
// ReactDOM Test Selector APIs used by Playwright e2e tests
|
||||
window.parent.REACT_DOM_DEVTOOLS = ReactDOM;
|
|
@ -12,7 +12,7 @@ const container = document.createElement('div');
|
|||
|
||||
// TODO We may want to parameterize this app
|
||||
// so that it can load things other than just ToDoList.
|
||||
const App = require('./apps/ListApp').default;
|
||||
const App = require('../e2e-apps/ListApp').default;
|
||||
|
||||
const root = createRoot(container);
|
||||
root.render(<App />);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const {resolve} = require('path');
|
||||
const {DefinePlugin} = require('webpack');
|
||||
const fs = require('fs');
|
||||
const {
|
||||
DARK_MODE_DIMMED_WARNING_COLOR,
|
||||
DARK_MODE_DIMMED_ERROR_COLOR,
|
||||
|
@ -11,6 +12,12 @@ const {
|
|||
getVersionString,
|
||||
} = require('react-devtools-extensions/utils');
|
||||
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
|
||||
const semver = require('semver');
|
||||
|
||||
const ReactVersionSrc = fs.readFileSync(require.resolve('shared/ReactVersion'));
|
||||
const currentReactVersion = /export default '([^']+)';/.exec(
|
||||
ReactVersionSrc,
|
||||
)[1];
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
if (!NODE_ENV) {
|
||||
|
@ -38,105 +45,157 @@ const __DEV__ = NODE_ENV === 'development';
|
|||
|
||||
const DEVTOOLS_VERSION = getVersionString();
|
||||
|
||||
const config = {
|
||||
mode: __DEV__ ? 'development' : 'production',
|
||||
devtool: __DEV__ ? 'cheap-source-map' : 'source-map',
|
||||
entry: {
|
||||
// If the React version isn't set, we will use the
|
||||
// current React version instead. Likewise if the
|
||||
// React version isnt' set, we'll use the build folder
|
||||
// for both React DevTools and React
|
||||
const REACT_VERSION = process.env.REACT_VERSION
|
||||
? semver.coerce(process.env.REACT_VERSION).version
|
||||
: currentReactVersion;
|
||||
|
||||
const E2E_APP_BUILD_DIR = process.env.REACT_VERSION
|
||||
? resolve(__dirname, '..', '..', 'build-regression', 'node_modules')
|
||||
: builtModulesDir;
|
||||
|
||||
const makeConfig = (entry, alias) => {
|
||||
const config = {
|
||||
mode: __DEV__ ? 'development' : 'production',
|
||||
devtool: __DEV__ ? 'cheap-source-map' : 'source-map',
|
||||
entry,
|
||||
node: {
|
||||
// source-maps package has a dependency on 'fs'
|
||||
// but this build won't trigger that code path
|
||||
fs: 'empty',
|
||||
},
|
||||
resolve: {
|
||||
alias,
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
__DEV__,
|
||||
__EXPERIMENTAL__: true,
|
||||
__EXTENSION__: false,
|
||||
__PROFILE__: false,
|
||||
__TEST__: NODE_ENV === 'test',
|
||||
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
|
||||
'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
|
||||
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-shell"`,
|
||||
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
||||
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"${DARK_MODE_DIMMED_WARNING_COLOR}"`,
|
||||
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"${DARK_MODE_DIMMED_ERROR_COLOR}"`,
|
||||
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"${DARK_MODE_DIMMED_LOG_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"${LIGHT_MODE_DIMMED_WARNING_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"${LIGHT_MODE_DIMMED_ERROR_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
|
||||
'process.env.E2E_APP_REACT_VERSION': `"${REACT_VERSION}"`,
|
||||
}),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
configFile: resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'react-devtools-shared',
|
||||
'babel.config.js',
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'style-loader',
|
||||
},
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: true,
|
||||
modules: true,
|
||||
localIdentName: '[local]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
if (TARGET === 'local') {
|
||||
// Local dev server build.
|
||||
config.devServer = {
|
||||
hot: true,
|
||||
port: 8080,
|
||||
clientLogLevel: 'warning',
|
||||
publicPath: '/dist/',
|
||||
stats: 'errors-only',
|
||||
};
|
||||
} else {
|
||||
// Static build to deploy somewhere else.
|
||||
config.output = {
|
||||
path: resolve(__dirname, 'dist'),
|
||||
filename: '[name].js',
|
||||
};
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
||||
const app = makeConfig(
|
||||
{
|
||||
'app-index': './src/app/index.js',
|
||||
'app-devtools': './src/app/devtools.js',
|
||||
'e2e-app': './src/e2e/app.js',
|
||||
'e2e-devtools': './src/e2e/devtools.js',
|
||||
'e2e-devtools-regression': './src/e2e-regression/devtools.js',
|
||||
'multi-left': './src/multi/left.js',
|
||||
'multi-devtools': './src/multi/devtools.js',
|
||||
'multi-right': './src/multi/right.js',
|
||||
'e2e-regression': './src/e2e-regression/app.js',
|
||||
},
|
||||
node: {
|
||||
// source-maps package has a dependency on 'fs'
|
||||
// but this build won't trigger that code path
|
||||
fs: 'empty',
|
||||
{
|
||||
react: resolve(builtModulesDir, 'react'),
|
||||
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
|
||||
'react-devtools-feature-flags': resolveFeatureFlags('shell'),
|
||||
'react-dom/client': resolve(builtModulesDir, 'react-dom/client'),
|
||||
'react-dom': resolve(builtModulesDir, 'react-dom/unstable_testing'),
|
||||
'react-is': resolve(builtModulesDir, 'react-is'),
|
||||
scheduler: resolve(builtModulesDir, 'scheduler'),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
react: resolve(builtModulesDir, 'react'),
|
||||
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
|
||||
'react-devtools-feature-flags': resolveFeatureFlags('shell'),
|
||||
'react-dom/client': resolve(builtModulesDir, 'react-dom/client'),
|
||||
'react-dom': resolve(builtModulesDir, 'react-dom/unstable_testing'),
|
||||
'react-is': resolve(builtModulesDir, 'react-is'),
|
||||
scheduler: resolve(builtModulesDir, 'scheduler'),
|
||||
},
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
__DEV__,
|
||||
__EXPERIMENTAL__: true,
|
||||
__EXTENSION__: false,
|
||||
__PROFILE__: false,
|
||||
__TEST__: NODE_ENV === 'test',
|
||||
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
|
||||
'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
|
||||
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-shell"`,
|
||||
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
||||
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"${DARK_MODE_DIMMED_WARNING_COLOR}"`,
|
||||
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"${DARK_MODE_DIMMED_ERROR_COLOR}"`,
|
||||
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"${DARK_MODE_DIMMED_LOG_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"${LIGHT_MODE_DIMMED_WARNING_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"${LIGHT_MODE_DIMMED_ERROR_COLOR}"`,
|
||||
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
|
||||
}),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
);
|
||||
|
||||
// Prior to React 18, we use ReactDOM.render rather than
|
||||
// createRoot.
|
||||
// We also use a separate build folder to build the React App
|
||||
// so that we can test the current DevTools against older version of React
|
||||
const e2eRegressionApp = semver.lt(REACT_VERSION, '18.0.0')
|
||||
? makeConfig(
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
configFile: resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'react-devtools-shared',
|
||||
'babel.config.js',
|
||||
),
|
||||
},
|
||||
'e2e-app-regression': './src/e2e-regression/app-legacy.js',
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'style-loader',
|
||||
},
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: true,
|
||||
modules: true,
|
||||
localIdentName: '[local]',
|
||||
},
|
||||
},
|
||||
],
|
||||
react: resolve(E2E_APP_BUILD_DIR, 'react'),
|
||||
'react-dom': resolve(E2E_APP_BUILD_DIR, 'react-dom'),
|
||||
...(semver.satisfies(REACT_VERSION, '16.5')
|
||||
? {schedule: resolve(E2E_APP_BUILD_DIR, 'schedule')}
|
||||
: {scheduler: resolve(E2E_APP_BUILD_DIR, 'scheduler')}),
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
)
|
||||
: makeConfig(
|
||||
{
|
||||
'e2e-app-regression': './src/e2e-regression/app.js',
|
||||
},
|
||||
{
|
||||
react: resolve(E2E_APP_BUILD_DIR, 'react'),
|
||||
'react-dom': resolve(E2E_APP_BUILD_DIR, 'react-dom'),
|
||||
'react-dom/client': resolve(E2E_APP_BUILD_DIR, 'react-dom'),
|
||||
scheduler: resolve(E2E_APP_BUILD_DIR, 'scheduler'),
|
||||
},
|
||||
);
|
||||
|
||||
if (TARGET === 'local') {
|
||||
// Local dev server build.
|
||||
config.devServer = {
|
||||
hot: true,
|
||||
port: 8080,
|
||||
clientLogLevel: 'warning',
|
||||
publicPath: '/dist/',
|
||||
stats: 'errors-only',
|
||||
};
|
||||
} else {
|
||||
// Static build to deploy somewhere else.
|
||||
config.output = {
|
||||
path: resolve(__dirname, 'dist'),
|
||||
filename: '[name].js',
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = config;
|
||||
module.exports = [app, e2eRegressionApp];
|
||||
|
|
Loading…
Reference in New Issue