From 3d49f6d00fe0b8441d39bc46964c505bfd2a7cde Mon Sep 17 00:00:00 2001 From: yifancong Date: Wed, 8 Nov 2023 19:34:22 +0800 Subject: [PATCH] fix: doctor utils time test error (#406) --- .changeset/real-terms-confess.md | 5 +++++ packages/doctor-utils/src/common/time.ts | 8 +++++++- packages/doctor-utils/tests/build/time.test.ts | 3 +-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/real-terms-confess.md diff --git a/.changeset/real-terms-confess.md b/.changeset/real-terms-confess.md new file mode 100644 index 0000000000..0a89f9b7dd --- /dev/null +++ b/.changeset/real-terms-confess.md @@ -0,0 +1,5 @@ +--- +'@rsbuild/doctor-utils': patch +--- + +fix: doctor utils time test error diff --git a/packages/doctor-utils/src/common/time.ts b/packages/doctor-utils/src/common/time.ts index 9fc0656f27..9e2b96dd70 100644 --- a/packages/doctor-utils/src/common/time.ts +++ b/packages/doctor-utils/src/common/time.ts @@ -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; } diff --git a/packages/doctor-utils/tests/build/time.test.ts b/packages/doctor-utils/tests/build/time.test.ts index adf5765509..5f6423162a 100644 --- a/packages/doctor-utils/tests/build/time.test.ts +++ b/packages/doctor-utils/tests/build/time.test.ts @@ -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;