From 8e5b523315c93d076451978da5f36d48b584c5b2 Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Mon, 23 May 2016 17:38:34 -0700 Subject: [PATCH 01/13] chore(coverage): setup coverage --- .babelrc | 30 +++++++++++++++++++++++++++++- .gitignore | 1 + build/karma.conf.babel.js | 14 +++++++++++--- build/webpack.config.js | 18 ------------------ package.json | 2 ++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.babelrc b/.babelrc index 80e4f50e51..24522a9d57 100644 --- a/.babelrc +++ b/.babelrc @@ -6,5 +6,33 @@ ], "plugins": [ "lodash" - ] + ], + "env": { + "development": { + "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/" }] + ] + } + } } diff --git a/.gitignore b/.gitignore index a7331188dd..8a16ce4047 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ npm-debug.log* node_modules/ bower_components/ +coverage/ dist/ docs/build docs/app/docgenInfo.json diff --git a/build/karma.conf.babel.js b/build/karma.conf.babel.js index 71faed10f6..21e0540182 100644 --- a/build/karma.conf.babel.js +++ b/build/karma.conf.babel.js @@ -1,5 +1,4 @@ import { argv } from 'yargs' -import webpack from 'webpack' import config from '../config' import webpackConfig from './webpack.config' @@ -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', ], @@ -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, + }, preprocessors: { + // do not include 'coverage' preprocessor for karma-coverage + // code is already instrumented by babel-plugin-__coverage__ '**/*.bundle.js': ['webpack'], }, client: { @@ -45,7 +53,7 @@ module.exports = (karmaConfig) => { ], }, plugins: [ - new webpack.DefinePlugin(config.compiler_globals), + ...webpackConfig.plugins, ], resolve: { ...webpackConfig.resolve, diff --git a/build/webpack.config.js b/build/webpack.config.js index 22b10cd48e..6afc3d4afe 100644 --- a/build/webpack.config.js +++ b/build/webpack.config.js @@ -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'], - }], - }], - ], - }, - }, }, }, { // diff --git a/package.json b/package.json index 541a7dfe39..1a2ff22eb5 100644 --- a/package.json +++ b/package.json @@ -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", "babel-plugin-lodash": "^3.1.4", "babel-plugin-react-transform": "^2.0.2", "babel-preset-es2015": "^6.5.0", @@ -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", From d4ec4bdf25ecdeb06e9b38f3b0fcff9b08716b9d Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Mon, 23 May 2016 17:39:30 -0700 Subject: [PATCH 02/13] chore(ci): report coverage --- circle.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circle.yml b/circle.yml index db4cb8969a..21a42c9dee 100644 --- a/circle.yml +++ b/circle.yml @@ -15,6 +15,8 @@ dependencies: test: pre: - npm run lint + post: + - bash <(curl -s https://codecov.io/bash) deployment: development: From f2dd1ef6fcd7b47a14f2a7dbdf504e922f44707b Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Mon, 23 May 2016 17:39:16 -0700 Subject: [PATCH 03/13] docs(readme): add coverage badge --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4dea620375..7f8f929910 100644 --- a/README.md +++ b/README.md @@ -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) The (soon to be) [official][8] integration between [Semantic UI][5] and [React][3]. From ba8fbf407d0001e25c491eea4f7f0b711d721829 Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Mon, 23 May 2016 17:43:51 -0700 Subject: [PATCH 04/13] test(common): enforce named function components --- test/specs/commonTests.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/specs/commonTests.js b/test/specs/commonTests.js index e1cb2c24a4..17817df9c2 100644 --- a/test/specs/commonTests.js +++ b/test/specs/commonTests.js @@ -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()}`, + ].join('\n')) + } + const info = _.find(componentInfo, i => i.constructorName === Component.prototype.constructor.name) const { _meta, constructorName, componentClassName, filenameWithoutExt, sdClass } = info From ae97dd85f771bb38f763b490d060a34959ca0293 Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Mon, 23 May 2016 17:41:40 -0700 Subject: [PATCH 05/13] refactor(Select): use named function --- src/addons/Select/Select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/Select/Select.js b/src/addons/Select/Select.js index 1cb8654313..0fbdb2e702 100644 --- a/src/addons/Select/Select.js +++ b/src/addons/Select/Select.js @@ -9,7 +9,7 @@ import Dropdown from '../../modules/Dropdown/Dropdown' * A