Skip to content

Commit

Permalink
Merge pull request storybookjs#904 from storybooks/jest-updated
Browse files Browse the repository at this point in the history
Use jest for unittesting - standardize unit testing epic
  • Loading branch information
shilman authored Apr 17, 2017
2 parents 930c08a + bfd9d26 commit 0792854
Show file tree
Hide file tree
Showing 224 changed files with 732 additions and 1,867 deletions.
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
20 changes: 20 additions & 0 deletions .jestrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"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}",
"!**/generators/**"
],
"coverageDirectory": "coverage",
"testEnvironment": "jsdom",
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
language: node_js
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
- 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 = {};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/getstorybookio/package.json → docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "0.0.1",
"private": true,
"devDependencies": {
"react-scripts": "0.2.1",
"@kadira/storybook": "^2.0.0"
"@kadira/storybook": "*",
"react-scripts": "0.2.1"
},
"dependencies": {
"@kadira/storybook-addons": "^1.3.1",
"@kadira/storybook-addons": "*",
"airbnb-js-shims": "^1.0.1",
"bootstrap": "^3.3.7",
"common-tags": "^1.3.1",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.9.5",
"@kadira/storybook": "*"
"@kadira/storybook": "*",
"react-scripts": "0.9.5"
},
"dependencies": {
"react": "^15.4.2",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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'));
File renamed without changes
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
File renamed without changes.
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
31 changes: 12 additions & 19 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 All @@ -24,34 +23,28 @@
},
"homepage": "https://github.com/kadirahq/storybook-addon-comments#readme",
"devDependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"babel-loader": "^6.2.5",
"babel-polyfill": "^6.13.0",
"babel-preset-react-app": "^0.2.1",
"@kadira/storybook": "*",
"@kadira/storybook-addons": "*",
"@kadira/storybook-database-cloud": "*",
"@kadira/storybook-deployer": "*",
"@kadira/storybook-ui": "*",
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-react-app": "^0.2.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",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"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
Loading

0 comments on commit 0792854

Please sign in to comment.