-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added delay functions & removed real time API in time-related tests
- Loading branch information
Showing
6 changed files
with
149 additions
and
3 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
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,41 @@ | ||
/* eslint-env mocha */ | ||
|
||
var Sinon = require('sinon') | ||
var Chai = require('chai') | ||
var expect = Chai.expect | ||
var delay = require('../../../../lib').Concurrent.delay | ||
|
||
describe('Integration', function () { | ||
describe('/concurrent', function () { | ||
describe('/timeout.js', function () { | ||
describe('.delay', function () { | ||
var clock | ||
|
||
beforeEach(function () { | ||
clock = Sinon.useFakeTimers() | ||
}) | ||
|
||
afterEach(function () { | ||
clock.restore() | ||
}) | ||
|
||
it('delays processing of specified code', function () { | ||
var callback = Sinon.stub() | ||
var delayed = delay(10, callback) | ||
expect(callback.callCount).to.eq(0) | ||
clock.next() | ||
return delayed | ||
.then(function () { | ||
expect(callback.callCount).to.eq(1) | ||
}) | ||
}) | ||
|
||
it('creates delayed promise if no callback is specified', function () { | ||
var promise = delay(1) | ||
clock.next() | ||
return promise | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
50 changes: 50 additions & 0 deletions
50
test/suites/integration/concurrent/timeout.throttle.spec.js
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,50 @@ | ||
/* eslint-env mocha */ | ||
|
||
var Sinon = require('sinon') | ||
var Chai = require('chai') | ||
var expect = Chai.expect | ||
var throttle = require('../../../../lib').Concurrent.throttle | ||
|
||
describe('Integration', function () { | ||
describe('/concurrent', function () { | ||
describe('/timeout.js', function () { | ||
describe('.throttle', function () { | ||
var clock | ||
|
||
beforeEach(function () { | ||
clock = Sinon.useFakeTimers() | ||
}) | ||
|
||
afterEach(function () { | ||
clock.restore() | ||
}) | ||
|
||
it('creates promise that resolves after passed time if it resolved too fast', function () { | ||
var promise = Promise.resolve() | ||
var stub = Sinon.stub() | ||
var throttled = throttle(promise, 10).then(stub) | ||
expect(stub.callCount).to.eq(0) | ||
clock.next() | ||
return throttled | ||
.then(function () { | ||
expect(stub.callCount).to.eq(1) | ||
}) | ||
}) | ||
|
||
it('doesn\'t slow down promise that takes longer that throttle time', function () { | ||
var promise = new Promise(function (resolve) { | ||
setTimeout(resolve, 30) | ||
}) | ||
var stub = Sinon.stub() | ||
var throttled = throttle(promise, 10).then(stub) | ||
expect(stub.callCount).to.eq(0) | ||
clock.tick(30) | ||
return throttled | ||
.then(function () { | ||
expect(stub.callCount).to.eq(1) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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