Skip to content

Commit

Permalink
Added test fixture for scheduling profiler (#21397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Apr 30, 2021
1 parent 269dd6e commit b6644fa
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
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();

0 comments on commit b6644fa

Please sign in to comment.