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

Added test fixture for scheduling profiler #21397

Merged
merged 1 commit into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fixtures/devtools/scheduling-profiler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies
15 changes: 15 additions & 0 deletions fixtures/devtools/scheduling-profiler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test fixture for `packages/react-devtools-scheduling-profiler`

1. First, run the fixture:
```sh
# In the root directory
# Download the latest *experimental* React build
scripts/release/download-experimental-build.js

# Run this fixtures
fixtures/devtools/scheduling-profiler/run.js
```

2. Then open [localhost:8000/](http://localhost:8000/) and use the Performance tab in Chrome to reload-and-profile.
3. Now stop profiling and export JSON.
4. Lastly, open [react-scheduling-profiler.vercel.app](https://react-scheduling-profiler.vercel.app/) and upload the performance JSON data you just recorded.
14 changes: 14 additions & 0 deletions fixtures/devtools/scheduling-profiler/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const {createElement, useLayoutEffect, useState} = React;
const {unstable_createRoot: createRoot} = ReactDOM;

function App() {
const [isMounted, setIsMounted] = useState(false);
useLayoutEffect(() => {
setIsMounted(true);
}, []);
return createElement('div', null, `isMounted? ${isMounted}`);
}

const container = document.getElementById('container');
const root = createRoot(container);
root.render(createElement(App));
14 changes: 14 additions & 0 deletions fixtures/devtools/scheduling-profiler/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Scheduling Profiler Fixture</title>

<script src="./scheduler.js"></script>
<script src="./react.js"></script>
<script src="./react-dom.js"></script>
</head>
<body>
<div id="container"></div>
<script src="./app.js"></script>
</body>
</html>
78 changes: 78 additions & 0 deletions fixtures/devtools/scheduling-profiler/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

'use strict';

const {
copyFileSync,
existsSync,
mkdirSync,
readFileSync,
rmdirSync,
} = require('fs');
const {join} = require('path');
const http = require('http');

const DEPENDENCIES = [
['scheduler/umd/scheduler.development.js', 'scheduler.js'],
['react/umd/react.development.js', 'react.js'],
['react-dom/umd/react-dom.development.js', 'react-dom.js'],
];

const BUILD_DIRECTORY = '../../../build/node_modules/';
const DEPENDENCIES_DIRECTORY = 'dependencies';

function initDependencies() {
if (existsSync(DEPENDENCIES_DIRECTORY)) {
rmdirSync(DEPENDENCIES_DIRECTORY, {recursive: true});
}
mkdirSync(DEPENDENCIES_DIRECTORY);

DEPENDENCIES.forEach(([from, to]) => {
const fromPath = join(__dirname, BUILD_DIRECTORY, from);
const toPath = join(__dirname, DEPENDENCIES_DIRECTORY, to);
console.log(`Copying ${fromPath} => ${toPath}`);
copyFileSync(fromPath, toPath);
});
}

function initServer() {
const host = 'localhost';
const port = 8000;

const requestListener = function(request, response) {
let contents;
switch (request.url) {
case '/react.js':
case '/react-dom.js':
case '/scheduler.js':
response.setHeader('Content-Type', 'text/javascript');
response.writeHead(200);
contents = readFileSync(
join(__dirname, DEPENDENCIES_DIRECTORY, request.url)
);
response.end(contents);
break;
case '/app.js':
response.setHeader('Content-Type', 'text/javascript');
response.writeHead(200);
contents = readFileSync(join(__dirname, 'app.js'));
response.end(contents);
break;
case '/index.html':
default:
response.setHeader('Content-Type', 'text/html');
response.writeHead(200);
contents = readFileSync(join(__dirname, 'index.html'));
response.end(contents);
break;
}
};

const server = http.createServer(requestListener);
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});
}

initDependencies();
initServer();