Skip to content

Commit

Permalink
test: coverage showing
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Aug 13, 2017
1 parent d02d720 commit be0140d
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules

# Bower
bower_components/

coverage/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ install:

script:
- npm test

after_script:
- npm run coverage
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![npm version](https://img.shields.io/npm/v/honoka.svg)](https://www.npmjs.org/package/honoka)
[![Build Status](https://travis-ci.org/kokororin/honoka.svg?branch=master)](https://travis-ci.org/kokororin/honoka)
[![Coverage Status](https://coveralls.io/repos/github/kokororin/honoka/badge.svg?branch=master)](https://coveralls.io/github/kokororin/honoka?branch=master)

Just a fetch() API wrapper

Expand Down
14 changes: 13 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const webpackCfg = require('./webpack.config');

module.exports = function(config) {
Expand Down Expand Up @@ -25,13 +26,24 @@ module.exports = function(config) {
mocha: {}
},
singleRun: true,
reporters: ['mocha'],
reporters: ['mocha', 'coverage-istanbul'],
preprocessors: {
'test/loadtests.js': ['webpack', 'sourcemap']
},
webpack: webpackCfg,
webpackServer: {
noInfo: true
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
dir: path.join(__dirname, 'coverage'),
'report-config': {
html: {
// outputs the report in ./coverage/html
subdir: 'html'
}
}
}
};

Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
"build": "webpack --progress",
"lint": "eslint ./src",
"start": "webpack --watch",
"test": "karma start && npm run lint"
"test": "cross-env NODE_ENV=test karma start && npm run lint",
"coverage": "cat ./coverage/lcov.info | coveralls"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kokororin/honoka.git"
},
"keywords": [
"fetch",
"xhr",
"ajax",
"promise",
"lovelive"
],
"author": "kokororin",
Expand All @@ -24,7 +28,6 @@
},
"homepage": "https://github.com/kokororin/honoka#readme",
"dependencies": {
"object-keys": "^1.0.11",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
Expand All @@ -36,12 +39,16 @@
"babel-preset-env": "^1.6.0",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.1.1",
"coveralls": "^2.13.1",
"cross-env": "^5.0.5",
"eslint": "^4.4.1",
"eslint-config-kotori": "^0.1.3",
"fetch-mock": "^5.12.2",
"istanbul-instrumenter-loader": "^3.0.0",
"karma": "^1.7.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.3",
"karma-sourcemap-loader": "^0.3.7",
Expand Down
5 changes: 4 additions & 1 deletion src/honoka.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ function honoka(url, options = {}) {

forEach(reversedInterceptors, interceptor => {
if (interceptor.response) {
interceptor.response(responseData, response);
honoka.response = response = interceptor.response(
responseData,
response
);
}
});

Expand Down
5 changes: 1 addition & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import keys from 'object-keys';

const spaceChars = ' \\s\u00A0';
const symbolRegex = /([[\]().?/*{}+$^:])/g;

Expand Down Expand Up @@ -79,8 +77,7 @@ export function buildURL(url, params) {

const uris = [];

forEach(keys(params), key => {
let value = params[key];
forEach(params, (value, key) => {
if (isObject(value)) {
value = JSON.stringify(value);
}
Expand Down
16 changes: 15 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const webpack = require('webpack');
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
const pkg = require('./package.json');

module.exports = {
const config = {
entry: ['whatwg-fetch', './src/index.js'],
output: {
path: path.join(__dirname, 'dist'),
Expand Down Expand Up @@ -39,3 +39,17 @@ module.exports = {
new UnminifiedWebpackPlugin()
]
};

if (process.env.NODE_ENV === 'test') {
config.module.rules.push({
test: /\.(js|jsx)$/,
enforce: 'post',
exclude: /node_modules|test/,
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
});
}

module.exports = config;
Loading

0 comments on commit be0140d

Please sign in to comment.