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 11import { defineConfig } from '@rstest/core' ;
22import { shared } from '../../rstest.workspace' ;
33
4+ // Disable color in test
5+ process . env . NO_COLOR = '1' ;
6+
47export default defineConfig ( {
58 ...shared ,
69 name : 'unit-dts' ,
Original file line number Diff line number Diff line change @@ -136,8 +136,19 @@ export const prettyTime = (seconds: number): string => {
136136 return `${ format ( seconds . toFixed ( 1 ) ) } s` ;
137137 }
138138
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 } ` ;
141152} ;
142153
143154// 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