Skip to content

Commit

Permalink
misc: configure test environment and code coverage
Browse files Browse the repository at this point in the history
Add code coverage reporting (console, HTML), prepare Travis CI config file for Codecov integration, update Node.js version used by Travis CI.
  • Loading branch information
grushetsky committed May 20, 2016
1 parent 93647fa commit ae8eb0e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.DS_Store

node_modules
npm-debug.log

.nyc_output
coverage

example/build
dist
lib
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "5.1.0"
script: npm run test
- "6.2.0"
script: npm run test:production
after_success: npm run coverage:production
25 changes: 24 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@
"main": "lib/index.js",
"scripts": {
"lint": "$(npm bin)/eslint src",
"test": "npm run lint",
"test": "NODE_ENV=development npm run lint && npm run spec",
"test:production": "NODE_ENV=production npm run lint && npm run spec",
"spec": "NODE_PATH=src nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
"spec:watch": "NODE_ENV=development npm run spec -- --watch",
"coverage": "nyc report",
"coverage:html": "nyc report --reporter=html && (http-server -p 8077 ./coverage & open-url http://localhost:8077/)",
"coverage:production": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"clean": "$(npm bin)/rimraf dist lib",
"build:lib": "$(npm bin)/babel src --out-dir lib",
"build:umd": "LIBRARY_NAME=reduxLogger NODE_ENV=development $(npm bin)/webpack src/index.js dist/index.js --config webpack.build.js",
"build:umd:min": "LIBRARY_NAME=reduxLogger NODE_ENV=production $(npm bin)/webpack -p src/index.js dist/index.min.js --config webpack.build.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"prepublish": "npm run clean && npm run test && npm run build"
},
"nyc": {
"exclude": [
"node_modules",
"spec",
"example",
"lib",
"dist",
"webpack.*.js"
]
},
"files": [
"dist",
"lib",
Expand Down Expand Up @@ -42,11 +58,18 @@
"babel-eslint": "6.0.4",
"babel-loader": "6.2.0",
"babel-plugin-add-module-exports": "0.1.1",
"babel-plugin-transform-inline-environment-variables": "6.3.13",
"babel-preset-es2015": "6.3.13",
"babel-preset-react": "6.3.13",
"babel-preset-stage-0": "6.3.13",
"chai": "3.5.0",
"codecov": "1.0.1",
"eslint": "2.10.2",
"eslint-plugin-react": "5.1.1",
"http-server": "0.9.0",
"mocha": "2.4.5",
"nyc": "6.4.4",
"open-url": "2.0.2",
"rimraf": "2.4.4",
"webpack": "1.12.9"
},
Expand Down
11 changes: 11 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect } from 'chai';

import { repeat } from 'helpers';

context(`Helpers`, () => {
describe(`'repeat'`, () => {
it(`should repeat a string the number of indicated times`, () => {
expect(repeat(`teacher`, 3)).to.equal(`teacherteacherteacher`);
});
});
});
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const repeat = (str, times) => (new Array(times + 1)).join(str);
export const repeat = (str, times) => (new Array(times + 1)).join(str);

const pad = (num, maxLength) => repeat(`0`, maxLength - num.toString().length) + num;
export const pad = (num, maxLength) => repeat(`0`, maxLength - num.toString().length) + num;

export const formatTime = (time) => `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;

Expand Down

0 comments on commit ae8eb0e

Please sign in to comment.