-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7fc6d7
commit f3e673c
Showing
12 changed files
with
227 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- "6" | ||
script: npm run test:production | ||
script: npm test | ||
|
||
# Repository token must be provided in "coverage:production" npm script | ||
after_success: npm run coverage:production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import uglify from 'rollup-plugin-uglify'; | ||
|
||
export default { | ||
entry: 'src/index.js', | ||
format: 'umd', | ||
exports: 'named', | ||
moduleName: 'reduxLogger', | ||
dest: 'dist/redux-logger.js', | ||
plugins: [ | ||
babel({ | ||
babelrc: false, | ||
presets: [ | ||
['es2015', { | ||
modules: false, | ||
}], | ||
'stage-0' | ||
], | ||
plugins: [ | ||
'external-helpers' | ||
], | ||
}), | ||
commonjs({ | ||
include: 'node_modules/**', | ||
}), | ||
nodeResolve({ | ||
jsnext: true, | ||
main: true, | ||
browser: true, | ||
}), | ||
uglify() | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { style, render, default as diffLogger } from '../src/diff'; | ||
|
||
context('Diff', () => { | ||
describe('style', () => { | ||
it('return css rules for the given kind of diff changes', () => { | ||
expect(style('E')).to.equal('color: #2196F3; font-weight: bold'); | ||
expect(style('N')).to.equal('color: #4CAF50; font-weight: bold'); | ||
expect(style('D')).to.equal('color: #F44336; font-weight: bold'); | ||
expect(style('A')).to.equal('color: #2196F3; font-weight: bold'); | ||
}); | ||
}); | ||
|
||
describe('render', () => { | ||
it('should return an array indicating the changes', () => { | ||
expect(render({ | ||
kind: 'E', | ||
path: ['capitain', 'name'], | ||
lhs: 'kirk', | ||
rhs: 'picard', | ||
})).to.eql(['capitain.name', 'kirk', '→', 'picard']); | ||
}); | ||
|
||
it('should return an array indicating an added property/element', () => { | ||
expect(render({ | ||
kind: 'N', | ||
path: ['crew', 'engineer'], | ||
rhs: 'geordi', | ||
})).to.eql(['crew.engineer', 'geordi']); | ||
}); | ||
|
||
it('should return an array indicating a removed property/element', () => { | ||
expect(render({ | ||
kind: 'D', | ||
path: ['crew', 'security'], | ||
})).to.eql(['crew.security']); | ||
}); | ||
|
||
it('should return an array indicating a changed index', () => { | ||
expect(render({ | ||
kind: 'A', | ||
path: ['crew'], | ||
index: 2, | ||
item: { | ||
kind: 'N', | ||
rhs: 'after', | ||
}, | ||
})).to.eql(['crew[2]', { | ||
kind: 'N', | ||
rhs: 'after', | ||
}]); | ||
}); | ||
|
||
it('should return an empty array', () => { | ||
expect(render({})).to.eql([]); | ||
}); | ||
}); | ||
|
||
describe('diffLogger', () => { | ||
let logger | ||
|
||
beforeEach(() => { | ||
logger = { | ||
log: sinon.spy(), | ||
groupCollapsed: sinon.spy(), | ||
groupEnd: sinon.spy(), | ||
group: sinon.spy(), | ||
}; | ||
}); | ||
|
||
it('should show no diff with group collapsed', () => { | ||
diffLogger({}, {}, logger, true); | ||
|
||
expect(logger.group.calledOnce).to.be.false; | ||
expect(logger.groupCollapsed.calledOnce).to.be.true; | ||
expect(logger.groupEnd.calledOnce).to.be.true; | ||
expect(logger.log.calledOnce).to.be.true; | ||
expect(logger.log.calledWith('—— no diff ——')).to.be.true; | ||
}); | ||
|
||
it('should show no diff with group not collapsed', () => { | ||
diffLogger({}, {}, logger, false); | ||
|
||
expect(logger.group.calledOnce).to.be.true; | ||
expect(logger.groupCollapsed.calledOnce).to.be.false; | ||
expect(logger.groupEnd.calledOnce).to.be.true; | ||
expect(logger.log.calledOnce).to.be.true; | ||
expect(logger.log.calledWith('—— no diff ——')).to.be.true; | ||
}); | ||
|
||
it('should log no diff without group', () => { | ||
const loggerWithNoGroupCollapsed = Object.assign({}, logger, { | ||
groupCollapsed: () => { | ||
throw new Error() | ||
}, | ||
groupEnd: () => { | ||
throw new Error() | ||
}, | ||
}); | ||
|
||
diffLogger({}, {}, loggerWithNoGroupCollapsed, true); | ||
|
||
expect(loggerWithNoGroupCollapsed.log.calledWith('diff')).to.be.true; | ||
expect(loggerWithNoGroupCollapsed.log.calledWith('—— no diff ——')).to.be.true; | ||
expect(loggerWithNoGroupCollapsed.log.calledWith('—— diff end —— ')).to.be.true; | ||
}); | ||
|
||
it('should log the diffs', () => { | ||
diffLogger({name: 'kirk'}, {name: 'picard'}, logger, false); | ||
|
||
expect(logger.log.calledWithExactly('%c CHANGED:', 'color: #2196F3; font-weight: bold', 'name', 'kirk', '→', 'picard')).to.be.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from 'chai'; | ||
import { repeat, pad, formatTime } from '../src/helpers'; | ||
|
||
context('Helpers', () => { | ||
describe('repeat', () => { | ||
it('should repeat a string the number of indicated times', () => { | ||
expect(repeat('teacher', 3)).to.equal('teacherteacherteacher'); | ||
}); | ||
}); | ||
|
||
describe('pad', () => { | ||
it('should add leading zeros to a number given a maximun length', () => { | ||
expect(pad(56, 4)).to.equal('0056'); | ||
}); | ||
}); | ||
|
||
describe('formatTime', () => { | ||
it('should format a time given a Date object', () => { | ||
const time = new Date('December 25, 1995 23:15:30'); | ||
expect(formatTime(time)).to.equal('23:15:30.000'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.