Unverified Commit adab23fa authored by Joe Haddad's avatar Joe Haddad
Browse files

e2e: Reduce complexity of e2e and improve Jest coverage (#1484)

parent 65e63403
Showing with 124 additions and 82 deletions
+124 -82
import React from 'react' import React, { Component, PropTypes } from 'react'
async function load() { async function load() {
return { users: [ return { users: [
...@@ -9,21 +9,23 @@ async function load() { ...@@ -9,21 +9,23 @@ async function load() {
] }; ] };
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const { users } = await load(); const { users } = await load();
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import DestructuringAndAwait from './DestructuringAndAwait'; ...@@ -5,6 +5,8 @@ import DestructuringAndAwait from './DestructuringAndAwait';
describe('destructuring and await', () => { describe('destructuring and await', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<DestructuringAndAwait />, div); return new Promise(resolve => {
ReactDOM.render(<DestructuringAndAwait onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function * load(limit) { function * load(limit) {
let i = 1; let i = 1;
...@@ -8,15 +8,13 @@ function * load(limit) { ...@@ -8,15 +8,13 @@ function * load(limit) {
} }
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
...@@ -25,7 +23,11 @@ export default class extends React.Component { ...@@ -25,7 +23,11 @@ export default class extends React.Component {
for (let user of load(4)) { for (let user of load(4)) {
users.push(user); users.push(user);
} }
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import Generators from './Generators'; ...@@ -5,6 +5,8 @@ import Generators from './Generators';
describe('generators', () => { describe('generators', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<Generators />, div); return new Promise(resolve => {
ReactDOM.render(<Generators onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load() { function load() {
return [ return [
...@@ -9,21 +9,23 @@ function load() { ...@@ -9,21 +9,23 @@ function load() {
]; ];
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const users = load(); const users = load();
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import ObjectDestructuring from './ObjectDestructuring'; ...@@ -5,6 +5,8 @@ import ObjectDestructuring from './ObjectDestructuring';
describe('object destructuring', () => { describe('object destructuring', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<ObjectDestructuring />, div); return new Promise(resolve => {
ReactDOM.render(<ObjectDestructuring onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load(baseUser) { function load(baseUser) {
return [ return [
...@@ -9,21 +9,23 @@ function load(baseUser) { ...@@ -9,21 +9,23 @@ function load(baseUser) {
]; ];
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const users = load({ age: 42 }); const users = load({ age: 42 });
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import ObjectSpread from './ObjectSpread'; ...@@ -5,6 +5,8 @@ import ObjectSpread from './ObjectSpread';
describe('object spread', () => { describe('object spread', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<ObjectSpread />, div); return new Promise(resolve => {
ReactDOM.render(<ObjectSpread onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load() { function load() {
return Promise.resolve([ return Promise.resolve([
...@@ -9,24 +9,26 @@ function load() { ...@@ -9,24 +9,26 @@ function load() {
]); ]);
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
componentDidMount() { componentDidMount() {
load().then(users => { load().then(users => {
this.setState({ users }, () => this.done()); this.setState({ users });
}); });
} }
componentDidUpdate() {
this.props.onReady();
}
render() { render() {
return ( return (
<div id="feature-promises"> <div id="feature-promises">
......
...@@ -5,6 +5,8 @@ import Promises from './Promises'; ...@@ -5,6 +5,8 @@ import Promises from './Promises';
describe('promises', () => { describe('promises', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<Promises />, div); return new Promise(resolve => {
ReactDOM.render(<Promises onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load({ id, ...rest } = { id: 0, user: { id: 42, name: '42' } }) { function load({ id, ...rest } = { id: 0, user: { id: 42, name: '42' } }) {
return [ return [
...@@ -9,21 +9,23 @@ function load({ id, ...rest } = { id: 0, user: { id: 42, name: '42' } }) { ...@@ -9,21 +9,23 @@ function load({ id, ...rest } = { id: 0, user: { id: 42, name: '42' } }) {
]; ];
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const users = load(); const users = load();
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import RestAndDefault from './RestAndDefault'; ...@@ -5,6 +5,8 @@ import RestAndDefault from './RestAndDefault';
describe('rest + default', () => { describe('rest + default', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<RestAndDefault />, div); return new Promise(resolve => {
ReactDOM.render(<RestAndDefault onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load({ id = 0, ...rest }) { function load({ id = 0, ...rest }) {
return [ return [
...@@ -9,21 +9,23 @@ function load({ id = 0, ...rest }) { ...@@ -9,21 +9,23 @@ function load({ id = 0, ...rest }) {
]; ];
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const users = load({ id: 0, user: { id: 42, name: '42' } }); const users = load({ id: 0, user: { id: 42, name: '42' } });
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import RestParameters from './RestParameters'; ...@@ -5,6 +5,8 @@ import RestParameters from './RestParameters';
describe('rest parameters', () => { describe('rest parameters', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<RestParameters />, div); return new Promise(resolve => {
ReactDOM.render(<RestParameters onReady={resolve} />, div);
});
}); });
}); });
import React from 'react' import React, { Component, PropTypes } from 'react'
function load(name) { function load(name) {
return [ return [
...@@ -9,21 +9,23 @@ function load(name) { ...@@ -9,21 +9,23 @@ function load(name) {
]; ];
} }
export default class extends React.Component { export default class extends Component {
static propTypes = {
onReady: PropTypes.func.isRequired
}
constructor(props) { constructor(props) {
super(props); super(props);
this.done = () => {};
this.props.setCallWhenDone && this.props.setCallWhenDone((done) => {
this.done = done;
});
this.state = { users: [] }; this.state = { users: [] };
} }
async componentDidMount() { async componentDidMount() {
const users = load('user_'); const users = load('user_');
this.setState({ users }, () => this.done()); this.setState({ users });
}
componentDidUpdate() {
this.props.onReady();
} }
render() { render() {
......
...@@ -5,6 +5,8 @@ import TemplateInterpolation from './TemplateInterpolation'; ...@@ -5,6 +5,8 @@ import TemplateInterpolation from './TemplateInterpolation';
describe('template interpolation', () => { describe('template interpolation', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const div = document.createElement('div'); const div = document.createElement('div');
ReactDOM.render(<TemplateInterpolation />, div); return new Promise(resolve => {
ReactDOM.render(<TemplateInterpolation onReady={resolve} />, div);
});
}); });
}); });
...@@ -110,6 +110,9 @@ create_react_app --scripts-version=$scripts_path --internal-testing-template=$ro ...@@ -110,6 +110,9 @@ create_react_app --scripts-version=$scripts_path --internal-testing-template=$ro
# Enter the app directory # Enter the app directory
cd test-kitchensink cd test-kitchensink
# Link to our preset
npm link $root_path/packages/babel-preset-react-app
# Test the build # Test the build
NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build NODE_PATH=src REACT_APP_SHELL_ENV_MESSAGE=fromtheshell npm run build
# Check for expected output # Check for expected output
...@@ -120,6 +123,7 @@ test -e build/static/js/main.*.js ...@@ -120,6 +123,7 @@ test -e build/static/js/main.*.js
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true \ CI=true \
NODE_PATH=src \ NODE_PATH=src \
NODE_ENV=test \
npm test -- --no-cache --testPathPattern="/src/" npm test -- --no-cache --testPathPattern="/src/"
# Test "development" environment # Test "development" environment
...@@ -132,18 +136,23 @@ grep -q 'The app is running at:' <(tail -f $tmp_server_log) ...@@ -132,18 +136,23 @@ grep -q 'The app is running at:' <(tail -f $tmp_server_log)
E2E_URL="http://localhost:3001" \ E2E_URL="http://localhost:3001" \
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true NODE_PATH=src \ CI=true NODE_PATH=src \
NODE_ENV=development \
node node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js node node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
# Test "production" environment # Test "production" environment
E2E_FILE=./build/index.html \ E2E_FILE=./build/index.html \
CI=true \ CI=true \
NODE_PATH=src \ NODE_PATH=src \
NODE_ENV=production \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
# ****************************************************************************** # ******************************************************************************
# Finally, let's check that everything still works after ejecting. # Finally, let's check that everything still works after ejecting.
# ****************************************************************************** # ******************************************************************************
# Unlink our preset
npm unlink $root_path/packages/babel-preset-react-app
# Eject... # Eject...
echo yes | npm run eject echo yes | npm run eject
...@@ -153,7 +162,7 @@ npm link $root_path/packages/eslint-config-react-app ...@@ -153,7 +162,7 @@ npm link $root_path/packages/eslint-config-react-app
npm link $root_path/packages/react-dev-utils npm link $root_path/packages/react-dev-utils
npm link $root_path/packages/react-scripts npm link $root_path/packages/react-scripts
# ...and we need to remove template's .babelrc # ...and we need to remove template's .babelrc
rm .babelrc rm .babelrc
# Test the build # Test the build
...@@ -166,6 +175,7 @@ test -e build/static/js/main.*.js ...@@ -166,6 +175,7 @@ test -e build/static/js/main.*.js
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true \ CI=true \
NODE_PATH=src \ NODE_PATH=src \
NODE_ENV=test \
npm test -- --no-cache --testPathPattern="/src/" npm test -- --no-cache --testPathPattern="/src/"
# Test "development" environment # Test "development" environment
...@@ -178,7 +188,7 @@ grep -q 'The app is running at:' <(tail -f $tmp_server_log) ...@@ -178,7 +188,7 @@ grep -q 'The app is running at:' <(tail -f $tmp_server_log)
E2E_URL="http://localhost:3002" \ E2E_URL="http://localhost:3002" \
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
CI=true NODE_PATH=src \ CI=true NODE_PATH=src \
NODE_ENV=production \ NODE_ENV=development \
node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js node_modules/.bin/mocha --require babel-register --require babel-polyfill integration/*.test.js
# Test "production" environment # Test "production" environment
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment