Skip to content

Commit 8713349

Browse files
committed
Adds react library configuration.
1 parent 97d94fe commit 8713349

File tree

10 files changed

+416
-20
lines changed

10 files changed

+416
-20
lines changed

.babelrc

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
{
22
"presets": [
33
["env", { "targets": { "node": true } }],
4-
"stage-3"
5-
],
6-
"plugins": [
7-
"syntax-flow",
8-
"transform-flow-strip-types"
4+
"stage-3",
5+
"react"
96
],
107
"env": {
118
"commonjs": {
129
"presets": [
1310
"latest",
14-
"stage-3"
11+
"stage-3",
12+
"react"
1513
],
1614
},
1715
"umd": {
1816
"presets": [
1917
["latest", { "es2015": { "modules": false } }],
20-
"stage-3"
18+
"stage-3",
19+
"react"
2120
],
2221
}
2322
}

package.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,32 @@
3535
"test:coverage": "yarn run test -- --coverage",
3636
"test:coverage:deploy": "yarn run coverage && codecov"
3737
},
38+
"peerDependencies": {
39+
"react": ">=15.0.0"
40+
},
3841
"devDependencies": {
3942
"app-root-dir": "1.0.2",
4043
"babel-cli": "6.18.0",
4144
"babel-core": "6.21.0",
4245
"babel-eslint": "7.1.1",
4346
"babel-jest": "18.0.0",
4447
"babel-loader": "6.2.10",
45-
"babel-plugin-syntax-flow": "6.18.0",
46-
"babel-plugin-transform-flow-strip-types": "6.21.0",
4748
"babel-polyfill": "6.20.0",
4849
"babel-preset-env": "1.1.4",
4950
"babel-preset-latest": "6.16.0",
51+
"babel-preset-react": "^6.16.0",
5052
"babel-preset-stage-3": "6.17.0",
5153
"babel-register": "6.18.0",
5254
"codecov": "1.0.1",
5355
"cross-env": "3.1.3",
56+
"enzyme": "^2.7.0",
57+
"enzyme-to-json": "^1.4.5",
5458
"eslint": "3.12.2",
5559
"eslint-config-airbnb": "13.0.0",
5660
"eslint-plugin-flowtype": "2.29.2",
5761
"eslint-plugin-import": "2.2.0",
5862
"eslint-plugin-jsx-a11y": "2.2.3",
63+
"eslint-plugin-react": "^6.8.0",
5964
"flow-bin": "0.37.4",
6065
"flow-coverage-report": "^0.2.0",
6166
"flow-typed": "^2.0.0",
@@ -65,8 +70,12 @@
6570
"jest": "18.1.0",
6671
"pretty-bytes": "4.0.2",
6772
"ramda": "0.23.0",
73+
"react": "^15.4.1",
74+
"react-addons-test-utils": "^15.4.1",
75+
"react-dom": "^15.4.1",
6876
"readline-sync": "1.4.5",
6977
"rimraf": "2.5.4",
78+
"sinon": "^1.17.7",
7079
"webpack": "2.2.0-rc.3",
7180
"webpack-dev-middleware": "1.9.0",
7281
"webpack-hot-middleware": "2.14.0"
@@ -80,6 +89,9 @@
8089
"collectCoverageFrom": [
8190
"src/**/*.{js,jsx}"
8291
],
92+
"snapshotSerializers": [
93+
"<rootDir>/node_modules/enzyme-to-json/serializer"
94+
],
8395
"testPathIgnorePatterns": [
8496
"<rootDir>/(commonjs|coverage|flow-typed|node_modules|tools|umd)/"
8597
]

src/MyComponent.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* @flow */
2+
3+
import React, { PropTypes } from 'react';
4+
5+
// $FlowFixMe - using propTypes
6+
function MyComponent({ msg }) {
7+
return <h1>{msg}</h1>;
8+
}
9+
10+
MyComponent.propTypes = {
11+
msg: PropTypes.string.isRequired,
12+
};
13+
14+
export default MyComponent;

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import helloWorld from './helloWorld';
44
import goodbyeWorld from './goodbyeWorld';
5+
import MyComponent from './MyComponent';
56

67
export {
78
helloWorld,
89
goodbyeWorld,
10+
MyComponent,
911
};

test/.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"rules": {
3-
"import/no-extraneous-dependencies": 0
3+
"import/no-extraneous-dependencies": 0,
4+
"no-console": 0
45
}
56
}

test/MyComponent.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* @flow */
2+
3+
import React from 'react';
4+
import MyComponent from '../src/MyComponent';
5+
import describeComponent from './__helpers__/describeComponent';
6+
7+
describeComponent('MyComponent', () => {
8+
it('renders', () => {
9+
expect(<MyComponent msg="foo" />).toMatchSnapshot();
10+
});
11+
12+
it('propTypes', () => {
13+
expect(() => <MyComponent />).toThrowError('Failed prop type');
14+
});
15+
});

test/__helpers__/describeComponent.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* @flow */
2+
3+
import sinon from 'sinon';
4+
5+
export default function describeComponent(desc : string, body : Function) {
6+
describe(desc, () => {
7+
// Since react will console.error propType warnings, that which we'd rather have
8+
// as errors, we use sinon.js to stub it into throwing these warning as errors
9+
// instead.
10+
beforeAll(() => {
11+
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
12+
});
13+
14+
// While not forgetting to restore it afterwards
15+
afterAll(() => { console.error.restore(); });
16+
17+
body();
18+
});
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exports[`MyComponent renders 1`] = `
2+
<MyComponent
3+
msg="foo" />
4+
`;

tools/webpack/configFactory.js

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ function webpackConfigFactory({ target } : Args) {
2525
library: libraryName,
2626
libraryTarget: 'umd',
2727
},
28+
externals: {
29+
react: {
30+
root: 'React',
31+
umd: 'react',
32+
},
33+
},
2834
plugins: removeEmpty([
2935
new webpack.DefinePlugin({
3036
'process.env.NODE_ENV': JSON.stringify('production'),

0 commit comments

Comments
 (0)