Skip to content

Commit

Permalink
Merge 97d0c15 into 95aa676
Browse files Browse the repository at this point in the history
  • Loading branch information
xunuoi committed Dec 18, 2018
2 parents 95aa676 + 97d0c15 commit 84b15ac
Show file tree
Hide file tree
Showing 14 changed files with 6,974 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[ignore]
.*/.flow-typed/.*
.*/bin/.*
.*/node_modules/jest-enzyme/.*
.*/node_modules/enzyme-matchers/.*
.*/__test__/bad-type/.*

[include]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
node_modules
flow-typed
dist
.DS_Store
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- node
- 8
- 6
- node
- 8
after_script: 'cat ./coverage/lcov.info | coveralls'
14 changes: 14 additions & 0 deletions __test__/bad-type/bad-props-stateless-component.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow strict
/* eslint-disable */
import * as React from 'react';
import { translate, type I18nType } from '../../src';
import mockI18n from '../../src/mockI18n';


// Case 1: React stateless component
const StatelessCom = ({ name, i18n }: { name: string, i18n: I18nType }) => (
<div>{i18n.gettext('S')}</div>
);
const TStatelessCom = translate(StatelessCom);
// Should throw error for missing required prop content
result = <TStatelessCom />;
32 changes: 32 additions & 0 deletions __test__/bad-type/bad-props.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @flow strict
/* eslint-disable */
import * as React from 'react';
import { translate, type I18nType } from '../../src';
import mockI18n from '../../src/mockI18n';

// Case 1: throw error for missing props
class ComponentB extends React.PureComponent<{
i18n: I18nType,
content: string,
children: React.Node,
}> {
componentDidMount() {
console.log('hey');
}

render() {
const { i18n, content, children } = this.props;

return (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);
}
}

const TComponentB = translate(ComponentB);
// Should throw error for missing required prop content
const result = <TComponentB >bar</TComponentB>;
40 changes: 40 additions & 0 deletions __test__/bad-type/bad-static-props.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @flow strict
/* eslint-disable */
import * as React from 'react';
import { translate, type I18nType } from '../../src';
import mockI18n from '../../src/mockI18n';

//Case 1: class component with static
class ComponentC extends React.Component<{
i18n: I18nType,
content: string,
children: React.Node,
}> {
static method(str: string) {
console.log('hey', str);
}

componentDidMount() {
console.log('hey');
}

render() {
const { i18n, content, children } = this.props;

return (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);
}
}

const TComponentC = translate(ComponentC);
const result = <TComponentC content="foo">bar</TComponentC>;

ComponentC.method('foo');

// Should throw Error
TComponentC.WrappedComponent.notExistMethod('foo');
127 changes: 127 additions & 0 deletions __test__/good-type.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// @flow strict
/* eslint-disable */
import * as React from 'react';
import { translate, type I18nType } from '../src';
import mockI18n from '../src/mockI18n';

let result;

// Case 1: functional component
const ComponentA = ({
i18n,
content,
children,
}: {
i18n: I18nType,
content: string,
children: React.Node,
}) => (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);

const TComponentA = translate(ComponentA);
result = <TComponentA content="foo">bar</TComponentA>;
result = (
<TComponentA.WrappedComponent content="foo" i18n={mockI18n}>
bar
</TComponentA.WrappedComponent>
);

// Case 2: simple class component
class ComponentB extends React.PureComponent<{
i18n: I18nType,
content: string,
children: React.Node,
}> {
componentDidMount() {
console.log('hey');
}

render() {
const { i18n, content, children } = this.props;

return (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);
}
}

const TComponentB = translate(ComponentB);
result = <TComponentB content="foo">bar</TComponentB>;

// Case 3: class component with static
class ComponentC extends React.Component<{
i18n: I18nType,
content: string,
children: React.Node,
}> {
static method(str: string) {
console.log('hey', str);
}

componentDidMount() {
console.log('hey');
}

render() {
const { i18n, content, children } = this.props;

return (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);
}
}

const TComponentC = translate(ComponentC);
result = <TComponentC content="foo">bar</TComponentC>;

ComponentC.method('foo');
TComponentC.WrappedComponent.method('foo');
// `name` is build-in string prop
const TComponentName = TComponentC.name;
const TComponentDisplayName = TComponentC.displayName;

// Case 4: class component with defaultProps
class ComponentD extends React.Component<{
i18n: I18nType,
content: string,
children: React.Node,
}> {
static defaultProps = {
content: 'foo',
};

componentDidMount() {
console.log('hey');
}

render() {
const { i18n, content, children } = this.props;

return (
<div>
{i18n.gettext('hey')}
{content}
{children}
</div>
);
}
}

// Case 4: React stateless component
const StatelessCom = ({name, i18n}: {name: string, i18n: I18nType}) => <div>{i18n.gettext('S')}</div>
const TStatelessCom = translate(StatelessCom);

result = <TStatelessCom name="Kate" />;
2 changes: 1 addition & 1 deletion __test__/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
// @flow strict
import React from 'react';
import { mount } from 'enzyme';
import { Jed, translate, I18nProvider, type I18nType } from '../src';
Expand Down
1 change: 0 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
import 'raf/polyfill';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Expand Down
29 changes: 11 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"localization"
],
"dependencies": {
"hoist-non-react-statics": "^3.1.0",
"jed": "^1.1.1",
"react": "^16.6.3"
},
Expand All @@ -40,7 +39,7 @@
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.3.0",
"flow-bin": "^0.86.0",
"flow-bin": "^0.84.0",
"flow-copy-source": "^2.0.2",
"flow-typed": "^2.4.0",
"husky": "^1.2.0",
Expand All @@ -49,16 +48,16 @@
"jest-serializer-enzyme": "^1.0.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.2",
"raf": "^3.4.1",
"react-addons-test-utils": "^15.6.2",
"react-dom": "^16.6.3"
},
"scripts": {
"test": "jest --coverage",
"badtest": "node test.flow.js",
"build": "babel src/ -d dist/ && flow-copy-source -v src/ dist/",
"prepublish": "npm run build",
"publish": "npm run build",
"pretest": "flow-typed install && flow && eslint ."
"pretest": "flow-typed install --overwrite && flow && npm run badtest && eslint ."
},
"lint-staged": {
"*.js": [
Expand Down
Loading

0 comments on commit 84b15ac

Please sign in to comment.