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
13
13
14
14
### Removed
15
15
16
+ ## [ 1.4.0] - 2021-10-26
17
+
18
+ ### Added
19
+
20
+ - ` sleep `
21
+
22
+ ### Changed
23
+
24
+ ### Removed
25
+
16
26
## [ 1.3.0] - 2021-10-20
17
27
18
28
### Added
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ npm i @techmmunity/utils
51
51
| function | description |
52
52
| ---------- | ----------------------------------------------- |
53
53
| ` cleanObj ` | Remove undefined and null values from an object |
54
+ | ` sleep ` | Await the amount of time specified (in seconds) |
54
55
55
56
## ` get* `
56
57
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module.exports = {
13
13
testEnvironment : "node" ,
14
14
moduleDirectories : [ "node_modules" , "src" ] ,
15
15
resetMocks : true ,
16
+ testTimeout : 15000 ,
16
17
coverageThreshold : {
17
18
global : {
18
19
statements : 99.17 ,
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @techmmunity/utils" ,
3
- "version" : " 1.3 .0" ,
3
+ "version" : " 1.4 .0" ,
4
4
"main" : " index.js" ,
5
5
"types" : " index.d.ts" ,
6
6
"license" : " Apache-2.0" ,
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
export * from "./lib/clean-obj" ;
10
+ export * from "./lib/sleep" ;
10
11
11
12
/**
12
13
* ---------------------------------------------------------------------------
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