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: ''
+ template: ''
})`
);
await preview.show("src/Button.stories.js:Primary");
await preview.iframe.waitForSelector(
- "xpath=//button[contains(., 'Button')]"
+ "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!')]"
);
});
@@ -79,6 +86,13 @@ test.describe.parallel("vue2/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 templated CSF2 story", async (preview) => {
@@ -106,6 +120,13 @@ test.describe.parallel("vue2/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 templated CSF2 story with assignment source referring local variable", async (preview) => {
@@ -142,6 +163,13 @@ test.describe.parallel("vue2/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 implicit template", async (preview) => {
@@ -168,9 +196,16 @@ test.describe.parallel("vue2/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 default args", async (preview) => {
+ test("renders CSF2 story with default export args", async (preview) => {
await preview.fileManager.update("src/Button.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -179,7 +214,7 @@ test.describe.parallel("vue2/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
}
@@ -193,11 +228,18 @@ test.describe.parallel("vue2/storybook", () => {
);
await preview.show("src/Button.stories.js:Primary");
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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -206,7 +248,7 @@ test.describe.parallel("vue2/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
}
@@ -224,6 +266,13 @@ test.describe.parallel("vue2/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) => {
@@ -246,6 +295,13 @@ test.describe.parallel("vue2/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) => {
@@ -277,9 +333,16 @@ test.describe.parallel("vue2/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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -288,7 +351,7 @@ test.describe.parallel("vue2/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
};
@@ -296,11 +359,18 @@ test.describe.parallel("vue2/storybook", () => {
);
await preview.show("src/Button.stories.js:Primary");
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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -309,7 +379,7 @@ test.describe.parallel("vue2/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
};
@@ -323,6 +393,13 @@ test.describe.parallel("vue2/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("detects when CSF2 story no longer available", async (preview) => {
diff --git a/framework-plugins/vue3/tests/storybook.spec.ts b/framework-plugins/vue3/tests/storybook.spec.ts
index 40133b3caea7..279d12be2333 100644
--- a/framework-plugins/vue3/tests/storybook.spec.ts
+++ b/framework-plugins/vue3/tests/storybook.spec.ts
@@ -45,12 +45,19 @@ test.describe.parallel("vue3/storybook", () => {
export const Primary = () => ({
components: { Button },
- template: ''
+ template: ''
})`
);
await preview.show("src/Button.stories.js:Primary");
await preview.iframe.waitForSelector(
- "xpath=//button[contains(., 'Button')]"
+ "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!')]"
);
});
@@ -81,6 +88,13 @@ test.describe.parallel("vue3/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 templated CSF2 story", async (preview) => {
@@ -110,6 +124,13 @@ test.describe.parallel("vue3/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 templated CSF2 story with assignment source referring local variable", async (preview) => {
@@ -148,9 +169,16 @@ test.describe.parallel("vue3/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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -159,7 +187,7 @@ test.describe.parallel("vue3/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
}
@@ -176,11 +204,18 @@ test.describe.parallel("vue3/storybook", () => {
);
await preview.show("src/Button.stories.js:Primary");
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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -189,7 +224,7 @@ test.describe.parallel("vue3/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
}
@@ -210,6 +245,13 @@ test.describe.parallel("vue3/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) => {
@@ -232,6 +274,13 @@ test.describe.parallel("vue3/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) => {
@@ -263,9 +312,16 @@ test.describe.parallel("vue3/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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -274,7 +330,7 @@ test.describe.parallel("vue3/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
};
@@ -282,11 +338,18 @@ test.describe.parallel("vue3/storybook", () => {
);
await preview.show("src/Button.stories.js:Primary");
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.vue", buttonVueSource);
await preview.fileManager.update(
"src/Button.stories.js",
@@ -295,7 +358,7 @@ test.describe.parallel("vue3/storybook", () => {
export default {
component: Button,
args: {
- label: "default"
+ label: "default export"
}
};
@@ -309,6 +372,13 @@ test.describe.parallel("vue3/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("detects when CSF2 story no longer available", async (preview) => {
diff --git a/iframe/preview/__previewjs_internal__/vite-hmr-listener.ts b/iframe/preview/__previewjs_internal__/vite-hmr-listener.ts
index 336e0099ba09..5de0b7f714d0 100644
--- a/iframe/preview/__previewjs_internal__/vite-hmr-listener.ts
+++ b/iframe/preview/__previewjs_internal__/vite-hmr-listener.ts
@@ -64,6 +64,8 @@ export function setupViteHmrListener() {
window.__PREVIEWJS_IFRAME__.reportEvent({
kind: "vite-invalidate",
});
- window.__PREVIEWJS_IFRAME__.refresh();
+ window.__PREVIEWJS_IFRAME__.refresh({
+ refetchPreviewableModule: true,
+ });
});
}
diff --git a/iframe/src/index.ts b/iframe/src/index.ts
index 160cd0edb809..30277428258c 100644
--- a/iframe/src/index.ts
+++ b/iframe/src/index.ts
@@ -19,6 +19,7 @@ declare global {
}
export type RefreshOptions = {
+ refetchPreviewableModule?: boolean;
previewableModule?: any;
wrapperModule?: any;
};