1
1
import test from 'ava' ;
2
- import prettyMilliseconds from '.' ;
2
+ import prettyMilliseconds from './index.js ' ;
3
3
4
4
test ( 'prettify milliseconds' , t => {
5
5
t . is ( prettyMilliseconds ( 0 ) , '0ms' ) ;
@@ -18,8 +18,8 @@ test('prettify milliseconds', t => {
18
18
t . is ( prettyMilliseconds ( 1000 * 60 * 60 * 999 ) , '41d 15h' ) ;
19
19
t . is ( prettyMilliseconds ( 1000 * 60 * 60 * 24 * 465 ) , '1y 100d' ) ;
20
20
t . is ( prettyMilliseconds ( 1000 * 60 * 67 * 24 * 465 ) , '1y 154d 6h' ) ;
21
- t . is ( prettyMilliseconds ( 119999 ) , '1m 59.9s' ) ;
22
- t . is ( prettyMilliseconds ( 120000 ) , '2m' ) ;
21
+ t . is ( prettyMilliseconds ( 119_999 ) , '1m 59.9s' ) ;
22
+ t . is ( prettyMilliseconds ( 120_000 ) , '2m' ) ;
23
23
} ) ;
24
24
25
25
test ( 'have a compact option' , t => {
@@ -40,14 +40,14 @@ test('have a unitCount option', t => {
40
40
} ) ;
41
41
42
42
test ( 'have a secondsDecimalDigits option' , t => {
43
- t . is ( prettyMilliseconds ( 10000 ) , '10s' ) ;
44
- t . is ( prettyMilliseconds ( 33333 ) , '33.3s' ) ;
43
+ t . is ( prettyMilliseconds ( 10_000 ) , '10s' ) ;
44
+ t . is ( prettyMilliseconds ( 33_333 ) , '33.3s' ) ;
45
45
t . is ( prettyMilliseconds ( 999 , { secondsDecimalDigits : 0 } ) , '999ms' ) ;
46
46
t . is ( prettyMilliseconds ( 1000 , { secondsDecimalDigits : 0 } ) , '1s' ) ;
47
47
t . is ( prettyMilliseconds ( 1999 , { secondsDecimalDigits : 0 } ) , '1s' ) ;
48
48
t . is ( prettyMilliseconds ( 2000 , { secondsDecimalDigits : 0 } ) , '2s' ) ;
49
- t . is ( prettyMilliseconds ( 33333 , { secondsDecimalDigits : 0 } ) , '33s' ) ;
50
- t . is ( prettyMilliseconds ( 33333 , { secondsDecimalDigits : 4 } ) , '33.3330s' ) ;
49
+ t . is ( prettyMilliseconds ( 33_333 , { secondsDecimalDigits : 0 } ) , '33s' ) ;
50
+ t . is ( prettyMilliseconds ( 33_333 , { secondsDecimalDigits : 4 } ) , '33.3330s' ) ;
51
51
} ) ;
52
52
53
53
test ( 'have a millisecondsDecimalDigits option' , t => {
@@ -58,7 +58,7 @@ test('have a millisecondsDecimalDigits option', t => {
58
58
59
59
test ( 'have a keepDecimalsOnWholeSeconds option' , t => {
60
60
t . is ( prettyMilliseconds ( 1000 * 33 , { secondsDecimalDigits : 2 , keepDecimalsOnWholeSeconds : true } ) , '33.00s' ) ;
61
- t . is ( prettyMilliseconds ( 1000 * 33.00004 , { secondsDecimalDigits : 2 , keepDecimalsOnWholeSeconds : true } ) , '33.00s' ) ;
61
+ t . is ( prettyMilliseconds ( 1000 * 33.000_04 , { secondsDecimalDigits : 2 , keepDecimalsOnWholeSeconds : true } ) , '33.00s' ) ;
62
62
} ) ;
63
63
64
64
test ( 'have a verbose option' , t => {
@@ -89,20 +89,20 @@ test('have a separateMilliseconds option', t => {
89
89
90
90
test ( 'have a formatSubMilliseconds option' , t => {
91
91
t . is ( prettyMilliseconds ( 0.4 , { formatSubMilliseconds : true } ) , '400µs' ) ;
92
- t . is ( prettyMilliseconds ( 0.123571 , { formatSubMilliseconds : true } ) , '123µs 571ns' ) ;
93
- t . is ( prettyMilliseconds ( 0.123456789 , { formatSubMilliseconds : true } ) , '123µs 456ns' ) ;
92
+ t . is ( prettyMilliseconds ( 0.123_571 , { formatSubMilliseconds : true } ) , '123µs 571ns' ) ;
93
+ t . is ( prettyMilliseconds ( 0.123_456_789 , { formatSubMilliseconds : true } ) , '123µs 456ns' ) ;
94
94
t . is (
95
- prettyMilliseconds ( ( 60 * 60 * 1000 ) + ( 23 * 1000 ) + 433 + 0.123456 , {
96
- formatSubMilliseconds : true
95
+ prettyMilliseconds ( ( 60 * 60 * 1000 ) + ( 23 * 1000 ) + 433 + 0.123_456 , {
96
+ formatSubMilliseconds : true ,
97
97
} ) ,
98
- '1h 23s 433ms 123µs 456ns'
98
+ '1h 23s 433ms 123µs 456ns' ,
99
99
) ;
100
100
} ) ;
101
101
102
102
test ( 'work with verbose and compact options' , t => {
103
103
const fn = milliseconds => prettyMilliseconds ( milliseconds , {
104
104
verbose : true ,
105
- compact : true
105
+ compact : true ,
106
106
} ) ;
107
107
108
108
t . is ( fn ( 1000 ) , '1 second' ) ;
@@ -132,20 +132,20 @@ test('work with verbose and unitCount options', t => {
132
132
test ( 'work with verbose and secondsDecimalDigits options' , t => {
133
133
const fn = milliseconds => prettyMilliseconds ( milliseconds , {
134
134
verbose : true ,
135
- secondsDecimalDigits : 4
135
+ secondsDecimalDigits : 4 ,
136
136
} ) ;
137
137
138
138
t . is ( fn ( 1000 ) , '1 second' ) ;
139
139
t . is ( fn ( 1000 + 400 ) , '1.4000 seconds' ) ;
140
140
t . is ( fn ( ( 1000 * 2 ) + 400 ) , '2.4000 seconds' ) ;
141
141
t . is ( fn ( ( 1000 * 5 ) + 254 ) , '5.2540 seconds' ) ;
142
- t . is ( fn ( 33333 ) , '33.3330 seconds' ) ;
142
+ t . is ( fn ( 33_333 ) , '33.3330 seconds' ) ;
143
143
} ) ;
144
144
145
145
test ( 'work with verbose and millisecondsDecimalDigits options' , t => {
146
146
const fn = milliseconds => prettyMilliseconds ( milliseconds , {
147
147
verbose : true ,
148
- millisecondsDecimalDigits : 4
148
+ millisecondsDecimalDigits : 4 ,
149
149
} ) ;
150
150
151
151
t . is ( fn ( 1 ) , '1.0000 millisecond' ) ;
@@ -158,25 +158,25 @@ test('work with verbose and millisecondsDecimalDigits options', t => {
158
158
test ( 'work with verbose and formatSubMilliseconds options' , t => {
159
159
t . is (
160
160
prettyMilliseconds ( 0.4 , { formatSubMilliseconds : true , verbose : true } ) ,
161
- '400 microseconds'
161
+ '400 microseconds' ,
162
162
) ;
163
163
t . is (
164
- prettyMilliseconds ( 0.123571 , {
164
+ prettyMilliseconds ( 0.123_571 , {
165
165
formatSubMilliseconds : true ,
166
- verbose : true
166
+ verbose : true ,
167
167
} ) ,
168
- '123 microseconds 571 nanoseconds'
168
+ '123 microseconds 571 nanoseconds' ,
169
169
) ;
170
170
t . is (
171
- prettyMilliseconds ( 0.123456789 , {
171
+ prettyMilliseconds ( 0.123_456_789 , {
172
172
formatSubMilliseconds : true ,
173
- verbose : true
173
+ verbose : true ,
174
174
} ) ,
175
- '123 microseconds 456 nanoseconds'
175
+ '123 microseconds 456 nanoseconds' ,
176
176
) ;
177
177
t . is (
178
178
prettyMilliseconds ( 0.001 , { formatSubMilliseconds : true , verbose : true } ) ,
179
- '1 microsecond'
179
+ '1 microsecond' ,
180
180
) ;
181
181
} ) ;
182
182
@@ -188,18 +188,18 @@ test('compact option overrides unitCount option', t => {
188
188
189
189
test ( 'work with separateMilliseconds and formatSubMilliseconds options' , t => {
190
190
t . is (
191
- prettyMilliseconds ( 1010.340067 , {
191
+ prettyMilliseconds ( 1010.340_067 , {
192
192
separateMilliseconds : true ,
193
- formatSubMilliseconds : true
193
+ formatSubMilliseconds : true ,
194
194
} ) ,
195
- '1s 10ms 340µs 67ns'
195
+ '1s 10ms 340µs 67ns' ,
196
196
) ;
197
197
t . is (
198
- prettyMilliseconds ( ( 60 * 1000 ) + 34 + 0.000005 , {
198
+ prettyMilliseconds ( ( 60 * 1000 ) + 34 + 0.000_005 , {
199
199
separateMilliseconds : true ,
200
- formatSubMilliseconds : true
200
+ formatSubMilliseconds : true ,
201
201
} ) ,
202
- '1m 34ms 5ns'
202
+ '1m 34ms 5ns' ,
203
203
) ;
204
204
} ) ;
205
205
@@ -213,15 +213,15 @@ test('throw on invalid', t => {
213
213
} ) ;
214
214
215
215
t . throws ( ( ) => {
216
- prettyMilliseconds ( Infinity ) ;
216
+ prettyMilliseconds ( Number . POSITIVE_INFINITY ) ;
217
217
} ) ;
218
218
} ) ;
219
219
220
220
test ( 'properly rounds milliseconds with secondsDecimalDigits' , t => {
221
221
const fn = milliseconds =>
222
222
prettyMilliseconds ( milliseconds , {
223
223
verbose : true ,
224
- secondsDecimalDigits : 0
224
+ secondsDecimalDigits : 0 ,
225
225
} ) ;
226
226
t . is ( fn ( 3 * 60 * 1000 ) , '3 minutes' ) ;
227
227
t . is ( fn ( ( 3 * 60 * 1000 ) - 1 ) , '2 minutes 59 seconds' ) ;
@@ -241,7 +241,7 @@ test('`colonNotation` option', t => {
241
241
t . is ( prettyMilliseconds ( 1543 , { colonNotation : true } ) , '0:01.5' ) ;
242
242
t . is ( prettyMilliseconds ( 1000 * 60 , { colonNotation : true } ) , '1:00' ) ;
243
243
t . is ( prettyMilliseconds ( 1000 * 90 , { colonNotation : true } ) , '1:30' ) ;
244
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true } ) , '1:35.5' ) ;
244
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true } ) , '1:35.5' ) ;
245
245
t . is ( prettyMilliseconds ( ( 1000 * 60 * 10 ) + 543 , { colonNotation : true } ) , '10:00.5' ) ;
246
246
t . is ( prettyMilliseconds ( ( 1000 * 60 * 59 ) + ( 1000 * 59 ) + 543 , { colonNotation : true } ) , '59:59.5' ) ;
247
247
t . is ( prettyMilliseconds ( ( 1000 * 60 * 60 * 15 ) + ( 1000 * 60 * 59 ) + ( 1000 * 59 ) + 543 , { colonNotation : true } ) , '15:59:59.5' ) ;
@@ -263,10 +263,10 @@ test('`colonNotation` option', t => {
263
263
t . is ( prettyMilliseconds ( 1543 , { colonNotation : true , secondsDecimalDigits : 1 } ) , '0:01.5' ) ;
264
264
t . is ( prettyMilliseconds ( 1543 , { colonNotation : true , secondsDecimalDigits : 2 } ) , '0:01.54' ) ;
265
265
t . is ( prettyMilliseconds ( 1543 , { colonNotation : true , secondsDecimalDigits : 3 } ) , '0:01.543' ) ;
266
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 0 } ) , '1:35' ) ;
267
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 1 } ) , '1:35.5' ) ;
268
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 2 } ) , '1:35.54' ) ;
269
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 3 } ) , '1:35.543' ) ;
266
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 0 } ) , '1:35' ) ;
267
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 1 } ) , '1:35.5' ) ;
268
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 2 } ) , '1:35.54' ) ;
269
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 3 } ) , '1:35.543' ) ;
270
270
t . is ( prettyMilliseconds ( ( 1000 * 60 * 10 ) + 543 , { colonNotation : true , secondsDecimalDigits : 3 } ) , '10:00.543' ) ;
271
271
t . is ( prettyMilliseconds ( ( 1000 * 60 * 60 * 15 ) + ( 1000 * 60 * 59 ) + ( 1000 * 59 ) + 543 , { colonNotation : true , secondsDecimalDigits : 3 } ) , '15:59:59.543' ) ;
272
272
@@ -287,9 +287,9 @@ test('`colonNotation` option', t => {
287
287
t . is ( prettyMilliseconds ( 1000 * 90 , { colonNotation : true , secondsDecimalDigits : 0 , unitCount : 1 } ) , '1' ) ;
288
288
t . is ( prettyMilliseconds ( 1000 * 90 , { colonNotation : true , secondsDecimalDigits : 0 , unitCount : 2 } ) , '1:30' ) ;
289
289
t . is ( prettyMilliseconds ( 1000 * 60 * 90 , { colonNotation : true , secondsDecimalDigits : 0 , unitCount : 3 } ) , '1:30:00' ) ;
290
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 1 } ) , '1' ) ;
291
- t . is ( prettyMilliseconds ( 95543 , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 2 } ) , '1:35.5' ) ;
292
- t . is ( prettyMilliseconds ( 95543 + ( 1000 * 60 * 60 ) , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 3 } ) , '1:01:35.5' ) ;
290
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 1 } ) , '1' ) ;
291
+ t . is ( prettyMilliseconds ( 95_543 , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 2 } ) , '1:35.5' ) ;
292
+ t . is ( prettyMilliseconds ( 95_543 + ( 1000 * 60 * 60 ) , { colonNotation : true , secondsDecimalDigits : 1 , unitCount : 3 } ) , '1:01:35.5' ) ;
293
293
294
294
// Make sure incompatible options fall back to `colonNotation`
295
295
t . is ( prettyMilliseconds ( ( 1000 * 60 * 59 ) + ( 1000 * 59 ) + 543 , { colonNotation : true , formatSubMilliseconds : true } ) , '59:59.5' ) ;
0 commit comments