Skip to content

Commit

Permalink
Prettier 1.2.2, refactor runCommand (#3352)
Browse files Browse the repository at this point in the history
* Prettier 1.2.2, refactor runCommand

* Fix test-examples

* Run prettier on examples and scripts

* Fix integration_tests

* Disable esilnt's computed-property-spacing
  • Loading branch information
thymikee authored and cpojer committed Apr 25, 2017
1 parent 3749160 commit 8c2a651
Show file tree
Hide file tree
Showing 32 changed files with 135 additions and 160 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./packages/eslint-config-fb-strict/index.js",
"parser": "babel-eslint",
"rules": {
"computed-property-spacing": 0,
"no-multiple-empty-lines": 1,
"flowtype/require-valid-file-annotation": 2,
"flowtype/boolean-style": 2,
Expand Down
9 changes: 6 additions & 3 deletions examples/async/__mocks__/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export default function request(url) {
return new Promise((resolve, reject) => {
const userID = parseInt(url.substr('/users/'.length), 10);
process.nextTick(
() => users[userID] ? resolve(users[userID]) : reject({
error: 'User with ' + userID + ' not found.',
})
() =>
(users[userID]
? resolve(users[userID])
: reject({
error: 'User with ' + userID + ' not found.',
}))
);
});
}
10 changes: 5 additions & 5 deletions examples/async/__tests__/user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import * as user from '../user';

// The promise that is being tested should be returned.
it('works with promises', () => {
return user.getUserName(5)
.then(name => expect(name).toEqual('Paul'));
return user.getUserName(5).then(name => expect(name).toEqual('Paul'));
});

// async/await can also be used.
Expand All @@ -21,10 +20,11 @@ it('works with async/await', async () => {
// Testing for async errors can be done using `catch`.
it('tests error with promises', () => {
expect.assertions(1);
return user.getUserName(3)
.catch(e => expect(e).toEqual({
return user.getUserName(3).catch(e =>
expect(e).toEqual({
error: 'User with 3 not found.',
}));
})
);
});

// Or try-catch.
Expand Down
1 change: 0 additions & 1 deletion examples/enzyme/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React from 'react';

export default class CheckboxWithLabel extends React.Component {

constructor(props) {
super(props);
this.state = {isChecked: false};
Expand Down
4 changes: 1 addition & 3 deletions examples/enzyme/__tests__/CheckboxWithLabel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import CheckboxWithLabel from '../CheckboxWithLabel';

it('CheckboxWithLabel changes the text after click', () => {
// Render a checkbox with label in the document
const checkbox = shallow(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);

expect(checkbox.text()).toEqual('Off');

Expand Down
2 changes: 1 addition & 1 deletion examples/jquery/__tests__/displayUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ it('displays a user after a click', () => {

// Tell the fetchCurrentUser mock function to automatically invoke
// its callback with some data
fetchCurrentUser.mockImplementation(cb => {
fetchCurrentUser.mockImplementation(cb => {
cb({
fullName: 'Johnny Cash',
loggedIn: true,
Expand Down
4 changes: 2 additions & 2 deletions examples/jquery/__tests__/fetchCurrentUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ it('calls the callback when $.ajax requests are finished', () => {

// Now we emulate the process by which `$.ajax` would execute its own
// callback
$.ajax.mock.calls[0/*first call*/][0/*first argument*/].success({
$.ajax.mock.calls[0 /*first call*/][0 /*first argument*/].success({
firstName: 'Bobby',
lastName: '");DROP TABLE Users;--',
});

// And finally we assert that this emulated call by `$.ajax` incurred a
// call back into the mock function we provided as a callback
expect(callback.mock.calls[0/*first call*/][0/*first arg*/]).toEqual({
expect(callback.mock.calls[0 /*first call*/][0 /*first arg*/]).toEqual({
fullName: 'Bobby ");DROP TABLE Users;--',
loggedIn: true,
});
Expand Down
22 changes: 9 additions & 13 deletions examples/react-native/Intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
'use strict';

import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import {StyleSheet, Text, View} from 'react-native';

const styles = StyleSheet.create({
container: {
Expand All @@ -34,14 +30,14 @@ const styles = StyleSheet.create({
export default class Intro extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}
41 changes: 17 additions & 24 deletions examples/react-native/__tests__/Intro-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,33 @@ import Intro from '../Intro';
import renderer from 'react-test-renderer';

it('renders correctly', () => {
const tree = renderer.create(
<Intro />
).toJSON();
const tree = renderer.create(<Intro />).toJSON();
expect(tree).toMatchSnapshot();
});

// These serve as integration tests for the jest-react-native preset.
it('renders the ActivityIndicator component', () => {
const ActivityIndicator = require('ActivityIndicator');
const tree = renderer.create(
<ActivityIndicator animating={true} size="small" />
).toJSON();
const tree = renderer
.create(<ActivityIndicator animating={true} size="small" />)
.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders the Image component', done => {
const Image = require('Image');
Image.getSize('path.jpg', (width, height) => {
const tree = renderer.create(
<Image style={{height, width}} />
).toJSON();
const tree = renderer.create(<Image style={{height, width}} />).toJSON();
expect(tree).toMatchSnapshot();
done();
});
});

it('renders the TextInput component', () => {
const TextInput = require('TextInput');
const tree = renderer.create(
<TextInput
autoCorrect={false}
value="apple banana kiwi"
/>
).toJSON();
const tree = renderer
.create(<TextInput autoCorrect={false} value="apple banana kiwi" />)
.toJSON();
expect(tree).toMatchSnapshot();
});

Expand All @@ -53,14 +46,14 @@ it('renders the ListView component', () => {
const Text = require('Text');
const dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
}).cloneWithRows([
'apple', 'banana', 'kiwi',
]);
const tree = renderer.create(
<ListView
dataSource={dataSource}
renderRow={rowData => <Text>{rowData}</Text>}
/>
).toJSON();
}).cloneWithRows(['apple', 'banana', 'kiwi']);
const tree = renderer
.create(
<ListView
dataSource={dataSource}
renderRow={rowData => <Text>{rowData}</Text>}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
1 change: 0 additions & 1 deletion examples/react/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React from 'react';

export default class CheckboxWithLabel extends React.Component {

constructor(props) {
super(props);
this.state = {isChecked: false};
Expand Down
6 changes: 1 addition & 5 deletions examples/snapshot/Clock.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import React from 'react';

export default class Clock extends React.Component {

constructor() {
super();

this.state = {seconds: Date.now() / 1000};
}

componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
this.timerID = setInterval(() => this.tick(), 1000);
}

componentWillUnmount() {
Expand Down
5 changes: 2 additions & 3 deletions examples/snapshot/Link.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const STATUS = {
};

export default class Link extends React.Component {

constructor() {
super();

Expand All @@ -34,10 +33,10 @@ export default class Link extends React.Component {
className={this.state.class}
href={this.props.page || '#'}
onMouseEnter={this._onMouseEnter}
onMouseLeave={this._onMouseLeave}>
onMouseLeave={this._onMouseLeave}
>
{this.props.children}
</a>
);
}

}
4 changes: 1 addition & 3 deletions examples/snapshot/__tests__/Clock.react-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jest.useFakeTimers();
Date.now = jest.fn(() => 1482363367071);

it('renders correctly', () => {
const tree = renderer.create(
<Clock />
).toJSON();
const tree = renderer.create(<Clock />).toJSON();
expect(tree).toMatchSnapshot();
});
16 changes: 7 additions & 9 deletions examples/snapshot/__tests__/Link.react-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ import Link from '../Link.react';
import renderer from 'react-test-renderer';

it('renders correctly', () => {
const tree = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
).toJSON();
const tree = renderer
.create(<Link page="http://www.facebook.com">Facebook</Link>)
.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders as an anchor when no page is set', () => {
const tree = renderer.create(
<Link>Facebook</Link>
).toJSON();
const tree = renderer.create(<Link>Facebook</Link>).toJSON();
expect(tree).toMatchSnapshot();
});

it('properly escapes quotes', () => {
const tree = renderer.create(
<Link>{'"Facebook" \\\'is \\ \'awesome\''}</Link>
).toJSON();
const tree = renderer
.create(<Link>{"\"Facebook\" \\'is \\ 'awesome'"}</Link>)
.toJSON();
expect(tree).toMatchSnapshot();
});

Expand Down
1 change: 0 additions & 1 deletion examples/timer/__tests__/timerGame-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ describe('timerGame', () => {
expect(callback).toBeCalled();
expect(callback.mock.calls.length).toBe(1);
});

});
1 change: 0 additions & 1 deletion examples/timer/infiniteTimerGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function infiniteTimerGame(callback) {
setTimeout(() => {
infiniteTimerGame(callback);
}, 10000);

}, 1000);
}

Expand Down
7 changes: 1 addition & 6 deletions examples/typescript/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ const tsConfig = require('./tsconfig.json');
module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return tsc.transpile(
src,
tsConfig.compilerOptions,
path,
[]
);
return tsc.transpile(src, tsConfig.compilerOptions, path, []);
}
return src;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

throw new Error(
`this error should not be a problem because` +
`this file is never required or executed`
`this file is never required or executed`
);

// Flow annotations to make sure istanbul can instrument non ES6 source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ describe('promise beforeAll', () => {
});
});

beforeAll(
() => {
return new Promise(resolve => setTimeout(resolve, 10));
},
500
);
beforeAll(() => {
return new Promise(resolve => setTimeout(resolve, 10));
}, 500);

// passing tests
it('runs tests after beforeAll asynchronously completes', () => {
Expand All @@ -31,12 +28,9 @@ describe('promise beforeAll', () => {

describe('with failing timeout', () => {
// failing before hook
beforeAll(
() => {
return new Promise(resolve => setTimeout(resolve, 100));
},
10
);
beforeAll(() => {
return new Promise(resolve => setTimeout(resolve, 100));
}, 10);

it('fails', () => {});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lerna": "2.0.0-beta.38",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"prettier": "1.2.0",
"prettier": "1.2.2",
"progress": "^1.1.8",
"react": "15.4.2",
"react-addons-test-utils": "15.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CustomConsole extends Console {

constructor(
stdout: stream$Writable,
stderr: stream$Writable,
stderr: stream$Writable,
formatBuffer: ?Formatter,
) {
super(stdout, stderr);
Expand Down
Loading

0 comments on commit 8c2a651

Please sign in to comment.