mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-28 07:09:50 +00:00
# Conflicts: # apps/docs/app/(home)/sponsors/data.tsx # apps/docs/app/(home)/uwu.tsx # apps/docs/app/og/[...slug]/generate.tsx # apps/docs/app/static.json/route.ts # apps/docs/content/blog/customise-ui.mdx # apps/docs/content/blog/mdx-v10-summary.mdx # apps/docs/content/blog/openapi-v9.mdx # apps/docs/content/blog/v15.mdx # apps/docs/content/blog/v16-2.mdx # apps/docs/content/docs/(framework)/deploying/static.mdx # apps/docs/content/docs/(framework)/integrations/content/custom.mdx # apps/docs/content/docs/(framework)/integrations/openapi/generate-files.mdx # apps/docs/content/docs/(framework)/integrations/openapi/server.mdx # apps/docs/content/docs/(framework)/integrations/story/client.story.tsx # apps/docs/content/docs/(framework)/integrations/story/index.mdx # apps/docs/content/docs/(framework)/integrations/story/next.mdx # apps/docs/content/docs/(framework)/search/orama.mdx # apps/docs/content/docs/(framework)/what-is-fumadocs.mdx # apps/docs/content/docs/cli/index.mdx # apps/docs/content/docs/headless/mdx/headings.mdx # apps/docs/content/docs/headless/mdx/rehype-code.mdx # apps/docs/content/docs/headless/mdx/remark-image.mdx # apps/docs/content/docs/headless/source-api/plugins.mdx # apps/docs/content/docs/mdx/(integrations)/loader/node.mdx # apps/docs/content/docs/mdx/global.mdx # apps/docs/content/docs/mdx/index.mdx # apps/docs/content/docs/ui/components/banner.mdx # apps/docs/content/docs/ui/components/graph-view.mdx # apps/docs/content/docs/ui/layouts/flux.mdx # apps/docs/content/docs/ui/layouts/home-layout.mdx # apps/docs/content/docs/ui/layouts/root-provider.mdx # apps/docs/content/docs/ui/theme.mdx # apps/docs/eslint.config.mjs # apps/docs/scripts/preload.ts # apps/docs/scripts/update-orama-index.ts # examples/openapi/README.md # examples/openapi/scripts/generate-docs.ts # examples/react-router-i18n/scripts/preload.ts # examples/tanstack-start-story/src/components/callout/story-client.tsx # packages/base-ui/scripts/compile-inline.utils.ts # packages/cli/src/build/index.ts # packages/core/src/content/md/frontmatter.ts # packages/create-app/scripts/update-git-repo.js # packages/create-app/scripts/update-git-repo.sh # packages/mdx-runtime/eslint.config.mjs # packages/openapi/scripts/compile-inline.utils.ts # packages/openapi/src/server/create.ts # packages/openapi/src/ui/full.tsx # packages/openapi/src/utils/process-document.ts # packages/press/waku.config.ts # packages/radix-ui/scripts/compile-inline.utils.ts
245 lines
6.2 KiB
TypeScript
245 lines
6.2 KiB
TypeScript
import { fileURLToPath } from 'node:url';
|
|
import * as path from 'node:path';
|
|
import { expect, test } from 'vitest';
|
|
import { z } from 'zod';
|
|
import { ValidationError } from '@/utils/validation';
|
|
import { defineCollections, defineConfig, defineDocs } from '@/config';
|
|
import { parseFrontmatter } from '@/utils/frontmatter';
|
|
import { buildConfig } from '@/config/build';
|
|
import { createCore } from '@/core';
|
|
import indexFile from '@/plugins/index-file';
|
|
import lastModified from '@/plugins/last-modified';
|
|
|
|
test('format errors', async () => {
|
|
const schema = z.object({
|
|
text: z.string(),
|
|
obj: z.object({
|
|
key: z.number(),
|
|
value: z.number(),
|
|
}),
|
|
value: z.string().max(4),
|
|
});
|
|
|
|
const result = await schema['~standard'].validate({
|
|
text: 4,
|
|
obj: {
|
|
value: 'string',
|
|
},
|
|
value: 'asfdfsdfsdfsd',
|
|
});
|
|
|
|
if (result.issues) {
|
|
const error = new ValidationError('in index.mdx:', result.issues);
|
|
|
|
expect(error.toString()).toMatchInlineSnapshot(`
|
|
"Error: in index.mdx::
|
|
text: Invalid input: expected string, received number
|
|
obj,key: Invalid input: expected number, received undefined
|
|
obj,value: Invalid input: expected number, received string
|
|
value: Too big: expected string to have <=4 characters"
|
|
`);
|
|
}
|
|
});
|
|
|
|
const baseDir = path.dirname(fileURLToPath(import.meta.url));
|
|
const cases: {
|
|
name: string;
|
|
config: Record<string, unknown>;
|
|
}[] = [
|
|
{
|
|
name: 'sync',
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
}),
|
|
blogs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
postprocess: {
|
|
extractLinkReferences: true,
|
|
},
|
|
}),
|
|
default: defineConfig({
|
|
plugins: [
|
|
lastModified({
|
|
versionControl: async () => new Date('2025-11-18'),
|
|
}),
|
|
],
|
|
}),
|
|
},
|
|
},
|
|
{
|
|
name: 'sync-meta',
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'meta',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
}),
|
|
},
|
|
},
|
|
{
|
|
name: 'async',
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
async: true,
|
|
}),
|
|
blogs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
postprocess: {
|
|
extractLinkReferences: true,
|
|
},
|
|
async: true,
|
|
}),
|
|
},
|
|
},
|
|
{
|
|
name: 'dynamic',
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
dynamic: true,
|
|
}),
|
|
blogs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
postprocess: {
|
|
extractLinkReferences: true,
|
|
},
|
|
dynamic: true,
|
|
}),
|
|
},
|
|
},
|
|
{
|
|
name: 'dynamic-docs',
|
|
config: {
|
|
docs: defineDocs({
|
|
dir: path.join(baseDir, './fixtures/generate-index-docs'),
|
|
docs: {
|
|
dynamic: true,
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
{
|
|
name: 'workspace',
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'doc',
|
|
dir: path.join(baseDir, './fixtures/generate-index'),
|
|
}),
|
|
default: defineConfig({
|
|
workspaces: {
|
|
test: {
|
|
dir: path.join(baseDir, './fixtures/generate-index-2'),
|
|
config: {
|
|
docs: defineCollections({
|
|
type: 'doc',
|
|
dir: '.',
|
|
async: true,
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
];
|
|
|
|
for (const { name, config } of cases) {
|
|
test(`generate JS index file: ${name}`, async () => {
|
|
const core = createCore({
|
|
configPath: path.relative(process.cwd(), path.join(baseDir, './fixtures/config.ts')),
|
|
environment: 'test',
|
|
outDir: path.relative(process.cwd(), path.join(baseDir, './fixtures')),
|
|
plugins: [indexFile()],
|
|
});
|
|
|
|
await core.init({
|
|
config: buildConfig(config, process.cwd()),
|
|
});
|
|
|
|
const { entries, workspaces } = await core.emit();
|
|
for (const [name, workspace] of Object.entries(workspaces)) {
|
|
for (const item of workspace) {
|
|
item.path = path.join(name, item.path);
|
|
entries.push(item);
|
|
}
|
|
}
|
|
const markdown = entries
|
|
.map((entry) => `\`\`\`ts title="${entry.path}"\n${entry.content}\n\`\`\``)
|
|
.join('\n\n');
|
|
|
|
if (name === 'dynamic') {
|
|
expect(markdown).toContain(`import path from 'node:path';`);
|
|
expect(markdown).toContain(
|
|
'create.doc("docs", "packages/mdx/test/fixtures/generate-index", [',
|
|
);
|
|
expect(markdown).toContain(
|
|
'create.doc("blogs", "packages/mdx/test/fixtures/generate-index", [',
|
|
);
|
|
}
|
|
|
|
if (name === 'dynamic-docs') {
|
|
expect(markdown).toContain(`import path from 'node:path';`);
|
|
expect(markdown).toMatch(
|
|
/create\.docs\("docs", "packages\/mdx\/test\/fixtures\/generate-index-docs", [\s\S]+, \[/,
|
|
);
|
|
}
|
|
|
|
await expect(markdown).toMatchFileSnapshot(`./fixtures/index-${name}.output.md`);
|
|
});
|
|
}
|
|
|
|
test('parse frontmatter', () => {
|
|
expect(parseFrontmatter('---\ntitle: hello world\ndescription: I love Fumadocs\n---\nwow looks cool.'))
|
|
.toMatchInlineSnapshot(`
|
|
{
|
|
"content": "wow looks cool.",
|
|
"data": {
|
|
"description": "I love Fumadocs",
|
|
"title": "hello world",
|
|
},
|
|
"matter": "---
|
|
title: hello world
|
|
description: I love Fumadocs
|
|
---
|
|
",
|
|
}
|
|
`);
|
|
|
|
expect(
|
|
parseFrontmatter(
|
|
'---\r\ntitle: hello world\r\ndescription: I love Fumadocs\r\n---\r\nwow looks cool.',
|
|
),
|
|
).toMatchInlineSnapshot(`
|
|
{
|
|
"content": "wow looks cool.",
|
|
"data": {
|
|
"description": "I love Fumadocs",
|
|
"title": "hello world",
|
|
},
|
|
"matter": "---
|
|
title: hello world
|
|
description: I love Fumadocs
|
|
---
|
|
",
|
|
}
|
|
`);
|
|
|
|
expect(parseFrontmatter('--- \ntitle: hello world\r\n---\r\nwow looks cool.')).toMatchInlineSnapshot(`
|
|
{
|
|
"content": "---
|
|
title: hello world
|
|
---
|
|
wow looks cool.",
|
|
"data": {},
|
|
"matter": "",
|
|
}
|
|
`);
|
|
});
|