Skip to content

Commit

Permalink
fix: doctor utils time test error (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Nov 8, 2023
1 parent 58306e2 commit 3d49f6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-terms-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rsbuild/doctor-utils': patch
---

fix: doctor utils time test error
8 changes: 7 additions & 1 deletion packages/doctor-utils/src/common/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ export function getCurrentTimestamp(
startHRTime: [number, number],
): number {
const endHRTime = hrtime(startHRTime);
const end = start + endHRTime[0] * 1000 + endHRTime[1] / 1000000;
// When in CI env, this (endHRTime[1] / 1000000) may have decimal, this would made test failed.
const end =
start +
endHRTime[0] * 1000 +
(process.env.VITEST
? Math.round(endHRTime[1] / 1000000)
: endHRTime[1] / 1000000);

return end;
}
3 changes: 1 addition & 2 deletions packages/doctor-utils/tests/build/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { Time } from '../../src/common';
vi.setConfig({ testTimeout: 100000 });

describe('test src/build/time.ts', () => {
// FIXME skipped because it always get timeout in CI
it.skip('getCurrentTimestamp', async () => {
it('getCurrentTimestamp', async () => {
const start = Date.now();
const startH = hrtime();
const delay = 500;
Expand Down

0 comments on commit 3d49f6d

Please sign in to comment.