generated from techmmunity/base-project-packages
-
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.
- Loading branch information
1 parent
cb8040d
commit c7ebb2f
Showing
7 changed files
with
56 additions
and
1 deletion.
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
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,6 @@ | ||
/** | ||
* Await the amount of time specified (in seconds) | ||
*/ | ||
export const sleep = (seconds: number): Promise<void> => | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
new Promise(resolve => setTimeout(resolve, seconds * 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,36 @@ | ||
/** | ||
* | ||
* True | ||
* | ||
*/ | ||
|
||
import { isBetween } from "../lib/is-between"; | ||
import { sleep } from "../lib/sleep"; | ||
|
||
describe("sleep", () => { | ||
it("with 1 second", async () => { | ||
const timeBefore = Date.now(); | ||
|
||
await sleep(1); | ||
|
||
const timeAfter = Date.now(); | ||
|
||
const offset = timeAfter - timeBefore; | ||
|
||
// Cannot test the exact time, so test a range | ||
expect(isBetween(offset, 1000, 1010)).toBeTruthy(); | ||
}); | ||
|
||
it("with 10 seconds", async () => { | ||
const timeBefore = Date.now(); | ||
|
||
await sleep(10); | ||
|
||
const timeAfter = Date.now(); | ||
|
||
const offset = timeAfter - timeBefore; | ||
|
||
// Cannot test the exact time, so test a range | ||
expect(isBetween(offset, 10000, 10010)).toBeTruthy(); | ||
}); | ||
}); |