-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from erikras/upgrade-deps
Upgraded deps, fixed build, added code cov
- Loading branch information
Showing
14 changed files
with
389 additions
and
535 deletions.
There are no files selected for viewing
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,12 +1,3 @@ | ||
{ | ||
"extends": "eslint-config-airbnb", | ||
"env": { | ||
"browser": true, | ||
"mocha": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"comma-dangle": 0, // not sure why airbnb turned this on. gross! | ||
"indent": [2, 2, {"SwitchCase": 1}] | ||
} | ||
"extends": "react-app" | ||
} |
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,11 +1,18 @@ | ||
language: node_js | ||
|
||
before_install: | ||
- npm install -g npm@latest | ||
|
||
node_js: | ||
- "4.0" | ||
- "4" | ||
- "6.0" | ||
- "6" | ||
- "5" | ||
- "4" | ||
- "stable" | ||
|
||
script: | ||
- npm run lint | ||
- npm test | ||
- npm test | ||
|
||
after_success: | ||
- npm run test:cov | ||
- npm run test:codecov |
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 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,110 @@ | ||
import expect from 'expect' | ||
import deepEquals from '../deepEquals' | ||
|
||
const tripleEquals = deepEquals((valueA, valueB) => valueA === valueB, true) | ||
|
||
describe('deepEquals', () => { | ||
it('should return true if argument fields are equal', () => { | ||
expect(tripleEquals(3, 3)).toBe(true) | ||
|
||
expect(tripleEquals('dog', 'dog')).toBe(true) | ||
|
||
expect( | ||
tripleEquals({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined }) | ||
).toBe(true) | ||
|
||
expect(tripleEquals({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true) | ||
|
||
const obj = {} | ||
expect(tripleEquals({ a: 1, b: 2, c: obj }, { a: 1, b: 2, c: obj })).toBe( | ||
true | ||
) | ||
|
||
expect(tripleEquals(null, null)).toBe(true) | ||
}) | ||
|
||
it('should return false if arguments are number and string', () => { | ||
expect(tripleEquals(2, '2')).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are string and number', () => { | ||
expect(tripleEquals('2', 2)).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are number and object', () => { | ||
expect(tripleEquals(4, {})).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are object and number', () => { | ||
expect(tripleEquals({}, 4)).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are number and array', () => { | ||
expect(tripleEquals(4, [])).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are array and number', () => { | ||
expect(tripleEquals([], 4)).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are string and object', () => { | ||
expect(tripleEquals('cat', {})).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are object and string', () => { | ||
expect(tripleEquals({}, 'cat')).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are string and array', () => { | ||
expect(tripleEquals('cat', ['c', 'a', 't'])).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are array and string', () => { | ||
expect(tripleEquals(['c', 'a', 't'], 'cat')).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are array and object', () => { | ||
expect(tripleEquals([], {})).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are object and array', () => { | ||
expect(tripleEquals({}, [])).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are object and null', () => { | ||
expect(tripleEquals({ a: 1 }, null)).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments are null and object', () => { | ||
expect(tripleEquals(null, { a: 1 })).toBe(false) | ||
}) | ||
|
||
it('should return false if first argument has too many keys', () => { | ||
expect(tripleEquals({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false) | ||
}) | ||
|
||
it('should return false if second argument has too many keys', () => { | ||
expect(tripleEquals({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false) | ||
}) | ||
|
||
it('should return false if arguments have different keys', () => { | ||
expect( | ||
tripleEquals({ a: 1, b: 2, c: undefined }, { a: 1, bb: 2, c: undefined }) | ||
).toBe(false) | ||
}) | ||
|
||
it('should return false if first array argument has too many items', () => { | ||
expect(tripleEquals([1, 2, 3, 4], [1, 2, 3])).toBe(false) | ||
}) | ||
|
||
it('should return false if second array argument has too many items', () => { | ||
expect(tripleEquals([1, 2, 3], [1, 2, 3, 4])).toBe(false) | ||
}) | ||
|
||
it('should work with objects inside arrays', () => { | ||
expect(tripleEquals( | ||
[ { val: 4 }, { val: 2 }, { val: 3 } ], | ||
[ { val: 1 }, { val: 2 }, { val: 3 } ] | ||
)).toBe(false) | ||
}) | ||
}) |
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,180 @@ | ||
import expect from 'expect' | ||
import memoize from '../memoize' | ||
|
||
describe('memoize', () => { | ||
describe('basic', () => { | ||
it('single', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x * y * z | ||
} | ||
multiply = memoize()(multiply) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(callCount).toBe(1) | ||
|
||
expect(multiply(4, 5, 6)).toBe(120) | ||
|
||
expect(callCount).toBe(2) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(callCount).toBe(3) | ||
}) | ||
|
||
it('multiple', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x * y * z | ||
} | ||
multiply = memoize(2)(multiply) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(callCount).toBe(1) | ||
|
||
expect(multiply(4, 5, 6)).toBe(120) | ||
|
||
expect(callCount).toBe(2) | ||
|
||
expect(multiply(1, 2, 3)).toBe(6) | ||
|
||
expect(callCount).toBe(2) | ||
|
||
expect(multiply(4, 5, 6)).toBe(120) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
}) | ||
|
||
describe('shallow', () => { | ||
it('array', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x.concat(y, z).reduce((t, n) => t * n) | ||
} | ||
multiply = memoize()(multiply) | ||
|
||
const x = [1, 2, 3] | ||
const y = [4, 5, 6] | ||
const z = [7, 8, 9] | ||
|
||
const x2 = [1, 2, 3] | ||
|
||
expect(multiply(x, y, z)).toBe(362880) | ||
|
||
expect(multiply(x2, y, z)).toBe(362880) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
|
||
it('object', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x.val * y.val * z.val | ||
} | ||
multiply = memoize(2)(multiply) | ||
|
||
const x = { val: 1 } | ||
const y = { val: 2 } | ||
const z = { val: 3 } | ||
|
||
const x2 = { val: 1 } | ||
|
||
expect(multiply(x, y, z)).toBe(6) | ||
|
||
expect(multiply(x2, y, z)).toBe(6) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
}) | ||
|
||
describe('deep', () => { | ||
it('array', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x.concat(y, z).reduce((t, n) => t * n) | ||
} | ||
multiply = memoize(true)(multiply) | ||
|
||
const x = [1, 2, 3] | ||
const y = [4, 5, 6] | ||
const z = [7, 8, 9] | ||
|
||
const x2 = [1, 2, 3] | ||
const x3 = [3, 2, 1] | ||
|
||
expect(multiply(x, y, z)).toBe(362880) | ||
|
||
expect(multiply(x2, y, z)).toBe(362880) | ||
|
||
expect(callCount).toBe(1) | ||
|
||
expect(multiply(x3, y, z)).toBe(362880) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
|
||
it('object', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x.val * y.val * z.val | ||
} | ||
multiply = memoize(true)(multiply) | ||
|
||
const x = { val: 1 } | ||
const y = { val: 2 } | ||
const z = { val: 3 } | ||
|
||
const x2 = { val: 1 } | ||
const x3 = { val: 4 } | ||
|
||
expect(multiply(x, y, z)).toBe(6) | ||
|
||
expect(multiply(x2, y, z)).toBe(6) | ||
|
||
expect(callCount).toBe(1) | ||
|
||
expect(multiply(x3, y, z)).toBe(24) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
|
||
it('object nested', () => { | ||
let callCount = 0 | ||
let multiply = (x, y, z) => { | ||
callCount += 1 | ||
return x.inner.val * y.inner.val * z.inner.val | ||
} | ||
multiply = memoize(true)(multiply) | ||
|
||
const x = { inner: { val: 1 } } | ||
const y = { inner: { val: 2 } } | ||
const z = { inner: { val: 3 } } | ||
|
||
const x2 = { inner: { val: 1 } } | ||
const x3 = { inner: { val: 4 } } | ||
|
||
expect(multiply(x, y, z)).toBe(6) | ||
|
||
expect(multiply(x2, y, z)).toBe(6) | ||
|
||
expect(callCount).toBe(1) | ||
|
||
expect(multiply(x3, y, z)).toBe(24) | ||
|
||
expect(callCount).toBe(2) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.