{"action":"opened","issue":{"url":"https://api.github.com/repos/ZoeyYoung/blog/issues/28","repository_url":"https://api.github.com/repos/ZoeyYoung/blog","labels_url":"https://api.github.com/repos/ZoeyYoung/blog/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/ZoeyYoung/blog/issues/28/comments","events_url":"https://api.github.com/repos/ZoeyYoung/blog/issues/28/events","html_url":"https://github.com/ZoeyYoung/blog/issues/28","id":141503314,"number":28,"title":"React + Webpack + Karma + Mocha + Babel 单元测试配置","user":{"login":"ZoeyYoung","id":1754066,"avatar_url":"https://avatars.githubusercontent.com/u/1754066?v=3","gravatar_id":"","url":"https://api.github.com/users/ZoeyYoung","html_url":"https://github.com/ZoeyYoung","followers_url":"https://api.github.com/users/ZoeyYoung/followers","following_url":"https://api.github.com/users/ZoeyYoung/following{/other_user}","gists_url":"https://api.github.com/users/ZoeyYoung/gists{/gist_id}","starred_url":"https://api.github.com/users/ZoeyYoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZoeyYoung/subscriptions","organizations_url":"https://api.github.com/users/ZoeyYoung/orgs","repos_url":"https://api.github.com/users/ZoeyYoung/repos","events_url":"https://api.github.com/users/ZoeyYoung/events{/privacy}","received_events_url":"https://api.github.com/users/ZoeyYoung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-17T07:35:00Z","updated_at":"2016-03-17T07:35:00Z","closed_at":null,"body":"### 安装\r\n\r\n1. 安装 [karma](https://www.npmjs.com/package/karma)\r\n2. 安装 [karma cli](https://www.npmjs.com/package/karma-cli)，用于在终端使用karma\r\n  `npm install karma-cli -g`\r\n3. 安装 [mocha](https://mochajs.org/) 测试框架\r\n4. 安装 [karma-mocha](http://npm%20install%20karma-mocha/)，用于结合使用mocha和Karma\r\n5. 安装 [karma-webpack](https://www.npmjs.com/package/karma-webpack)，用于结合使用karma和webpack(用于预处理)\r\n6. 安装 [karma-sourcemap-loader](https://www.npmjs.com/package/karma-sourcemap-loader)\r\n7. 安装 [karma-chrome-launcher](https://www.npmjs.com/package/karma-chrome-launcher)\r\n8. 安装 [chai](http://chaijs.com/) (或其它断言库)\r\n9. 安装 babel-loader，用于支持JSX和ES6\r\n10. 安装 webpack\r\n11. 安装 [karma-coverage](https://www.npmjs.com/package/karma-coverage)\r\n12. 安装 [istanbul-instrumenter-loader](https://github.com/deepsweet/istanbul-instrumenter-loader)\r\n\r\n```\r\nnpm install karma mocha karma-mocha webpack karma-webpack karma-sourcemap-loader karma-chrome-launcher karma-coverage chai babel-loader --save-dev\r\n```\r\n\r\nkarma-mocha-reporter\r\nphantomjs-prebuilt\r\n\r\n### 配置\r\n\r\n两个文件：\r\n\r\n* karma.conf.js\r\n* tests.webpack.js\r\n\r\n参考 [react-karma-babel-webpack-code-coverage](https://github.com/goopscoop/react-karma-babel-webpack-code-coverage)\r\n\r\n[How to implement testing + code coverage on React with Karma, Babel, and Webpack](https://medium.com/@scbarrus/how-to-get-test-coverage-on-react-with-karma-babel-and-webpack-c9273d805063#.59gr151aa)"}}