UNPKG

@mintlify/previewing

Version:

Preview Mintlify docs locally

100 lines (99 loc) 3.76 kB
import { beforeEach, describe, expect, it } from 'vitest'; import { clearDocsConfigCaches, getDocsConfigApiHash, getDocsConfigNavigationHash, getVariablesHash, hasDocsConfigApiChanged, hasDocsConfigNavigationChanged, hasNavigationApiReference, hadDocsConfigApiReference, hasDocsConfigVariablesChanged, updateDocsConfigHashCache, } from '../local-preview/listener/docs-config-cache.js'; const createDocsConfig = (page) => ({ $schema: 'https://mintlify.com/docs.json', name: 'Mintlify', theme: 'mint', colors: { primary: '#16A34A', }, navigation: { pages: [page], }, }); describe('docsConfigCache', () => { beforeEach(() => { clearDocsConfigCaches(); }); it('tracks api, navigation, and variables hash changes independently', () => { const docsConfig = { ...createDocsConfig('raw-page'), api: { openapi: 'openapi.json', }, variables: { product: 'Mintlify', }, }; updateDocsConfigHashCache(docsConfig); expect(hasDocsConfigApiChanged(getDocsConfigApiHash(docsConfig))).toBe(false); expect(hasDocsConfigNavigationChanged(getDocsConfigNavigationHash(docsConfig))).toBe(false); expect(hasDocsConfigVariablesChanged(getVariablesHash(docsConfig.variables))).toBe(false); expect(hasDocsConfigApiChanged(getDocsConfigApiHash(createDocsConfig('raw-page')))).toBe(true); expect(hasDocsConfigNavigationChanged(getDocsConfigNavigationHash(createDocsConfig('new-page')))).toBe(true); expect(hasDocsConfigVariablesChanged(getVariablesHash({ product: 'Mint' }))).toBe(true); }); it('detects API references anywhere in navigation', () => { expect(hasNavigationApiReference({ groups: [ { group: 'API', openapi: 'openapi.json', }, ], })).toBe(true); expect(hasNavigationApiReference({ tabs: [ { tab: 'Realtime', groups: [ { group: 'Events', asyncapi: 'asyncapi.json', }, ], }, ], })).toBe(true); expect(hasNavigationApiReference({ tabs: [ { tab: 'Realtime', asyncapi: 'asyncapi.json', groups: [ { group: 'Events', asyncapi: 'asyncapi.json', }, ], }, ], })).toBe(true); expect(hasNavigationApiReference({ tabs: [ { tab: 'GraphQL', graphql: { source: 'schema.graphql', directory: 'reference' }, }, ], })).toBe(true); }); it('allows plain MDX navigation through the navigation fast path', () => { expect(hasNavigationApiReference({ groups: [ { group: 'Guides', pages: ['quickstart', 'install'], }, ], })).toBe(false); }); it('remembers API references so removing the last generated source triggers cleanup', () => { const docsConfig = { ...createDocsConfig('raw-page'), navigation: { tabs: [{ tab: 'GraphQL', graphql: 'schema.graphql' }] }, }; updateDocsConfigHashCache(docsConfig); expect(hadDocsConfigApiReference()).toBe(true); }); });