-
-
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 branch 'next' into kasper/fix-attach-spy
- Loading branch information
Showing
41 changed files
with
458 additions
and
219 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
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
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
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
55 changes: 29 additions & 26 deletions
55
code/builders/builder-vite/src/plugins/inject-export-order-plugin.ts
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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import { parse } from 'es-module-lexer'; | ||
import MagicString from 'magic-string'; | ||
import { createFilter } from 'vite'; | ||
|
||
const include = [/\.stories\.([tj])sx?$/, /(stories|story).mdx$/]; | ||
const filter = createFilter(include); | ||
export async function injectExportOrderPlugin() { | ||
const { createFilter } = await import('vite'); | ||
|
||
export const injectExportOrderPlugin = { | ||
name: 'storybook:inject-export-order-plugin', | ||
// This should only run after the typescript has been transpiled | ||
enforce: 'post', | ||
async transform(code: string, id: string) { | ||
if (!filter(id)) return undefined; | ||
const include = [/\.stories\.([tj])sx?$/, /(stories|story).mdx$/]; | ||
const filter = createFilter(include); | ||
|
||
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object, | ||
// and run `await init;` once and then call `parse()` without `await`, | ||
// instead of calling `await parse()` every time. | ||
const [, exports] = await parse(code); | ||
return { | ||
name: 'storybook:inject-export-order-plugin', | ||
// This should only run after the typescript has been transpiled | ||
enforce: 'post', | ||
async transform(code: string, id: string) { | ||
if (!filter(id)) return undefined; | ||
|
||
if (exports.includes('__namedExportsOrder')) { | ||
// user has defined named exports already | ||
return undefined; | ||
} | ||
const s = new MagicString(code); | ||
const orderedExports = exports.filter((e) => e !== 'default'); | ||
s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`); | ||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: true, source: id }), | ||
}; | ||
}, | ||
}; | ||
// TODO: Maybe convert `injectExportOrderPlugin` to function that returns object, | ||
// and run `await init;` once and then call `parse()` without `await`, | ||
// instead of calling `await parse()` every time. | ||
const [, exports] = await parse(code); | ||
|
||
if (exports.includes('__namedExportsOrder')) { | ||
// user has defined named exports already | ||
return undefined; | ||
} | ||
const s = new MagicString(code); | ||
const orderedExports = exports.filter((e) => e !== 'default'); | ||
s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`); | ||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: true, source: id }), | ||
}; | ||
}, | ||
}; | ||
} |
5 changes: 3 additions & 2 deletions
5
code/builders/builder-vite/src/plugins/strip-story-hmr-boundaries.ts
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
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
Oops, something went wrong.