From 829cdc930a44a1810402d0f5ea694ee5d7a6f76e Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Tue, 26 May 2026 23:34:51 +0200 Subject: [PATCH] duration must be at least 500ms --- .../src/instrumentation.test.ts | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/packages/@tailwindcss-node/src/instrumentation.test.ts b/packages/@tailwindcss-node/src/instrumentation.test.ts index f6ae55741..b2068d9d6 100644 --- a/packages/@tailwindcss-node/src/instrumentation.test.ts +++ b/packages/@tailwindcss-node/src/instrumentation.test.ts @@ -1,6 +1,5 @@ import { stripVTControlCharacters } from 'util' import { expect, it } from 'vitest' -import { dimensions } from '../../tailwindcss/src/utils/dimensions' import { Instrumentation } from './instrumentation' it('should add instrumentation using start/end markers', () => { @@ -73,15 +72,18 @@ it('should measure async callbacks via the `span` api', async () => { await new Promise((r) => setTimeout(r, 500)) }) - expect.assertions(1) + expect.assertions(2) I.report((output) => { - expect(stabilize(output)).toMatchInlineSnapshot(` + expect(stripVTControlCharacters(output).replace(/\[.*\]/g, '[0.xxms]')).toMatchInlineSnapshot(` " - [510.00ms] Foo - [ 0.05ms] ↳ Bar × 100 + [0.xxms] Foo + [0.xxms] ↳ Bar × 100 " `) + + let [, duration] = stripVTControlCharacters(output).match(/\[(.*)\]/)! + expect(parseFloat(duration)).toBeGreaterThanOrEqual(500) }) }) @@ -134,29 +136,3 @@ it('should auto end pending timers when reporting', () => { `) }) }) - -let nf = new Intl.NumberFormat(undefined, { - style: 'decimal', - minimumFractionDigits: 2, -}) - -function stabilize(output: string) { - return stripVTControlCharacters(output).replace(/\[(\s*)(.*)\]/g, (_, whitespace, duration) => { - let [value, unit] = dimensions.get(duration.trim())! - return `[${whitespace}${nf.format(stableRound(value))}${unit}]` - }) -} - -function stableRound(value: number) { - if (value === 0) return 0 - - let sign = Math.sign(value) - let abs = Math.abs(value) - - let magnitude = 10 ** Math.floor(Math.log10(abs)) - - let step = magnitude / 10 - if (abs < 0.1) step = 0.05 - - return sign * Math.ceil(abs / step) * step -}