File tree Expand file tree Collapse file tree 7 files changed +56
-1
lines changed Expand file tree Collapse file tree 7 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
1414### Removed
1515
16+ ## [ 1.4.0] - 2021-10-26
17+
18+ ### Added
19+
20+ - ` sleep `
21+
22+ ### Changed
23+
24+ ### Removed
25+
1626## [ 1.3.0] - 2021-10-20
1727
1828### Added
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ npm i @techmmunity/utils
5151| function | description |
5252| ---------- | ----------------------------------------------- |
5353| ` cleanObj ` | Remove undefined and null values from an object |
54+ | ` sleep ` | Await the amount of time specified (in seconds) |
5455
5556## ` get* `
5657
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module.exports = {
1313 testEnvironment : "node" ,
1414 moduleDirectories : [ "node_modules" , "src" ] ,
1515 resetMocks : true ,
16+ testTimeout : 15000 ,
1617 coverageThreshold : {
1718 global : {
1819 statements : 99.17 ,
Original file line number Diff line number Diff line change 11{
22 "name" : " @techmmunity/utils" ,
3- "version" : " 1.3 .0" ,
3+ "version" : " 1.4 .0" ,
44 "main" : " index.js" ,
55 "types" : " index.d.ts" ,
66 "license" : " Apache-2.0" ,
Original file line number Diff line number Diff line change 77 */
88
99export * from "./lib/clean-obj" ;
10+ export * from "./lib/sleep" ;
1011
1112/**
1213 * ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ /**
2+ * Await the amount of time specified (in seconds)
3+ */
4+ export const sleep = ( seconds : number ) : Promise < void > =>
5+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
6+ new Promise ( resolve => setTimeout ( resolve , seconds * 1000 ) ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ * True
4+ *
5+ */
6+
7+ import { isBetween } from "../lib/is-between" ;
8+ import { sleep } from "../lib/sleep" ;
9+
10+ describe ( "sleep" , ( ) => {
11+ it ( "with 1 second" , async ( ) => {
12+ const timeBefore = Date . now ( ) ;
13+
14+ await sleep ( 1 ) ;
15+
16+ const timeAfter = Date . now ( ) ;
17+
18+ const offset = timeAfter - timeBefore ;
19+
20+ // Cannot test the exact time, so test a range
21+ expect ( isBetween ( offset , 1000 , 1010 ) ) . toBeTruthy ( ) ;
22+ } ) ;
23+
24+ it ( "with 10 seconds" , async ( ) => {
25+ const timeBefore = Date . now ( ) ;
26+
27+ await sleep ( 10 ) ;
28+
29+ const timeAfter = Date . now ( ) ;
30+
31+ const offset = timeAfter - timeBefore ;
32+
33+ // Cannot test the exact time, so test a range
34+ expect ( isBetween ( offset , 10000 , 10010 ) ) . toBeTruthy ( ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments