Skip to content

Commit

Permalink
Use create-react-app for fixtures application
Browse files Browse the repository at this point in the history
This moves the current fixture architecture to one based around create-react-app. There are a few important things to note:

* The react-loader.js script is always loaded before the bundle and will populate React and ReactDOM on the window. It is then read from the window by all components.
* The UI for the "React Sandbox" or "React Fixtures App" is also rendered with whatever version of React the user has selected. This means we dont have to deal with iframes or worry about multiple versions of React potentially interferring. But it also means that all components must be written using createClass to be fully backwards compatable. I tested back to 0.13.1 and it works fine.
  • Loading branch information
Brandon Dail committed Jan 3, 2017
1 parent 62c3c4b commit 99bfa28
Show file tree
Hide file tree
Showing 28 changed files with 5,868 additions and 576 deletions.
15 changes: 15 additions & 0 deletions fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
17 changes: 1 addition & 16 deletions fixtures/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# Browser Fixtures

This folder contains tools to assist in the testing of browser quirks.

Each document is browsable without setting up a static file server. Just open
the test case in a browser.

## Browser Targets

React 15+ supports all ES5 compliant browsers:

https://facebook.github.io/react/docs/react-dom.html#browser-support

### IE8 Support

React 0.14 and lower support IE8 after including several required shims.
# React Fixtures (TODO)
19 changes: 19 additions & 0 deletions fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "_fixtures",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.8.4"
},
"dependencies": {
"query-string": "^4.2.3",
"react": "^15.4.1",
"react-dom": "^15.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added fixtures/public/favicon.ico
Binary file not shown.
32 changes: 32 additions & 0 deletions fixtures/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<script src="react-loader.js"></script>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
8 changes: 5 additions & 3 deletions fixtures/react-loader.js → fixtures/public/react-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* (Loads React 15.4.1)
*/

var REACT_PATH = '../../build/react.js';
var DOM_PATH = '../../build/react-dom.js';
var REACT_PATH = 'react.js';
var DOM_PATH = 'react-dom.js';
var BABEL_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.19.0/babel.js';

function parseQuery(qstr) {
Expand All @@ -25,9 +25,11 @@ function parseQuery(qstr) {
return query;
}

var query = parseQuery(window.location.search.slice(1));
var query = parseQuery(window.location.search);
var version = query.version || 'local';

console.log(query)

if (version !== 'local') {
REACT_PATH = 'https://unpkg.com/react@' + version + '/dist/react.min.js';
DOM_PATH = 'https://unpkg.com/react-dom@' + version + '/dist/react-dom.min.js';
Expand Down
82 changes: 0 additions & 82 deletions fixtures/range-inputs/index.html

This file was deleted.

84 changes: 0 additions & 84 deletions fixtures/selects/index.html

This file was deleted.

19 changes: 19 additions & 0 deletions fixtures/src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const React = window.React;
import Header from './Header';
import Fixtures from './fixtures';
import '../styles/App.css';

const App = React.createClass({
render() {
return (
<div>
<Header />
<div className="container" >
<Fixtures />
</div>
</div>
);
},
});

export default App;
68 changes: 68 additions & 0 deletions fixtures/src/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { parse, stringify } from 'query-string';
const React = window.React;

const Header = React.createClass({
getInitialState() {
const query = parse(window.location.search);
const version = query.version || 'local';
const versions = [version];
return { version, versions };
},
componentWillMount() {
fetch('http://api.github.com/repos/facebook/react/tags')
.then(res => res.json())
.then(tags => {
let versions = tags.map(tag => tag.name.slice(1));
versions = ['local', ...versions];
this.setState({ versions });
});
},
handleVersionChange(event) {
const query = parse(window.location.search);
query.version = event.target.value;
if (query.version === 'local') {
delete query.version;
}
window.location.search = stringify(query);
},
handleFixtureChange(event) {
window.location.pathname = event.target.value;
},
render() {
return (
<header className="header">
<div className="header__inner">
<span className="header__logo">
<img src="https://facebook.github.io/react/img/logo.svg" alt="" width="32" height="32" />
React Sandbox (v{React.version})
</span>

<div className="header-controls">
<label htmlFor="example">
<span className="sr-only">Select an example</span>
<select value={window.location.pathname} onChange={this.handleFixtureChange}>
<option value="/">Select a Fixture</option>
<option value="/range-inputs">Range Inputs</option>
<option value="/text-inputs">Text Inputs</option>
<option value="/selects">Selects</option>
<option value="/textareas">Textareas</option>
</select>
</label>
<label htmlFor="react_version">
<span className="sr-only">Select a version to test</span>
<select
value={this.state.version}
onChange={this.handleVersionChange}>
{this.state.versions.map(version => (
<option key={version} value={version}>{version}</option>
))}
</select>
</label>
</div>
</div>
</header>
);
},
});

export default Header;
28 changes: 28 additions & 0 deletions fixtures/src/components/RangeInputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const React = window.React;

const RangeInputs = React.createClass({
getInitialState() {
return { value: 0.5 };
},
onChange(event) {
this.setState({ value: event.target.value });
},
render() {
return (
<form>
<fieldset>
<legend>Controlled</legend>
<input type="range" value={this.state.value} onChange={this.onChange.bind(this)} />
<span className="hint">Value: {this.state.value}</span>
</fieldset>

<fieldset>
<legend>Uncontrolled</legend>
<input type="range" defaultValue={0.5} />
</fieldset>
</form>
);
},
});

export default RangeInputs;
Loading

0 comments on commit 99bfa28

Please sign in to comment.