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

Use jest for unittesting - standardize unit testing epic #904

Merged
merged 60 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9986d94
chore(tests): migrate to Jest
aaronmcadam Apr 3, 2017
cde14c7
fix(addon-knobs): remove mocha type defs
aaronmcadam Apr 3, 2017
146f5a8
refactor(react-storybook): use Jest matchers instead of chai
aaronmcadam Apr 9, 2017
30c9ba8
refactor(storybook-ui): use Jest matchers in index tests
aaronmcadam Apr 9, 2017
e53965c
refactor(storybook-ui): use Jest matchers in API tests
aaronmcadam Apr 9, 2017
a2a1817
remove storyshots "test"
aaronmcadam Apr 10, 2017
27a8c68
fix(package.json): move Jest config to .jestrc
aaronmcadam Apr 10, 2017
cc9f29b
fix: remove all Yarn lock files
aaronmcadam Apr 10, 2017
7a1c030
let NPM resolve the path to the snapshot serializer
aaronmcadam Apr 10, 2017
fb65019
fix(storybook-ui): use Jest mocks in ui test
aaronmcadam Apr 10, 2017
3178d70
fix(storybook-ui): use Jest matchers, leave Sinon mocks
aaronmcadam Apr 10, 2017
bea3ce0
fix(storybook-ui): use Jest mocks in gen_podda_loader
aaronmcadam Apr 10, 2017
ac57c94
fix(storybook-ui): use Jest matchers in filters
aaronmcadam Apr 10, 2017
5ff3b08
fix(storybook-ui): use Jest matchers in shortcuts
aaronmcadam Apr 10, 2017
f5c2978
fix(storybook-ui): use Jest mocks in handle_keyevents
aaronmcadam Apr 10, 2017
41badd3
fix(storybook-ui): use Jest mocks in init_panels
aaronmcadam Apr 10, 2017
6ec6bc5
fix(storybook-ui): use Jest matchers in down_panel
aaronmcadam Apr 10, 2017
56aeb49
fix(storybook-ui): use Jest matchers in shortcuts_help
aaronmcadam Apr 10, 2017
94c9035
update handle_keyevents
aaronmcadam Apr 10, 2017
c0d4c54
fix(storybook-ui): use Jest matchers in left_panel
aaronmcadam Apr 10, 2017
ab26aed
fix(storybook-ui): use Jest matchers and mocks in handle_routing
aaronmcadam Apr 10, 2017
226cba2
fix(storybook-ui): use Jest mocks and enzyme matchers
aaronmcadam Apr 10, 2017
9f6d1e7
fix(storybook-ui): use Jest matchers in layout
aaronmcadam Apr 10, 2017
751de4c
fix(storybook-ui): use Jest mocks and enzyme matchers in left_panel
aaronmcadam Apr 10, 2017
86680cb
fix(storybook-ui): use Jest mocks in left_panel header
aaronmcadam Apr 10, 2017
7fdaf84
fix(storybook-ui): use jest matchers in layout index
aaronmcadam Apr 10, 2017
52a1052
fix(storybook-ui): use Jest matchers in stories
aaronmcadam Apr 10, 2017
26b96ab
fix(storybook-ui): use Jest and enzyme matchers in text_filter
aaronmcadam Apr 10, 2017
e2ff8c3
Merge branch 'master' into am-jest-migration
ndelangen Apr 14, 2017
95d696e
CHANGE packages/channel to jest
ndelangen Apr 14, 2017
a738b0c
FIX unit-test for addon-comments & CHANGE to jest
ndelangen Apr 14, 2017
8a5d499
REMOVE unneeded eslint-exceptions
ndelangen Apr 14, 2017
da4ed3b
REMOVE bullshit test
ndelangen Apr 14, 2017
90f464d
CHANGE addon-knobs to jest
ndelangen Apr 14, 2017
81286fc
CLEANUP testscripts
ndelangen Apr 14, 2017
631c38f
MOVE test
ndelangen Apr 14, 2017
730feb7
Merge branch 'master' into am-jest-migration
ndelangen Apr 15, 2017
2afa604
UPDATE almost everything
ndelangen Apr 16, 2017
3556c9b
CHANGE all versions of internal packages to `*`
ndelangen Apr 16, 2017
6c6f5d4
REMOVE npm test script where not needed
ndelangen Apr 16, 2017
3a84022
FIX test with jest
ndelangen Apr 16, 2017
fdab656
CHANGE lerna install to hoist by default (faster installs)
ndelangen Apr 16, 2017
1151cba
REMOVE unneeded module && blacklist folder from jest test-detection
ndelangen Apr 16, 2017
d34d718
CHANGE travis config to run test sections in parallel (hopefully)
ndelangen Apr 16, 2017
5c042e5
ADD testing for examples
ndelangen Apr 16, 2017
a803c85
FIX test
ndelangen Apr 16, 2017
9e53b87
MOVE examples out of packages
ndelangen Apr 16, 2017
f74c2a5
MOVE tests next to code && ADD .bettercodehub.yml
ndelangen Apr 16, 2017
57a43b5
Merge branch 'master' into jest-updated
ndelangen Apr 16, 2017
78e9e77
ADD coverage reporting
ndelangen Apr 16, 2017
524e6a9
Merge branch 'jest-updated' of github.com:storybooks/react-storybook …
ndelangen Apr 16, 2017
52ae939
FIX travis.yml
ndelangen Apr 16, 2017
481c4a5
CHANGE package.json ordering of properties
ndelangen Apr 16, 2017
1cbf37b
CHANGE to use yerna over lerna
ndelangen Apr 16, 2017
b4cbbbd
CHANGE code coverage to blacklist generators code
ndelangen Apr 16, 2017
50c61f1
MOVE documentation site outside packages
ndelangen Apr 16, 2017
a2c7a4a
FIX wrong yerna package
ndelangen Apr 16, 2017
783f342
Revert "FIX wrong yerna package"
ndelangen Apr 16, 2017
f87d377
Revert "CHANGE to use yerna over lerna"
ndelangen Apr 16, 2017
bfd9d26
Merge branch 'master' into jest-updated
ndelangen Apr 16, 2017
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
14 changes: 14 additions & 0 deletions .bettercodehub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
component_depth: 2
languages:
- javascript

- name: javascript
production:
exclude:
- .*\.test\.js
- .*\/__test__\/.*\.js
- .*\/__mock__\/.*\.js
test:
include:
- .*\.test\.js
- .*\/__test__\/.*\.js
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ npm-shrinkwrap.json
dist
.tern-port
*.DS_Store
.jest
junit.xml
coverage/
*.lerna_backup
build
packages/examples/automated-*
Expand Down
19 changes: 19 additions & 0 deletions .jestrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cacheDirectory": ".jest",
"clearMocks": true,
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.js"
},
"roots": ["packages"],
"collectCoverage": false,
"collectCoverageFrom": [
"packages/**/*.{js,jsx}"
],
"coverageDirectory": "coverage",
"testEnvironment": "jsdom",
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ cache:
yarn: true
directories:
- node_modules
- .jest
notifications:
email: false
node_js:
- "node"
before_install: ./scripts/travis/before_install.sh
after_success: ./scripts/travis/after_success.sh
script: npm run lint && npm run test
script:
- "npm run lint"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- "npm run test"
- "npm run coverage"
- "npm run test-examples"
git:
depth: 1
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'file-stub';
1 change: 1 addition & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ import ReactDOM from 'react-dom';
import App from './App';
import './index.css';

ReactDOM.render(
<App />,
document.getElementById('root')
);
ReactDOM.render(<App />, document.getElementById('root'));
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const buttonStyles = {
};

const Button = ({ children, onClick }) => (
<button
style={buttonStyles}
onClick={onClick}
>
<button style={buttonStyles} onClick={onClick}>
{children}
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const styles = {
code: {
fontSize: 15,
fontWeight: 600,
padding: "2px 5px",
border: "1px solid #eae9e9",
padding: '2px 5px',
border: '1px solid #eae9e9',
borderRadius: 4,
backgroundColor: '#f3f2f2',
color: '#3a3a3a',
Expand All @@ -33,7 +33,7 @@ const styles = {
backgroundColor: '#f3f2f2',
padding: '1px 10px',
margin: '10px 0',
}
},
};

const codeBlock = `
Expand All @@ -51,7 +51,7 @@ storiesOf('App', module)
export default class Welcome extends React.Component {
showApp(e) {
e.preventDefault();
if(this.props.showApp) this.props.showApp();
if (this.props.showApp) this.props.showApp();
}

render() {
Expand All @@ -62,27 +62,48 @@ export default class Welcome extends React.Component {
This is a UI component dev environment for your app.
</p>
<p>
We've added some basic stories inside the <code style={styles.code}>src/stories</code> directory.
<br/>
We've added some basic stories inside the
{' '}
<code style={styles.code}>src/stories</code>
{' '}
directory.
<br />
A story is a single state of one or more UI components. You can have as many stories as you want.
<br/>
<br />
(Basically a story is like a visual test case.)
</p>
<p>
See these sample <a style={styles.link} href='#' onClick={this.showApp.bind(this)}>stories</a> for a component called <code style={styles.code}>Button</code>.
See these sample
{' '}
<a style={styles.link} href="#" onClick={this.showApp.bind(this)}>stories</a>
{' '}
for a component called
{' '}
<code style={styles.code}>Button</code>
.
</p>
<p>
Just like that, you can add your own components as stories.
<br />
Here's how to add your <code style={styles.code}>App</code> component as a story.
<div
style={styles.codeBlock}
dangerouslySetInnerHTML={{__html: `<pre>${codeBlock}</pre>`}}
dangerouslySetInnerHTML={{ __html: `<pre>${codeBlock}</pre>` }}
/>
</p>
<p>
Usually we create stories with smaller UI components in the app.<br />
Have a look at the <a style={styles.link} href="https://getstorybook.io/docs/basics/writing-stories" target="_blank">Writing Stories</a> section in our documentation.
Have a look at the
{' '}
<a
style={styles.link}
href="https://getstorybook.io/docs/basics/writing-stories"
target="_blank"
>
Writing Stories
</a>
{' '}
section in our documentation.
</p>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions examples/cra-storybook/src/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { storiesOf, action, linkTo } from '@kadira/storybook';
import Button from './Button';
import Welcome from './Welcome';

storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);

storiesOf('Button', module)
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)
.add('with some emoji', () => <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>);
1 change: 0 additions & 1 deletion packages/examples/package.json → examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "A set of examples of how to use storybook, also used for regression testing",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"test:automated-cra-storybook": "node scripts/automated-cra-storybook.js"
},
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "3.0.0",
"packages": [
"packages/*",
"packages/examples/*"
"examples/*"
]
}
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
"name": "storybook",
"devDependencies": {
"babel-eslint": "^7.2.2",
"codecov": "^2.1.0",
"enzyme": "^2.8.2",
"enzyme-to-json": "^1.5.1",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jest": "^19.0.1",
"eslint-plugin-prettier": "^2.0.1",
"jest": "^19.0.2",
"jest-enzyme": "^3.0.1",
"lerna": "2.0.0-rc.2",
"prettier": "^1.1.0"
"prettier": "^1.1.0",
"react": "^15.5.4",
"react-addons-test-utils": "^15.5.1",
"react-dom": "^15.5.4"
},
"scripts": {
"postinstall": "lerna bootstrap",
"test": "lerna run test",
"lint": "eslint ."
"postinstall": "lerna bootstrap --hoist",
"lint": "eslint .",
"test": "jest --config ./.jestrc",
"test:watch": "npm test -- --watch",
"test-examples": "CI=true lerna run test",
"coverage": "codecov"
}
}
11 changes: 5 additions & 6 deletions packages/addon-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"scripts": {
"deploy-storybook": "storybook-to-ghpages",
"prepublish": "node .scripts/npm-prepublish.js",
"storybook": "start-storybook -p 9001",
"test": "echo \"Error: no test specified\" && exit 0"
"storybook": "start-storybook -p 9001"
},
"repository": {
"type": "git",
Expand All @@ -22,9 +21,9 @@
},
"homepage": "https://github.com/kadirahq/storybook-addon-actions#readme",
"devDependencies": {
"@kadira/storybook": "^2.20.1",
"@kadira/storybook-addons": "^1.3.0",
"@kadira/storybook-ui": "^3.0.0",
"@kadira/storybook": "*",
"@kadira/storybook-addons": "*",
"@kadira/storybook-ui": "*",
"babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
Expand All @@ -41,7 +40,7 @@
"react-inspector": "^1.1.0"
},
"peerDependencies": {
"@kadira/storybook-addons": "^1.3.0",
"@kadira/storybook-addons": "*",
"react": "*",
"react-dom": "*"
}
Expand Down
19 changes: 6 additions & 13 deletions packages/addon-comments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "preview.js",
"scripts": {
"prepublish": ". ./.scripts/prepublish.sh",
"test": "mocha --require .scripts/mocha_runner src/**/tests/**/*.js",
"storybook": "start-storybook -p 3006",
"storybook-local": "STORYBOOK_CLOUD_SERVER='http://localhost:3003/graphql' start-storybook -p 9010",
"storybook-remote": "start-storybook -p 3006",
Expand Down Expand Up @@ -36,22 +35,16 @@
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"mocha": "^3.0.2",
"chai": "^3.5.0",
"sinon": "^1.17.6",
"enzyme": "^2.2.0",
"jsdom": "^9.5.0",
"git-url-parse": "^6.0.1",
"@kadira/storybook": "^2.24.1",
"@kadira/storybook-addons": "^1.5.0",
"@kadira/storybook-database-cloud": "^2.3.1",
"@kadira/storybook-deployer": "^1.2.0",
"@kadira/storybook-ui": "^3.4.1",
"chokidar": "^1.6.0",
"@kadira/storybook": "*",
"@kadira/storybook-addons": "*",
"@kadira/storybook-database-cloud": "*",
"@kadira/storybook-deployer": "*",
"@kadira/storybook-ui": "*",
"shelljs": "^0.7.4"
},
"peerDependencies": {
"@kadira/storybook-addons": "^1.5.0",
"@kadira/storybook-addons": "*",
"react": "*",
"react-dom": "*"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import PropTypes from 'prop-types';
/* eslint jsx-a11y/href-no-hash:0, no-undef:0, no-alert:0 */

import React, { Component } from 'react';
import moment from 'moment';
import renderHTML from 'react-render-html';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import PropTypes from 'prop-types';
/* eslint no-undef: 0 */

import React, { Component } from 'react';
import CommentList from '../CommentList';
import CommentForm from '../CommentForm';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint no-param-reassign:0 */

import deepEquals from 'deep-equal';
import { EventEmitter } from 'events';

Expand Down Expand Up @@ -27,7 +25,12 @@ export default class DataStore {
const key = this._getStoryKey(currentStory);
const item = this.cache[key];

if (!item) return null;
if (!item) {
return {
comments: [],
invalidated: false,
};
}

const comments = item.comments;
let invalidated = false;
Expand Down Expand Up @@ -67,9 +70,9 @@ export default class DataStore {
this._fireComments(item.comments);
// if the cache invalidated we need to load comments again.
if (item.invalidated) {
this._loadUsers().then(() => this._loadComments());
return this._loadUsers().then(() => this._loadComments());
}
return;
return Promise.resolve(null);
}

// load comments for the first time.
Expand Down Expand Up @@ -117,7 +120,6 @@ export default class DataStore {
// add to cache
this._addToCache(currentStory, comments);

/* eslint no-param-reassign:0 */
// set comments only if we are on the relavant story
if (deepEquals(currentStory, this.currentStory)) {
this._fireComments(comments);
Expand Down Expand Up @@ -202,15 +204,15 @@ export default class DataStore {
}

addComment(comment) {
this._addAuthorToTheDatabase()
return this._addAuthorToTheDatabase()
.then(() => this._addPendingComment(comment))
.then(() => this._addCommentToDatabase(comment))
.then(() => this._loadUsers())
.then(() => this._loadComments());
}

deleteComment(commentId) {
this._setDeletedComment(commentId)
return this._setDeletedComment(commentId)
.then(() => this._deleteCommentOnDatabase(commentId))
.then(() => this._loadComments());
}
Expand Down
Loading