-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to
jest
instead of old mocha
+ istanbul
- Loading branch information
1 parent
a131732
commit d0c7e3b
Showing
54 changed files
with
1,347 additions
and
1,397 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"main": "./build/index.js", | ||
"scripts": { | ||
"build": "abc build", | ||
"test": "abc test && abc lint", | ||
"test": "jest --runInBand --forceExit && abc lint", | ||
"version": "abc build" | ||
}, | ||
"author": "[email protected]", | ||
|
@@ -30,6 +30,7 @@ | |
}, | ||
"devDependencies": { | ||
"abc-environment": "^2.0.0", | ||
"jest": "^23.6.0", | ||
"redis": "^2.6.2" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,57 +1,56 @@ | ||
/* eslint-env node, mocha */ | ||
import { expect } from 'chai' | ||
/* eslint-env jest */ | ||
import storage from '../../src/cache/redis' | ||
import redis from 'redis' | ||
const cache = storage({redis: redis.createClient()}) | ||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
describe('cache > redis', function () { | ||
this.timeout(5000) | ||
jest.setTimeout(5000) | ||
|
||
beforeEach(() => { | ||
cache.flush() | ||
}) | ||
|
||
it('requires an configuration object', () => { | ||
expect(() => storage()).to.throw() | ||
expect(() => storage()).toThrow() | ||
}) | ||
|
||
it('can flush the cache', async () => { | ||
await cache.set('foo', 'bar', 60 * 60) | ||
let cachedFresh = await cache.get('foo') | ||
expect(cachedFresh, 'cachedFresh').to.equal('bar') | ||
expect(cachedFresh).toEqual('bar') | ||
|
||
await cache.flush() | ||
|
||
let cachedFlushed = await cache.get('foo') | ||
expect(cachedFlushed, 'cachedFlushed').to.equal(null) | ||
expect(cachedFlushed).toEqual(null) | ||
}) | ||
|
||
it('can set and get a single value', async () => { | ||
await cache.set('foo', {herp: 'derp'}, 2) | ||
|
||
// Make sure the data is cached | ||
let cachedFresh = await cache.get('foo') | ||
expect(cachedFresh, 'cachedFresh').to.deep.equal({herp: 'derp'}) | ||
expect(cachedFresh).toEqual({herp: 'derp'}) | ||
|
||
// Make sure the data expires | ||
await wait(3000) | ||
let cachedExpired = await cache.get('foo') | ||
expect(cachedExpired, 'cachedExpired').to.deep.equal(null) | ||
expect(cachedExpired).toEqual(null) | ||
}) | ||
|
||
it('can set and get multiple values', async () => { | ||
await cache.set('abc', {foo: 'bar'}, 2) | ||
await cache.mset([['foo', 'bar', 2], ['herp', {derp: 1}, 2]]) | ||
|
||
let cachedFresh = await cache.get('abc') | ||
expect(cachedFresh, 'cachedFresh').to.deep.equal({foo: 'bar'}) | ||
expect(cachedFresh).toEqual({foo: 'bar'}) | ||
let cachedFreshMany = await cache.mget(['foo', 'herp', 'abc']) | ||
expect(cachedFreshMany, 'cachedFreshMany').to.deep.equal(['bar', {derp: 1}, {foo: 'bar'}]) | ||
expect(cachedFreshMany).toEqual(['bar', {derp: 1}, {foo: 'bar'}]) | ||
|
||
await wait(3000) | ||
|
||
let cachedExpired = await cache.mget(['foo', 'herp', 'abc']) | ||
expect(cachedExpired, 'cachedExpired').to.deep.equal([null, null, null]) | ||
expect(cachedExpired).toEqual([null, null, null]) | ||
}) | ||
}) |
Oops, something went wrong.