Skip to content

Commit af1d693

Browse files
authored
fix: improve formatting of minutes in build time (#1112)
1 parent a7bbc44 commit af1d693

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

packages/plugin-dts/rstest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defineConfig } from '@rstest/core';
22
import { shared } from '../../rstest.workspace';
33

4+
// Disable color in test
5+
process.env.NO_COLOR = '1';
6+
47
export default defineConfig({
58
...shared,
69
name: 'unit-dts',

packages/plugin-dts/src/utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
});

0 commit comments

Comments
 (0)