-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Lolex as alternate implementation of Fake Timers
- Loading branch information
Showing
29 changed files
with
1,143 additions
and
55 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,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import runJest from '../runJest'; | ||
|
||
describe('Lolex as implementation fo fake timers', () => { | ||
it('should be possible to use Lolex from config', () => { | ||
const result = runJest('lolex/from-config'); | ||
expect(result.status).toBe(0); | ||
}); | ||
|
||
it('should be possible to use Lolex from jest-object', () => { | ||
const result = runJest('lolex/from-jest-object'); | ||
expect(result.status).toBe(0); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
test('fake timers', () => { | ||
jest.setSystemTime(0); | ||
|
||
expect(Date.now()).toBe(0); | ||
|
||
jest.setSystemTime(1000); | ||
|
||
expect(Date.now()).toBe(1000); | ||
}); |
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,6 @@ | ||
{ | ||
"jest": { | ||
"timers": "lolex", | ||
"testEnvironment": "node" | ||
} | ||
} |
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,20 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
test('fake timers', () => { | ||
jest.useFakeTimers('lolex'); | ||
|
||
jest.setSystemTime(0); | ||
|
||
expect(Date.now()).toBe(0); | ||
|
||
jest.setSystemTime(1000); | ||
|
||
expect(Date.now()).toBe(1000); | ||
}); |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// flow-typed signature: a865cf1b7ee719c2a40b85dc8dccf56c | ||
// flow-typed version: fc3f3a2e99/lolex_v2.x.x/flow_>=v0.64.x | ||
|
||
// @flow | ||
declare module 'lolex' { | ||
declare opaque type ImmediateID; | ||
declare type installConfig = { | ||
target?: Object, | ||
now?: number | Date, | ||
toFake?: string[], | ||
loopLimit?: number, | ||
shouldAdvanceTime?: boolean, | ||
advanceTimeDelta?: number, | ||
}; | ||
declare type lolex = { | ||
createClock(now?: number, loopLimit?: number): Clock, | ||
install(config?: installConfig): Clock, | ||
timers: Object, | ||
withGlobal(global: Object): lolex, | ||
}; | ||
declare type Clock = { | ||
setTimeout: typeof setTimeout; | ||
clearTimeout: typeof clearTimeout; | ||
setInterval: typeof setInterval; | ||
clearInterval: typeof clearInterval; | ||
setImmediate: typeof setImmediate; | ||
clearImmediate: typeof clearImmediate; | ||
requestAnimationFrame: typeof requestAnimationFrame; | ||
cancelAnimationFrame: typeof cancelAnimationFrame; | ||
hrtime: typeof process.hrtime; | ||
nextTick: typeof process.nextTick; | ||
now: number; | ||
performance?: { | ||
now: typeof performance.now, | ||
}; | ||
tick(time: number | string): void; | ||
next(): void; | ||
reset(): void; | ||
runAll(): void; | ||
runMicrotasks(): void; | ||
runToFrame(): void; | ||
runToLast(): void; | ||
setSystemTime(now?: number | Date): void; | ||
uninstall(): Object[]; | ||
Date: typeof Date; | ||
Performance: typeof Performance; | ||
countTimers(): number; | ||
} | ||
declare module.exports: lolex; | ||
} |
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
Oops, something went wrong.