File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { defineConfig } from '@rstest/core' ;
2
2
import { shared } from '../../rstest.workspace' ;
3
3
4
+ // Disable color in test
5
+ process . env . NO_COLOR = '1' ;
6
+
4
7
export default defineConfig ( {
5
8
...shared ,
6
9
name : 'unit-dts' ,
Original file line number Diff line number Diff line change @@ -136,8 +136,19 @@ export const prettyTime = (seconds: number): string => {
136
136
return `${ format ( seconds . toFixed ( 1 ) ) } s` ;
137
137
}
138
138
139
- const minutes = seconds / 60 ;
140
- return `${ format ( minutes . toFixed ( 2 ) ) } m` ;
139
+ const minutes = Math . floor ( seconds / 60 ) ;
140
+ const minutesLabel = `${ format ( minutes . toFixed ( 0 ) ) } m` ;
141
+ const remainingSeconds = seconds % 60 ;
142
+
143
+ if ( remainingSeconds === 0 ) {
144
+ return minutesLabel ;
145
+ }
146
+
147
+ const secondsLabel = `${ format (
148
+ remainingSeconds . toFixed ( remainingSeconds % 1 === 0 ? 0 : 1 ) ,
149
+ ) } s`;
150
+
151
+ return `${ minutesLabel } ${ secondsLabel } ` ;
141
152
} ;
142
153
143
154
// tinyglobby only accepts posix path
Original file line number Diff line number Diff line change
1
+ import { expect , test } from '@rstest/core' ;
2
+ import { prettyTime } from '../src/utils' ;
3
+
4
+ test ( 'should pretty time correctly' , ( ) => {
5
+ expect ( prettyTime ( 0.0012 ) ) . toEqual ( '0.001 s' ) ;
6
+ expect ( prettyTime ( 0.0123 ) ) . toEqual ( '0.01 s' ) ;
7
+ expect ( prettyTime ( 0.1234 ) ) . toEqual ( '0.12 s' ) ;
8
+ expect ( prettyTime ( 1.234 ) ) . toEqual ( '1.23 s' ) ;
9
+ expect ( prettyTime ( 12.34 ) ) . toEqual ( '12.3 s' ) ;
10
+ expect ( prettyTime ( 120 ) ) . toEqual ( '2 m' ) ;
11
+ expect ( prettyTime ( 123.4 ) ) . toEqual ( '2 m 3.4 s' ) ;
12
+ expect ( prettyTime ( 1234 ) ) . toEqual ( '20 m 34 s' ) ;
13
+ expect ( prettyTime ( 1234.5 ) ) . toEqual ( '20 m 34.5 s' ) ;
14
+ } ) ;
You can’t perform that action at this time.
0 commit comments