Skip to content

Commit

Permalink
upgrade clone to v2.x, update tests for clones
Browse files Browse the repository at this point in the history
  • Loading branch information
erdii committed Oct 27, 2016
1 parent cf9b773 commit bb397e0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
116 changes: 95 additions & 21 deletions _src/test/mocha_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,8 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
return
return

it "test promise storage", (done) ->
deferred_value = "Some deferred value"
if Promise?
p = new Promise (fulfill, reject) ->
fulfill deferred_value
return
p.then (value) ->
deferred_value.should.eql value
return
localCacheNoClone.set "promise", p
q = localCacheNoClone.get "promise"
q.then (value) ->
state.n++
done()
return
else
console.log "No Promises available in this node version (#{process.version})"
this.skip()
return

after () ->
count = 14
count++ if Promise?
count.should.eql state.n
return
return
Expand Down Expand Up @@ -345,6 +324,101 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
res2 = localCache.get "clone"
state.obj.should.eql res2
return

it "test promise storage (fulfill before adding to cache)", (done) ->
deferred_value = "Some deferred value"
if Promise?
p = new Promise (fulfill, reject) ->
fulfill deferred_value
return
p.then (value) ->
deferred_value.should.eql value
return
localCache.set "promise", p
q = localCache.get "promise"
q.then (value) ->
done()
return
else
console.log "No Promises available in this node version (#{process.version})"
this.skip()
return

it "test promise storage (fulfill after adding to cache)", (done) ->
deferred_value = "Some deferred value"
if Promise?
called = 0
callStub = () ->
called++
if called is 2
done()
return

p = new Promise (fulfill, reject) ->
fulfiller = () ->
fulfill deferred_value
return
setTimeout fulfiller, 250
return
p.then (value) ->
deferred_value.should.eql value
callStub()
return
localCache.set "promise", p
q = localCache.get "promise"
q.then (value) ->
deferred_value.should.eql value
callStub()
return
else
console.log "No Promises available in this node version (#{process.version})"
this.skip()
return

it "test es6 map", () ->
unless Map?
console.log "No Maps available in this node version (#{process.version})"
this.skip()
return

key = randomString 10
map = new Map([ ["firstkey", "firstvalue"], ["2ndkey", "2ndvalue"], ["thirdkey", "thirdvalue"] ])

localCache.set key, map

map.set "fourthkey", "fourthvalue"

cached_map = localCache.get key
should( cached_map.get("2ndkey") ).eql "2ndvalue"
should( cached_map.get "fourthkey" ).be.undefined()
return

it "test `useClones = true` with an Object", () ->
key = randomString 10
value =
a: 123
b: 456
c = 789

localCache.set key, value
value.a = c

value.should.not.be.eql localCache.get(key)
return

it "test `useClones = false` with an Object", () ->
key = randomString 10
value =
a: 123
b: 456
c = 789

localCacheNoClone.set key, value
value.a = c

should( value is localCacheNoClone.get(key) ).be.true()
return

return

describe "correct and incorrect key types", () ->
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"build": "grunt build"
},
"dependencies": {
"lodash": "4.x",
"clone": "1.0.x"
"clone": "2.x",
"lodash": "4.x"
},
"devDependencies": {
"grunt": "0.4.x",
Expand Down

0 comments on commit bb397e0

Please sign in to comment.