diff --git a/core/src/vite/plugins/preview-script.ts b/core/src/vite/plugins/preview-script.ts index 81accbbe3410..e354d02aa01f 100644 --- a/core/src/vite/plugins/preview-script.ts +++ b/core/src/vite/plugins/preview-script.ts @@ -44,6 +44,12 @@ let refresh = () => {}; window.__PREVIEWJS_IFRAME__.refresh = (options) => { refresh(options); + if (options.refetchPreviewableModule) { + loadFreshPreviewableModule().then(previewableModule => refresh({ + ...options, + previewableModule, + })); + } }; import.meta.hot.accept(["/${previewablePath}"], ([previewableModule]) => { @@ -82,7 +88,7 @@ const wrapperModulePromise = Promise.all([${detectedGlobalCssFilePaths // Important: the wrapper must be loaded first as it may monkey-patch // modules imported by the component module. wrapperModulePromise.then(wrapperModule => { - import(/* @vite-ignore */ "/${previewablePath}?t=" + Date.now()).then(previewableModule => { + loadFreshPreviewableModule().then(previewableModule => { refresh = initPreview({ previewableModule, previewableName: ${JSON.stringify(previewableName)}, @@ -91,5 +97,9 @@ wrapperModulePromise.then(wrapperModule => { }); }); }); + +function loadFreshPreviewableModule() { + return import(/* @vite-ignore */ "/${previewablePath}?t=" + Date.now()); +} `; } diff --git a/framework-plugins/preact/tests/storybook.spec.ts b/framework-plugins/preact/tests/storybook.spec.ts index c23ad10d909a..f20f3daf0a50 100644 --- a/framework-plugins/preact/tests/storybook.spec.ts +++ b/framework-plugins/preact/tests/storybook.spec.ts @@ -25,6 +25,13 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with explicit args", async (preview) => { @@ -45,6 +52,13 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with assignment source referring local variable", async (preview) => { @@ -74,9 +88,16 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); - test("renders CSF2 story with default args", async (preview) => { + test("renders CSF2 story with default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -84,7 +105,7 @@ test.describe.parallel("preact/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -92,11 +113,18 @@ test.describe.parallel("preact/storybook", () => { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); - test("renders CSF2 story with explicit args over default args", async (preview) => { + test("renders CSF2 story with explicit args over default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -104,7 +132,7 @@ test.describe.parallel("preact/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -117,6 +145,13 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with explicit args", async (preview) => { @@ -138,6 +173,13 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with assignment source referring local variable", async (preview) => { @@ -168,9 +210,16 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); - test("renders CSF3 story with default args", async (preview) => { + test("renders CSF3 story with default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -178,7 +227,7 @@ test.describe.parallel("preact/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } } @@ -186,11 +235,18 @@ test.describe.parallel("preact/storybook", () => { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); - test("renders CSF3 story with explicit args over default args", async (preview) => { + test("renders CSF3 story with explicit args over default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -198,7 +254,7 @@ test.describe.parallel("preact/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -212,6 +268,13 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with render function", async (preview) => { @@ -234,5 +297,12 @@ test.describe.parallel("preact/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); }); diff --git a/framework-plugins/react/tests/storybook.spec.ts b/framework-plugins/react/tests/storybook.spec.ts index 3f2541faf544..c1cf913c73fb 100644 --- a/framework-plugins/react/tests/storybook.spec.ts +++ b/framework-plugins/react/tests/storybook.spec.ts @@ -30,6 +30,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with explicit args", async (preview) => { @@ -50,6 +57,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with assignment source referring local variable", async (preview) => { @@ -79,6 +93,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with default args", async (preview) => { @@ -89,7 +110,7 @@ for (const reactVersion of reactVersions()) { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -97,7 +118,14 @@ for (const reactVersion of reactVersions()) { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); @@ -109,7 +137,7 @@ for (const reactVersion of reactVersions()) { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -122,6 +150,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with explicit args", async (preview) => { @@ -143,6 +178,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with assignment source referring local variable", async (preview) => { @@ -173,6 +215,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with default args", async (preview) => { @@ -183,7 +232,7 @@ for (const reactVersion of reactVersions()) { export default { component: Button, args: { - label: "default" + label: "default export" } } @@ -191,7 +240,14 @@ for (const reactVersion of reactVersions()) { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); @@ -203,7 +259,7 @@ for (const reactVersion of reactVersions()) { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -217,6 +273,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with render function", async (preview) => { @@ -239,6 +302,13 @@ for (const reactVersion of reactVersions()) { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); }); }); diff --git a/framework-plugins/solid/tests/storybook.spec.ts b/framework-plugins/solid/tests/storybook.spec.ts index 438ac343bb87..d0c3af8949c2 100644 --- a/framework-plugins/solid/tests/storybook.spec.ts +++ b/framework-plugins/solid/tests/storybook.spec.ts @@ -25,6 +25,13 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with explicit args", async (preview) => { @@ -45,6 +52,13 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF2 story with assignment source referring local variable", async (preview) => { @@ -74,9 +88,16 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); - test("renders CSF2 story with default args", async (preview) => { + test("renders CSF2 story with default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -84,7 +105,7 @@ test.describe.parallel("solid/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -92,11 +113,18 @@ test.describe.parallel("solid/storybook", () => { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); - test("renders CSF2 story with explicit args over default args", async (preview) => { + test("renders CSF2 story with explicit args over default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -104,7 +132,7 @@ test.describe.parallel("solid/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -117,6 +145,13 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with explicit args", async (preview) => { @@ -138,6 +173,13 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with assignment source referring local variable", async (preview) => { @@ -168,9 +210,16 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'local value')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "local value", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); - test("renders CSF3 story with default args", async (preview) => { + test("renders CSF3 story with default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -178,7 +227,7 @@ test.describe.parallel("solid/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } } @@ -186,11 +235,18 @@ test.describe.parallel("solid/storybook", () => { ); await preview.show("src/Button.tsx:ButtonStory"); await preview.iframe.waitForSelector( - "xpath=//button[contains(., 'default')]" + "xpath=//button[contains(., 'default export')]" + ); + await preview.fileManager.update("src/Button.tsx", { + replace: "default export", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" ); }); - test("renders CSF3 story with explicit args over default args", async (preview) => { + test("renders CSF3 story with explicit args over default export args", async (preview) => { await preview.fileManager.update( "src/Button.tsx", `const Button = ({ label }) => ; @@ -198,7 +254,7 @@ test.describe.parallel("solid/storybook", () => { export default { component: Button, args: { - label: "default" + label: "default export" } }; @@ -212,6 +268,13 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'explicit')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "explicit", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); test("renders CSF3 story with render function", async (preview) => { @@ -234,5 +297,12 @@ test.describe.parallel("solid/storybook", () => { await preview.iframe.waitForSelector( "xpath=//button[contains(., 'Hello, World!')]" ); + await preview.fileManager.update("src/Button.tsx", { + replace: "Hello, World!", + with: "Hi, World!", + }); + await preview.iframe.waitForSelector( + "xpath=//button[contains(., 'Hi, World!')]" + ); }); }); diff --git a/framework-plugins/vue2/tests/storybook.spec.ts b/framework-plugins/vue2/tests/storybook.spec.ts index de108ff958c6..66404743cd8f 100644 --- a/framework-plugins/vue2/tests/storybook.spec.ts +++ b/framework-plugins/vue2/tests/storybook.spec.ts @@ -45,12 +45,19 @@ test.describe.parallel("vue2/storybook", () => { export const Primary = () => ({ components: { Button }, - template: '