From a7bbb9b0032b6e79a11d52daba2e5513c02fa18d Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:39:58 +0200 Subject: [PATCH] wrap benchmark suite in describe call again --- tests/tw-merge.benchmark.ts | 128 ++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/tests/tw-merge.benchmark.ts b/tests/tw-merge.benchmark.ts index c9f7b2a..09d44bf 100644 --- a/tests/tw-merge.benchmark.ts +++ b/tests/tw-merge.benchmark.ts @@ -4,76 +4,78 @@ import { ClassNameValue, extendTailwindMerge } from '../src' import testData from './tw-merge-benchmark-data.json' -bench('init', () => { - const twMerge = extendTailwindMerge({}) - twMerge() -}) +describe('twMerge', () => { + bench('init', () => { + const twMerge = extendTailwindMerge({}) + twMerge() + }) -for (const isCached of [true, false]) { - describe(isCached ? 'cached' : 'uncached', () => { - let twMerge: (...classLists: ClassNameValue[]) => string + for (const isCached of [true, false]) { + describe(isCached ? 'cached' : 'uncached', () => { + let twMerge: (...classLists: ClassNameValue[]) => string - function setup(task: BenchTask) { - task.opts.beforeEach = function beforeEach() { - twMerge = extendTailwindMerge({ - cacheSize: isCached ? undefined : 0, - }) + function setup(task: BenchTask) { + task.opts.beforeEach = function beforeEach() { + twMerge = extendTailwindMerge({ + cacheSize: isCached ? undefined : 0, + }) - twMerge() + twMerge() + } } - } - const withSuffix = (str: string) => str + ' ' + (isCached ? '(cached)' : '(uncached)') + const withSuffix = (str: string) => str + ' ' + (isCached ? '(cached)' : '(uncached)') - const options: BenchOptions | undefined = process.env.CI - ? undefined - : { - warmupTime: 10, - time: 50, - setup, - } + const options: BenchOptions | undefined = process.env.CI + ? undefined + : { + warmupTime: 10, + time: 50, + setup, + } - if (process.env.CI) { - // codespeed tries to optimize function, before actual setup call - we need to adopt - beforeEach(setup) - } + if (process.env.CI) { + // codespeed tries to optimize function, before actual setup call - we need to adopt + beforeEach(setup) + } - bench( - withSuffix('simple'), - () => { - twMerge('flex mx-10 px-10', 'mr-5 pr-5') - }, - options, - ) + bench( + withSuffix('simple'), + () => { + twMerge('flex mx-10 px-10', 'mr-5 pr-5') + }, + options, + ) - bench( - withSuffix('heavy'), - () => { - twMerge( - 'font-medium text-sm leading-16', - 'group/button relative isolate items-center justify-center overflow-hidden rounded-md outline-none transition [-webkit-app-region:no-drag] focus-visible:ring focus-visible:ring-primary', - 'inline-flex', - 'bg-primary-50 ring ring-primary-200', - 'text-primary dark:text-primary-900 hover:bg-primary-100', - false, - 'font-medium text-sm leading-16 gap-4 px-6 py-4', - null, - 'p-0 size-24', - null, - ) - }, - options, - ) + bench( + withSuffix('heavy'), + () => { + twMerge( + 'font-medium text-sm leading-16', + 'group/button relative isolate items-center justify-center overflow-hidden rounded-md outline-none transition [-webkit-app-region:no-drag] focus-visible:ring focus-visible:ring-primary', + 'inline-flex', + 'bg-primary-50 ring ring-primary-200', + 'text-primary dark:text-primary-900 hover:bg-primary-100', + false, + 'font-medium text-sm leading-16 gap-4 px-6 py-4', + null, + 'p-0 size-24', + null, + ) + }, + options, + ) - bench( - withSuffix('collection'), - () => { - for (let i = 0; i < testData.length; ++i) { - type Item = (typeof testData)[number][number] - twMerge(...(testData[i] as Exclude[])) - } - }, - options, - ) - }) -} + bench( + withSuffix('collection'), + () => { + for (let i = 0; i < testData.length; ++i) { + type Item = (typeof testData)[number][number] + twMerge(...(testData[i] as Exclude[])) + } + }, + options, + ) + }) + } +})