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

Flow upgrade #4355

Merged
merged 5 commits into from
Aug 27, 2017
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
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ module.name_mapper='^types/\(.*\)$' -> '<PROJECT_ROOT>/types/\1.js'
module.name_mapper='\(jest-[^/]*\)' -> '<PROJECT_ROOT>/packages/\1/src/index.js'

[version]
^0.50.0
^0.53.1
2 changes: 1 addition & 1 deletion examples/react-native/Intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const styles = StyleSheet.create({
},
});

export default class Intro extends Component {
export default class Intro extends Component<{}> {
render() {
return (
<View style={styles.container}>
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Intro from './Intro';
import React, {AppRegistry} from 'react-native';
import {Component} from 'react';

class App extends Component {
class App extends Component<{}> {
render() {
return <Intro />;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Intro from './Intro';
import React, {Component} from 'react';
import {AppRegistry} from 'react-native';

class App extends Component {
class App extends Component<{}> {
render() {
return <Intro />;
}
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 @@
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-relay": "0.0.8",
"eslint-plugin-unicorn": "^2.1.2",
"flow-bin": "^0.50.0",
"flow-bin": "^0.53.1",
"glob": "^7.1.1",
"graceful-fs": "^4.1.11",
"immutable": "^4.0.0-rc.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-repl/src/cli/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const evalCommand = (cmd, context, filename, callback, config) => {
}
result = vm.runInThisContext(cmd);
} catch (e) {
// $FlowFixMe: https://github.com/facebook/flow/pull/4713
return callback(isRecoverableError(e) ? new repl.Recoverable(e) : e);
}
return callback(null, result);
Expand Down Expand Up @@ -76,6 +77,7 @@ const replInstance = repl.start({
useGlobal: true,
});

// $FlowFixMe: https://github.com/facebook/flow/pull/4713
replInstance.context.require = moduleName => {
if (/(\/|\\|\.)/.test(moduleName)) {
moduleName = path.resolve(process.cwd(), moduleName);
Expand Down
14 changes: 13 additions & 1 deletion packages/pretty-format/src/__tests__/immutable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import React from 'react';
import * as React from 'react';
import Immutable from 'immutable';
import prettyFormat from '../';
const {Immutable: ImmutablePlugin, ReactElement} = prettyFormat.plugins;
Expand Down Expand Up @@ -98,6 +98,7 @@ describe('Immutable.OrderedSet', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.OrderedSet([reactElement, reactElement]),
Expand All @@ -107,6 +108,7 @@ describe('Immutable.OrderedSet', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.OrderedSet([reactElement, reactElement]),
Expand Down Expand Up @@ -181,6 +183,7 @@ describe('Immutable.List', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.List([reactElement, reactElement]),
Expand All @@ -191,6 +194,7 @@ describe('Immutable.List', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(Immutable.List([reactElement, reactElement])).toPrettyPrintTo(
'Immutable.List [\n <Mouse>\n Hello World\n </Mouse>,\n <Mouse>\n Hello World\n </Mouse>,\n]',
Expand Down Expand Up @@ -264,6 +268,7 @@ describe('Immutable.Stack', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.Stack([reactElement, reactElement]),
Expand All @@ -274,6 +279,7 @@ describe('Immutable.Stack', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(Immutable.Stack([reactElement, reactElement])).toPrettyPrintTo(
'Immutable.Stack [\n <Mouse>\n Hello World\n </Mouse>,\n <Mouse>\n Hello World\n </Mouse>,\n]',
Expand Down Expand Up @@ -343,6 +349,7 @@ describe('Immutable.Set', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.Set([reactElement, reactElement]),
Expand All @@ -352,6 +359,7 @@ describe('Immutable.Set', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(Immutable.Set([reactElement, reactElement])).toPrettyPrintTo(
'Immutable.Set [\n <Mouse>\n Hello World\n </Mouse>,\n]',
Expand Down Expand Up @@ -403,6 +411,7 @@ describe('Immutable.Map', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.Map({a: reactElement, b: reactElement}),
Expand All @@ -413,6 +422,7 @@ describe('Immutable.Map', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(Immutable.Map({a: reactElement, b: reactElement})).toPrettyPrintTo(
'Immutable.Map {\n "a": <Mouse>\n Hello World\n </Mouse>,\n "b": <Mouse>\n Hello World\n </Mouse>,\n}',
Expand Down Expand Up @@ -471,6 +481,7 @@ describe('Immutable.OrderedMap', () => {
});

it('supports React elements {min: true}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.OrderedMap({a: reactElement, b: reactElement}),
Expand All @@ -481,6 +492,7 @@ describe('Immutable.OrderedMap', () => {
});

it('supports React elements {min: false}', () => {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
const reactElement = React.createElement('Mouse', null, 'Hello World');
expect(
Immutable.OrderedMap({a: reactElement, b: reactElement}),
Expand Down
32 changes: 26 additions & 6 deletions packages/pretty-format/src/__tests__/react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {OptionsReceived} from 'types/PrettyFormat';
const React = require('react');
const renderer = require('react-test-renderer');

const elementSymbol = Symbol.for('react.element');
const testSymbol = Symbol.for('react.test.json');

const prettyFormat = require('../');
Expand Down Expand Up @@ -57,34 +58,39 @@ test('supports a single element with no props or children', () => {

test('supports a single element with non-empty string child', () => {
assertPrintedJSX(
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('Mouse', null, 'Hello World'),
'<Mouse>\n Hello World\n</Mouse>',
);
});

test('supports a single element with empty string child', () => {
assertPrintedJSX(
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('Mouse', null, ''),
'<Mouse>\n \n</Mouse>',
);
});

test('supports a single element with non-zero number child', () => {
assertPrintedJSX(
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('Mouse', null, 4),
'<Mouse>\n 4\n</Mouse>',
);
});

test('supports a single element with zero number child', () => {
assertPrintedJSX(
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('Mouse', null, 0),
'<Mouse>\n 0\n</Mouse>',
);
});

test('supports a single element with mixed children', () => {
assertPrintedJSX(
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('Mouse', null, [[1, null], 2, undefined, [false, [3]]]),
'<Mouse>\n 1\n 2\n 3\n</Mouse>',
);
Expand All @@ -100,6 +106,7 @@ test('supports props with strings', () => {
test('supports props with multiline strings', () => {
const val = React.createElement(
'svg',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
React.createElement('polyline', {
id: 'J',
Expand Down Expand Up @@ -168,6 +175,7 @@ test('escapes children properly', () => {
assertPrintedJSX(
React.createElement(
'Mouse',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
'"-"',
React.createElement('Mouse'),
Expand Down Expand Up @@ -294,19 +302,16 @@ test('supports a single element with custom React elements with a child', () =>
);
});

test('supports Unknown element', () => {
// Suppress React.createElement(undefined) console error
const consoleError = console.error;
(console: Object).error = jest.fn();
expect(formatElement(React.createElement(undefined))).toEqual(
test('supports undefined element type', () => {
expect(formatElement({$$typeof: elementSymbol, props: {}})).toEqual(
'<UNDEFINED />',
);
(console: Object).error = consoleError;
});

test('supports a single element with React elements with a child', () => {
assertPrintedJSX(
React.createElement('Mouse', {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
prop: React.createElement('div', null, 'mouse'),
}),
'<Mouse\n prop={\n <div>\n mouse\n </div>\n }\n/>',
Expand All @@ -318,8 +323,10 @@ test('supports a single element with React elements with children', () => {
React.createElement('Mouse', {
prop: React.createElement(
'div',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
'mouse',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('span', null, 'rat'),
),
}),
Expand All @@ -330,6 +337,7 @@ test('supports a single element with React elements with children', () => {
test('supports a single element with React elements with array children', () => {
assertPrintedJSX(
React.createElement('Mouse', {
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
prop: React.createElement('div', null, 'mouse', [
React.createElement('span', {key: 1}, 'rat'),
React.createElement('span', {key: 2}, 'cat'),
Expand All @@ -341,7 +349,9 @@ test('supports a single element with React elements with array children', () =>

test('supports array of elements', () => {
const val = [
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('dt', null, 'jest'),
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('dd', null, 'to talk in a playful manner'),
React.createElement(
'dd',
Expand Down Expand Up @@ -402,6 +412,7 @@ describe('test object for subset match', () => {
describe('indent option', () => {
const val = React.createElement(
'ul',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
React.createElement(
'li',
Expand Down Expand Up @@ -451,6 +462,7 @@ describe('maxDepth option', () => {
const val = React.createElement(
// ++depth === 1
'dl',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
React.createElement('dt', {id: 'jest'}, 'jest'), // ++depth === 2
React.createElement(
Expand All @@ -460,6 +472,7 @@ describe('maxDepth option', () => {
id: 'jest-1',
},
'to talk in a ',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('em', null, 'playful'), // ++depth === 3
' manner',
),
Expand All @@ -473,6 +486,7 @@ describe('maxDepth option', () => {
color: '#99424F',
},
},
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('em', null, 'painless'), // ++depth === 3
' JavaScript testing',
),
Expand Down Expand Up @@ -513,6 +527,7 @@ describe('maxDepth option', () => {
id: 'jest-1',
},
'to talk in a ',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('em', null, 'playful'), // ++depth === 3
' manner',
),
Expand All @@ -526,6 +541,7 @@ describe('maxDepth option', () => {
color: '#99424F',
},
},
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('em', null, 'painless'), // ++depth === 3
' JavaScript testing',
),
Expand Down Expand Up @@ -582,8 +598,10 @@ test('ReactElement plugin highlights syntax', () => {
const jsx = React.createElement('Mouse', {
prop: React.createElement(
'div',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
'mouse',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('span', null, 'rat'),
),
});
Expand All @@ -598,8 +616,10 @@ test('ReactTestComponent plugin highlights syntax', () => {
const jsx = React.createElement('Mouse', {
prop: React.createElement(
'div',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
null,
'mouse',
// $FlowFixMe: https://github.com/facebook/flow/issues/4658
React.createElement('span', null, 'rat'),
),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/plugins/react_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const getType = element => {
};

export const serialize = (
element: React$Element<*>,
element: React$Element<any>,
config: Config,
indentation: string,
depth: number,
Expand Down
2 changes: 0 additions & 2 deletions test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => {
`);
}

// $FlowFixMe Object.assign
return Object.assign({}, DEFAULT_GLOBAL_CONFIG, overrides);
};

Expand All @@ -120,7 +119,6 @@ const makeProjectConfig = (overrides: Object = {}): ProjectConfig => {
`);
}

// $FlowFixMe Object.assign
return Object.assign({}, DEFAULT_PROJECT_CONFIG, overrides);
};

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2763,9 +2763,9 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-bin@^0.50.0:
version "0.50.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.50.0.tgz#d4cdb2430dee1a3599f0eb6fe551146e3027256a"
flow-bin@^0.53.1:
version "0.53.1"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.53.1.tgz#9b22b63a23c99763ae533ebbab07f88c88c97d84"

flow-remove-types@^1.1.0:
version "1.2.1"
Expand Down