-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24096 from j3rem1e/bug/24008
Svelte: Fix docs generating when using `lang="ts"` or optional chaining
- Loading branch information
Showing
14 changed files
with
245 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,40 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
import { test, expect } from '@playwright/test'; | ||
import process from 'process'; | ||
import { SbPage } from './util'; | ||
|
||
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:6006'; | ||
const templateName = process.env.STORYBOOK_TEMPLATE_NAME; | ||
|
||
test.describe('Svelte', () => { | ||
test.skip( | ||
// eslint-disable-next-line jest/valid-title | ||
!templateName?.includes('svelte'), | ||
'Only run this test on Svelte' | ||
); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(storybookUrl); | ||
await new SbPage(page).waitUntilLoaded(); | ||
}); | ||
|
||
test('JS story has auto-generated args table', async ({ page }) => { | ||
const sbPage = new SbPage(page); | ||
|
||
await sbPage.navigateToStory('stories/renderers/svelte/js-docs', 'docs'); | ||
const root = sbPage.previewRoot(); | ||
const argsTable = root.locator('.docblock-argstable'); | ||
await expect(argsTable).toContainText('Rounds the button'); | ||
}); | ||
|
||
test('TS story has auto-generated args table', async ({ page }) => { | ||
// eslint-disable-next-line jest/valid-title | ||
test.skip(!templateName?.endsWith('ts') || false, 'Only test TS story in TS templates'); | ||
const sbPage = new SbPage(page); | ||
|
||
await sbPage.navigateToStory('stories/renderers/svelte/ts-docs', 'docs'); | ||
const root = sbPage.previewRoot(); | ||
const argsTable = root.locator('.docblock-argstable'); | ||
await expect(argsTable).toContainText('Rounds the button'); | ||
}); | ||
}); |
This file contains 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
This file contains 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
38 changes: 38 additions & 0 deletions
38
code/frameworks/svelte-vite/template/stories_svelte-vite-default-ts/ButtonTypeScript.svelte
This file contains 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,38 @@ | ||
<script lang="ts"> | ||
/** | ||
* @component Button TypeScript | ||
* @wrapper | ||
*/ | ||
import { global as globalThis } from '@storybook/global'; | ||
// @ts-ignore | ||
const Button = globalThis.Components?.Button; | ||
/** | ||
* Rounds the button | ||
*/ | ||
export let primary: boolean = false; | ||
/** | ||
* Displays the count | ||
*/ | ||
export let count: number = 0; | ||
/** | ||
* Button text | ||
* @slot | ||
*/ | ||
export let text: string = 'You clicked'; | ||
function handleClick(_event: MouseEvent) { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<h1>Button TypeScript</h1> | ||
|
||
<Button {primary} on:click on:click={handleClick} label="{text}: {count}" /> | ||
|
||
<p>A little text to show this is a view.</p> | ||
<p>If we need to test components in a Svelte environment, for instance to test slot behaviour,</p> | ||
<p>then wrapping the component up in a view</p> | ||
<p>made just for the story is the simplest way to achieve this.</p> |
12 changes: 12 additions & 0 deletions
12
code/frameworks/svelte-vite/template/stories_svelte-vite-default-ts/ts-docs.stories.js
This file contains 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,12 @@ | ||
import ButtonTypescript from './ButtonTypeScript.svelte'; | ||
|
||
export default { | ||
title: 'stories/renderers/svelte/ts-docs', | ||
component: ButtonTypescript, | ||
args: { | ||
primary: true, | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export const Primary = {}; |
38 changes: 38 additions & 0 deletions
38
code/frameworks/sveltekit/template/stories_svelte-kit-skeleton-ts/ButtonTypeScript.svelte
This file contains 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,38 @@ | ||
<script lang="ts"> | ||
/** | ||
* @component Button TypeScript | ||
* @wrapper | ||
*/ | ||
import { global as globalThis } from '@storybook/global'; | ||
// @ts-ignore | ||
const Button = globalThis.Components?.Button; | ||
/** | ||
* Rounds the button | ||
*/ | ||
export let primary: boolean = false; | ||
/** | ||
* Displays the count | ||
*/ | ||
export let count: number = 0; | ||
/** | ||
* Button text | ||
* @slot | ||
*/ | ||
export let text: string = 'You clicked'; | ||
function handleClick(_event: MouseEvent) { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<h1>Button TypeScript</h1> | ||
|
||
<Button {primary} on:click on:click={handleClick} label="{text}: {count}" /> | ||
|
||
<p>A little text to show this is a view.</p> | ||
<p>If we need to test components in a Svelte environment, for instance to test slot behaviour,</p> | ||
<p>then wrapping the component up in a view</p> | ||
<p>made just for the story is the simplest way to achieve this.</p> |
12 changes: 12 additions & 0 deletions
12
code/frameworks/sveltekit/template/stories_svelte-kit-skeleton-ts/ts-docs.stories.js
This file contains 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,12 @@ | ||
import ButtonTypescript from './ButtonTypeScript.svelte'; | ||
|
||
export default { | ||
title: 'stories/renderers/svelte/ts-docs', | ||
component: ButtonTypescript, | ||
args: { | ||
primary: true, | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export const Primary = {}; |
This file contains 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
This file contains 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
This file contains 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,11 @@ | ||
import ButtonJavaScript from './views/ButtonJavaScript.svelte'; | ||
|
||
export default { | ||
component: ButtonJavaScript, | ||
args: { | ||
primary: true, | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export const Primary = {}; |
2 changes: 1 addition & 1 deletion
2
code/renderers/svelte/template/stories/slot-decorators.stories.js
This file contains 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
This file contains 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
This file contains 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
This file contains 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