mirror of
https://github.com/withastro/starlight.git
synced 2026-10-12 02:24:41 +00:00
Add benchmark for sidebar sublist processing (#4216)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { klona } from 'klona';
|
||||
import { bench, describe, vi } from 'vitest';
|
||||
import { getRouteDataTestContext } from '../__tests__/test-utils';
|
||||
import { generateRouteData } from '../src/utils/routing/data';
|
||||
import { getRouteBySlugParam } from '../src/utils/routing';
|
||||
import { getSidebar } from '../src/utils/navigation';
|
||||
import { flattenSidebar, getSidebar } from '../src/utils/navigation';
|
||||
import type { SidebarEntry } from '../src/utils/routing/types';
|
||||
|
||||
const docs = vi.hoisted(() => {
|
||||
const docs: [string, { title: string }][] = [];
|
||||
@@ -48,3 +50,17 @@ describe('routing', () => {
|
||||
getSidebar(context.url.pathname, route.locale);
|
||||
});
|
||||
});
|
||||
|
||||
/** Recursive function that simulates the heavier logic in `<SidebarSublist>` rendering. */
|
||||
function mockSidebarRender(sublist: SidebarEntry[]) {
|
||||
for (const entry of sublist) {
|
||||
if (entry.type !== 'link') {
|
||||
flattenSidebar(entry.entries).some((i) => i.isCurrent);
|
||||
mockSidebarRender(entry.entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bench('sidebar current groups', () => {
|
||||
mockSidebarRender(klona(getSidebar(context.url.pathname, route.locale)));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user