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

Setup coverage #245

Merged
merged 13 commits into from
May 24, 2016
Merged
30 changes: 29 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,33 @@
],
"plugins": [
"lodash"
]
],
"env": {
"development": {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved all babel config into babelrc. The development section was previously in the loader query.

"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": [
"react"
],
"locals": [
"module"
]
}, {
"transform": "react-transform-catch-errors",
"imports": [
"react",
"redbox-react"
]
}]
}]
]
},
"test": {
"plugins": [
["__coverage__", { "ignore": "test/" }]
Copy link
Member Author

Choose a reason for hiding this comment

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

Since isparta is no longer maintained, we use the new babel-plugin-__coverage__. This plugin instruments the code only. We use the standard karma-coverage karma plugin to generate the coverage reports, but not for instrumenting.

]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
npm-debug.log*
node_modules/
bower_components/
coverage/
dist/
docs/build
docs/app/docgenInfo.json
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Stardust [![Code Climate](https://img.shields.io/codeclimate/github/TechnologyAdvice/stardust.svg?style=flat-square)](https://codeclimate.com/github/TechnologyAdvice/stardust) [![Gemnasium](https://img.shields.io/gemnasium/TechnologyAdvice/stardust.svg?style=flat-square)](https://gemnasium.com/TechnologyAdvice/stardust) [![Circle CI](https://img.shields.io/circleci/project/TechnologyAdvice/stardust/master.svg?style=flat-square)](https://circleci.com/gh/TechnologyAdvice/stardust/tree/master)
# Stardust
[![Circle CI](https://img.shields.io/circleci/project/TechnologyAdvice/stardust/master.svg?style=flat-square)](https://circleci.com/gh/TechnologyAdvice/stardust/tree/master)
[![Codecov](https://img.shields.io/codecov/c/github/TechnologyAdvice/stardust/master.svg?style=flat-square)](https://codecov.io/gh/TechnologyAdvice/stardust)
[![Code Climate](https://img.shields.io/codeclimate/github/TechnologyAdvice/stardust.svg?style=flat-square)](https://codeclimate.com/github/TechnologyAdvice/stardust)
[![Gemnasium](https://img.shields.io/gemnasium/TechnologyAdvice/stardust.svg?style=flat-square)](https://gemnasium.com/TechnologyAdvice/stardust)
Copy link
Member Author

Choose a reason for hiding this comment

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

Added coverage badge.


The (soon to be) [official][8] integration between [Semantic UI][5] and [React][3].

Expand Down
14 changes: 11 additions & 3 deletions build/karma.conf.babel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { argv } from 'yargs'
import webpack from 'webpack'

import config from '../config'
import webpackConfig from './webpack.config'
Expand All @@ -11,7 +10,7 @@ module.exports = (karmaConfig) => {
basePath: process.cwd(),
browsers: ['PhantomJS'],
singleRun: !argv.watch,
reporters: ['mocha'],
reporters: ['mocha', 'coverage'],
files: [
'./test/tests.bundle.js',
],
Expand All @@ -23,7 +22,16 @@ module.exports = (karmaConfig) => {
// exit on ResourceError, useful if karma exits without killing phantom
exitOnResourceError: true,
},
coverageReporter: {
reporters: [
{ type: 'lcov', dir: 'coverage', subdir: '.' },
{ type: 'text-summary' },
],
includeAllSources: true,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

We report lcov data to the coverage/ folder. We also show a summary of coverage levels in the console.

preprocessors: {
// do not include 'coverage' preprocessor for karma-coverage
// code is already instrumented by babel-plugin-__coverage__
'**/*.bundle.js': ['webpack'],
},
client: {
Expand All @@ -45,7 +53,7 @@ module.exports = (karmaConfig) => {
],
},
plugins: [
new webpack.DefinePlugin(config.compiler_globals),
...webpackConfig.plugins,
Copy link
Member Author

Choose a reason for hiding this comment

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

Plugins are conditionally set in webpack config, use all available plugins.

],
resolve: {
...webpackConfig.resolve,
Expand Down
18 changes: 0 additions & 18 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,6 @@ webpackConfig.module.loaders = [{
loader: 'babel',
query: {
cacheDirectory: true,
plugins: [],
presets: ['es2015', 'react', 'stage-1'],
env: {
development: {
plugins: [
['react-transform', {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react'],
}],
}],
],
},
},
},
}, {
//
Expand Down
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
test:
pre:
- npm run lint
post:
- bash <(curl -s https://codecov.io/bash)

deployment:
development:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"babel-core": "^6.5.2",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.0",
"babel-plugin-__coverage__": "^0.111111.11",
Copy link
Member

Choose a reason for hiding this comment

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

Lol, is that version for real?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, I wish this said "babel-plugin-coverage": "^0.1.1". Some other folks are pushing for a "normal" 1.0 release as well on this issue.

"babel-plugin-lodash": "^3.1.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-preset-es2015": "^6.5.0",
Expand Down Expand Up @@ -85,6 +86,7 @@
"json-loader": "^0.5.3",
"karma": "^0.13.22",
"karma-cli": "^1.0.0",
"karma-coverage": "^1.0.0",
"karma-mocha": "^1.0.1",
"karma-mocha-reporter": "^2.0.0",
"karma-phantomjs-launcher": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/addons/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Dropdown from '../../modules/Dropdown/Dropdown'
* A <Select /> is sugar for <Dropdown selection />.
* @see Dropdown
*/
const Select = ({ className, ...rest }) => {
function Select({ className, ...rest }) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This issue was raised and fixed. Automated conformance testing depends on the constructor name. Arrow functions are anonymous. Added a conformance check to ensure all components have names. Updated all stateless functional components to have function names.

Copy link
Member

Choose a reason for hiding this comment

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

If you were to rely on the component's displayName, you could do:

const Select = () => { ... }

Select.displayName = 'Select'

const classes = cx('sd-select', className)

return <Dropdown {...rest} className={classes} selection />
Expand Down
2 changes: 1 addition & 1 deletion src/collections/Menu/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PropTypes } from 'react'
import classNames from 'classnames'
import META from '../../utils/Meta'

const MenuItem = ({ __onClick, active, children, className, label, name, onClick, ...rest }) => {
function MenuItem({ __onClick, active, children, className, label, name, onClick, ...rest }) {
const handleClick = (e) => {
if (__onClick) __onClick(name)
if (onClick) onClick(name)
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Label/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Image from '../Image/Image'
/**
* A label displays content classification
*/
const Label = (props) => {
function Label(props) {
const {
attached, children, color, corner, className, circular, detail, detailLink, floating, horizontal, icon,
image, link, onClick, onClickDetail, onClickRemove, pointing, removable, ribbon, size, tag, text,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Dropdown/DropdownItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { someChildType } from '../../utils/childrenUtils'
import { useKeyOnly } from '../../utils/propUtils'
import META from '../../utils/Meta'

const DropdownItem = (props) => {
function DropdownItem(props) {
const {
active,
children,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let debug
const noop = () => undefined

if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
Copy link
Member Author

Choose a reason for hiding this comment

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

Debug messages crowd test output heavily, silenced debug logs in testing.

debug = require('debug')
localStorage.debug = 'stardust:*'
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Item/ItemItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PropTypes } from 'react'
import cx from 'classnames'
import META from '../../utils/Meta'

const ItemItems = (props) => {
function ItemItems(props) {
const { className, children, ...rest } = props
const classes = cx('sd-item-items ui', className, 'items')

Expand Down
2 changes: 1 addition & 1 deletion test/specs/collections/Form/Fields-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Fields', () => {

describe('evenlyDivided', () => {
it('adds the word class for the number of child fields', () => {
const children = _.times(_.random(1, 16), () => <FormField />)
const children = _.times(_.random(1, 16), (i) => <FormField key={i} />)
const className = `${numberToWord(children.length)} fields`

shallow(<FormFields evenlyDivided>{children}</FormFields>)
Expand Down
10 changes: 10 additions & 0 deletions test/specs/commonTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ const componentInfo = componentCtx.keys().map(key => {
* @param {Object} [requiredProps={}] Props required to render Component without errors or warnings.
*/
export const isConformant = (Component, requiredProps = {}) => {
// tests depend on Component constructor names, enforce them
if (!Component.prototype.constructor.name) {
const ReactDOMServer = require('react-dom/server')
throw new Error([
'Component is not a named function. This should help identify it:',
`static _meta = ${JSON.stringify(Component._meta, null, 2)}`,
`Rendered:\n${ReactDOMServer.renderToStaticMarkup(<Component />)}`,
].join('\n'))
}

const info = _.find(componentInfo, i => i.constructorName === Component.prototype.constructor.name)
const { _meta, constructorName, componentClassName, filenameWithoutExt, sdClass } = info

Expand Down
16 changes: 8 additions & 8 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const wrapperMount = (node, opts) => {
attachTo = document.createElement('div')
document.body.appendChild(attachTo)

wrapper = global.mount(node, { ...opts, attachTo })
wrapper = mount(node, { ...opts, attachTo })
return wrapper
}
const wrapperShallow = (...args) => (wrapper = global.shallow(...args))
const wrapperRender = (...args) => (wrapper = global.render(...args))
const wrapperShallow = (...args) => (wrapper = shallow(...args))
const wrapperRender = (...args) => (wrapper = render(...args))

// ----------------------------------------
// Options
Expand All @@ -52,9 +52,6 @@ const dropdownMenuIsOpen = () => {
menu.should.have.className('visible')
}

options = getOptions()
defaultProps = { options }

describe('Dropdown Component', () => {
beforeEach(() => {
attachTo = undefined
Copy link
Member Author

Choose a reason for hiding this comment

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

cruft

Expand Down Expand Up @@ -720,12 +717,15 @@ describe('Dropdown Component', () => {
})

it('still allows moving selection after blur/focus', () => {
// open, first item is selected
const search = wrapperMount(<Dropdown {...defaultProps} search />)
.find('input.search')
.simulate('focus')

domEvent.keyDown(document, { key: 'ArrowDown' })
dropdownMenuIsOpen()

// open, first item is selected
const items = wrapper
.simulate('click')
.find('DropdownItem')

items
Expand Down
14 changes: 14 additions & 0 deletions test/specs/utils/AutoControlledComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('extending AutoControlledComponent', () => {
})

it('sets state for autoControlledProps', () => {
consoleUtil.disableOnce()

Copy link
Member Author

Choose a reason for hiding this comment

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

These test throw auto controlled prop warnings due to randomly generated props. Silenced logs to silence the warnings.

const autoControlledProps = _.keys(makeProps())
const randomProp = _.sample(autoControlledProps)
const randomValue = faker.hacker.verb()
Expand Down Expand Up @@ -70,6 +72,8 @@ describe('extending AutoControlledComponent', () => {
})

it('does not set state for props defined by the parent', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)

Expand All @@ -95,6 +99,8 @@ describe('extending AutoControlledComponent', () => {

describe('initial state', () => {
it('is derived from autoControlledProps in props', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)

Expand All @@ -114,6 +120,8 @@ describe('extending AutoControlledComponent', () => {

describe('default props', () => {
it('are applied to state for props in autoControlledProps', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)
const defaultProps = makeDefaultProps(props)
Expand All @@ -134,6 +142,8 @@ describe('extending AutoControlledComponent', () => {
})

it('allows trySetState to work on non-default autoControlledProps', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)
const defaultProps = makeDefaultProps(props)
Expand All @@ -155,6 +165,8 @@ describe('extending AutoControlledComponent', () => {

describe('changing props', () => {
it('sets state for props in autoControlledProps', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)

Expand Down Expand Up @@ -189,6 +201,8 @@ describe('extending AutoControlledComponent', () => {
})

it('does not set state for default props when changed', () => {
consoleUtil.disableOnce()

const props = makeProps()
const autoControlledProps = _.keys(props)
const defaultProps = makeDefaultProps(props)
Expand Down