Skip to content

Commit

Permalink
Add Jest tests and Codecov reports (FaridSafi#673)
Browse files Browse the repository at this point in the history
* chore(test): add jest

* chore(coverage): add codecov to circleci

* chore(vscode): remove vscode from git

* chore(test): snapshot all component
  • Loading branch information
xcarpentier authored and cooperka committed Dec 20, 2017
1 parent 5e94773 commit e054648
Show file tree
Hide file tree
Showing 45 changed files with 5,094 additions and 104 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
example/
TODO.md
screenshots/
.babelrc
tests/
15 changes: 0 additions & 15 deletions .vscode/settings.json

This file was deleted.

6 changes: 1 addition & 5 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"ignore_dirs": [
".git",
"node_modules",
"example"
]
"ignore_dirs": [".git", "node_modules", "example"]
}
5 changes: 2 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ dependencies:
test:
override:
- yarn run lint
# TODO: - yarn run flow
# TODO: - yarn run test -- --coverage
# TODO: - codecov
- yarn run test:coverage
- codecov

# TODO: deployment:
# release:
Expand Down
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,31 @@
"homepage": "https://github.com/FaridSafi/react-native-gifted-chat#readme",
"scripts": {
"lint": "eslint . --ext .js,.jsx",
"precommit": "yarn lint"
"precommit": "yarn lint",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"jest": {
"preset": "react-native",
"setupFiles": ["./tests/setup.js"]
},
"devDependencies": {
"babel": "6.23.0",
"babel-jest": "22.0.3",
"babel-preset-react-native": "4.0.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "16.1.0",
"eslint-config-cooperka": "0.2.9",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-react-native": "3.2.0",
"husky": "0.14.3"
"husky": "0.14.3",
"jest": "22.0.3",
"react": "16.2.0",
"react-native": "0.51.0",
"react-test-renderer": "16.2.0"
},
"dependencies": {
"@expo/react-native-action-sheet": "^1.0.1",
Expand All @@ -49,4 +63,4 @@
"shallowequal": "1.0.2",
"uuid": "3.1.0"
}
}
}
11 changes: 11 additions & 0 deletions src/__tests__/Actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Actions } from '../GiftedChat';

it('should render <Actions /> and compare with snapshot', () => {
const tree = renderer.create(<Actions />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/Avatar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Avatar } from '../GiftedChat';

it('should render <Avatar /> and compare with snapshot', () => {
const tree = renderer.create(<Avatar renderAvatar={() => 'renderAvatar'} />).toJSON();

expect(tree).toMatchSnapshot();
});
13 changes: 13 additions & 0 deletions src/__tests__/Bubble.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Bubble } from '../GiftedChat';

it('should render <Bubble /> and compare with snapshot', () => {
const tree = renderer
.create(<Bubble user={{ _id: 1 }} currentMessage={{ user: { _id: 1 } }} />)
.toJSON();

expect(tree).toMatchSnapshot();
});
5 changes: 5 additions & 0 deletions src/__tests__/Color.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Color from '../Color';

it('should compare Color with snapshot', () => {
expect(Color).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/Composer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Composer } from '../GiftedChat';

it('should render <Composer /> and compare with snapshot', () => {
const tree = renderer.create(<Composer />).toJSON();

expect(tree).toMatchSnapshot();
});
5 changes: 5 additions & 0 deletions src/__tests__/Constant.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Constant from '../Constant';

it('should compare Constant with snapshot', () => {
expect(Constant).toMatchSnapshot();
});
12 changes: 12 additions & 0 deletions src/__tests__/Day.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'react-native';
import React from 'react';
import createComponentWithContext from '../../tests/context';

import { Day } from '../GiftedChat';

it('should render <Day /> and compare with snapshot', () => {
const component = createComponentWithContext(<Day />);
const tree = component.toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/GiftedAvatar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { GiftedAvatar } from '../GiftedChat';

it('should render <GiftedAvatar /> and compare with snapshot', () => {
const tree = renderer.create(<GiftedAvatar />).toJSON();

expect(tree).toMatchSnapshot();
});
33 changes: 33 additions & 0 deletions src/__tests__/GiftedChat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { GiftedChat } from '../GiftedChat';

const messages = [
{
_id: 1,
text: 'Hello developer',
createdAt: new Date(),
user: {
_id: 2,
name: 'React Native',
},
},
];

it('should render <GiftedChat/> and compare with snapshot', () => {
const tree = renderer
.create(
<GiftedChat
messages={messages}
onSend={() => {}}
user={{
_id: 1,
}}
/>,
)
.toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/InputToolbar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { InputToolbar } from '../GiftedChat';

it('should render <InputToolbar /> and compare with snapshot', () => {
const tree = renderer.create(<InputToolbar />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/LoadEarlier.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { LoadEarlier } from '../GiftedChat';

it('should render <LoadEarlier /> and compare with snapshot', () => {
const tree = renderer.create(<LoadEarlier />).toJSON();

expect(tree).toMatchSnapshot();
});
13 changes: 13 additions & 0 deletions src/__tests__/Message.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Message } from '../GiftedChat';

it('should render <Message /> and compare with snapshot', () => {
const tree = renderer
.create(<Message user={{ _id: 1 }} currentMessage={{ user: { _id: 1 } }} />)
.toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/MessageContainer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { MessageContainer } from '../GiftedChat';

it('should render <MessageContainer /> and compare with snapshot', () => {
const tree = renderer.create(<MessageContainer />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/MessageImage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { MessageImage } from '../GiftedChat';

it('should render <MessageImage /> and compare with snapshot', () => {
const tree = renderer.create(<MessageImage />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/MessageText.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { MessageText } from '../GiftedChat';

it('should render <MessageText /> and compare with snapshot', () => {
const tree = renderer.create(<MessageText />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/Send.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { Send } from '../GiftedChat';

it('should render <Send /> and compare with snapshot', () => {
const tree = renderer.create(<Send />).toJSON();

expect(tree).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/__tests__/SystemMessage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import { SystemMessage } from '../GiftedChat';

it('should render <SystemMessage /> and compare with snapshot', () => {
const tree = renderer.create(<SystemMessage />).toJSON();

expect(tree).toMatchSnapshot();
});
12 changes: 12 additions & 0 deletions src/__tests__/Time.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'react-native';
import React from 'react';
import createComponentWithContext from '../../tests/context';

import { Time } from '../GiftedChat';

it('should render <Time /> and compare with snapshot', () => {
const component = createComponentWithContext(<Time />);
const tree = component.toJSON();

expect(tree).toMatchSnapshot();
});
67 changes: 67 additions & 0 deletions src/__tests__/__snapshots__/Actions.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render <Actions /> and compare with snapshot 1`] = `
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
collapsable={undefined}
hasTVPreferredFocus={undefined}
hitSlop={undefined}
isTVSelectable={true}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"height": 26,
"marginBottom": 10,
"marginLeft": 10,
"opacity": 1,
"width": 26,
}
}
testID={undefined}
tvParallaxProperties={undefined}
>
<View
style={
Array [
Object {
"borderColor": "#b2b2b2",
"borderRadius": 13,
"borderWidth": 2,
"flex": 1,
},
Object {},
]
}
>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#b2b2b2",
"fontSize": 16,
"fontWeight": "bold",
"textAlign": "center",
},
Object {},
]
}
>
+
</Text>
</View>
</View>
`;
Loading

0 comments on commit e054648

Please sign in to comment.