-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Vue: Provide apiDescription in the manifest #35900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
16efb17
Vue: Provide apiDescription in the manifest
huang-julien 7e0add0
Merge branch 'next' into julien/vue-api-description
huang-julien bca609b
Update code/renderers/vue3/src/docgen/api-description.ts
huang-julien c1f0b56
Update code/renderers/vue3/src/docgen/api-description.ts
huang-julien 51ec080
chore: format
huang-julien 58dde85
Merge branch 'next' into julien/vue-api-description
huang-julien 56dbb65
fix: snapshots
huang-julien 5bd900f
Merge branch 'julien/vue-api-description' of https://github.com/story…
huang-julien fce39e5
Merge branch 'next' into julien/vue-api-description
huang-julien 4e0ac01
fix: snapshots
huang-julien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
201 changes: 201 additions & 0 deletions
201
code/lib/docgen-harness/src/vue3/vue3-api-description.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| import { readdirSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { createCheckerByJson } from 'vue-component-meta'; | ||
|
|
||
| import { buildApiDescription } from '../../../../renderers/vue3/src/docgen/api-description.ts'; | ||
| import { | ||
| CHECKER_OPTIONS, | ||
| collectComponentMetaSources, | ||
| } from '../../../../renderers/vue3/src/docgen/component-meta.ts'; | ||
|
|
||
| const fixturesDir = join(dirname(fileURLToPath(import.meta.url)), '__testfixtures__'); | ||
| const checker = createCheckerByJson(fixturesDir, { include: ['**/*'] }, CHECKER_OPTIONS); | ||
|
|
||
| async function apiDescriptionFor(fixtureCase: string): Promise<string | undefined> { | ||
| const testDir = join(fixturesDir, fixtureCase); | ||
| const [sfcFile] = readdirSync(testDir).filter((file) => file.endsWith('.vue')); | ||
| const sources = await collectComponentMetaSources(checker, join(testDir, sfcFile)); | ||
| const meta = sources.find((source) => source.exportName === 'default'); | ||
| return meta && buildApiDescription(meta); | ||
| } | ||
|
|
||
| describe('vue3 api description from real vue-component-meta output', () => { | ||
| it('props-basic-types', async () => { | ||
| expect(await apiDescriptionFor('props-basic-types')).toMatchInlineSnapshot(` | ||
| "## Props | ||
|
|
||
| \`\`\` | ||
| export type PropsBasicTypesProps = { | ||
| /** The main label text. */ | ||
| label: string; | ||
| /** | ||
| * How many times the label repeats. | ||
| * | ||
| * @default 1 | ||
| */ | ||
| count?: number; | ||
| /** | ||
| * Whether the control is enabled. | ||
| * | ||
| * @default false | ||
| */ | ||
| enabled?: boolean; | ||
| /** | ||
| * Plain string tags rendered after the label. | ||
| * | ||
| * @default [] | ||
| */ | ||
| tags?: string[]; | ||
| /** Arbitrary configuration object. */ | ||
| config?: { theme: string; dense: boolean; }; | ||
| /** Formats the count for display. */ | ||
| formatter?: ((value: number) => string); | ||
| /** Unique token for the instance. */ | ||
| token?: symbol; | ||
| /** Large numeric identifier. */ | ||
| big?: bigint; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
|
|
||
| it('v-model', async () => { | ||
| expect(await apiDescriptionFor('v-model')).toMatchInlineSnapshot(` | ||
| "## Models | ||
|
|
||
| Two-way bindings. Bind each one with the \`v-model\` syntax shown next to it — do not pass the prop and listen to its \`update:\` event separately. | ||
|
|
||
| \`\`\` | ||
| export type VModelInputModels = { | ||
| /** The text value controlled via the default v-model. */ | ||
| modelValue: string; // v-model="..." | ||
| /** Whether the box is checked, controlled via the named v-model. */ | ||
| checked?: boolean; // v-model:checked="..." | ||
| } | ||
| \`\`\` | ||
|
|
||
| ## Events | ||
|
|
||
| \`\`\` | ||
| export type VModelInputEvents = { | ||
| "update:checked": [value: boolean | undefined]; | ||
| /** Emitted when the text value changes. */ | ||
| "update:modelValue": [value: string]; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
|
|
||
| it('define-expose', async () => { | ||
| expect(await apiDescriptionFor('define-expose')).toMatchInlineSnapshot(` | ||
| "## Props | ||
|
|
||
| \`\`\` | ||
| export type DefineExposeProps = { | ||
| /** Visible label of the counter button. */ | ||
| label: string; | ||
| } | ||
| \`\`\` | ||
|
|
||
| ## Exposed | ||
|
|
||
| Available on the component instance through a template ref. | ||
|
|
||
| \`\`\` | ||
| export type DefineExposeExposed = { | ||
| /** How many times the button has been pressed. */ | ||
| count: number; | ||
| reset: () => void; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
|
|
||
| it('define-slots-with-props', async () => { | ||
| expect(await apiDescriptionFor('define-slots-with-props')).toMatchInlineSnapshot(` | ||
| "## Props | ||
|
|
||
| \`\`\` | ||
| export type DefineSlotsWithPropsProps = { | ||
| /** | ||
| * Visible label of the button. | ||
| * | ||
| * @default "Button" | ||
| */ | ||
| label?: string; | ||
| /** | ||
| * Whether the button is disabled. | ||
| * | ||
| * @default false | ||
| */ | ||
| disabled?: boolean; | ||
| } | ||
| \`\`\` | ||
|
|
||
| ## Slots | ||
|
|
||
| Each slot is typed with the props it passes to its content. | ||
|
|
||
| \`\`\` | ||
| export type DefineSlotsWithPropsSlots = { | ||
| /** Main content, rendered instead of the label. */ | ||
| default: any; | ||
| /** Icon rendered before the content. */ | ||
| icon: { size: string; }; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
|
|
||
| it('events-jsdoc', async () => { | ||
| expect(await apiDescriptionFor('events-jsdoc')).toMatchInlineSnapshot(` | ||
| "## Props | ||
|
|
||
| \`\`\` | ||
| export type EventsJsdocProps = { | ||
| /** Visible label. */ | ||
| label: string; | ||
| } | ||
| \`\`\` | ||
|
|
||
| ## Events | ||
|
|
||
| \`\`\` | ||
| export type EventsJsdocEvents = { | ||
| /** Emitted when the user cancels editing. */ | ||
| cancel: []; | ||
| /** Emitted when the user saves the current value. */ | ||
| save: [payload: { id: number; }]; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
|
|
||
| it('jsdoc-tags', async () => { | ||
| expect(await apiDescriptionFor('jsdoc-tags')).toMatchInlineSnapshot(` | ||
| "## Props | ||
|
|
||
| \`\`\` | ||
| export type JsdocTagsProps = { | ||
| /** | ||
| * Visible label. | ||
| * | ||
| * @deprecated Prefer \`title\`. | ||
| * @since 10.0 | ||
| */ | ||
| label?: string; | ||
| /** | ||
| * Preferred title text. | ||
| * | ||
| * @default "Untitled" | ||
| */ | ||
| title?: string; | ||
| } | ||
| \`\`\`" | ||
| `); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.