Skip to content

Commit

Permalink
adding support for storybook v8
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed Apr 12, 2024
1 parent 64ae1be commit 41ae1ba
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .changeset/blue-bugs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@pixeleye/cli-capture": patch
"@pixeleye/cli-devices": patch
"@pixeleye/cli-install": patch
"@pixeleye/cli-logger": patch
"@pixeleye/cli-booth": patch
"@pixeleye/cli-image": patch
"pixeleye": patch
"@pixeleye/cli-api": patch
"@pixeleye/cli-env": patch
"@pixeleye/playwright": patch
"@pixeleye/puppeteer": patch
"@pixeleye/storybook": patch
"@pixeleye/cypress": patch
---

Updated dependencies
5 changes: 5 additions & 0 deletions .changeset/sweet-rabbits-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pixeleye/storybook": minor
---

Added support for storybook v8
4 changes: 4 additions & 0 deletions integrations/cli/pixeleye/src/handlers/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import {
waitForProcessing,
watchExit,
} from "./utils";
import { setEnv } from "@pixeleye/cli-env";

export async function storybook(url: string, options: Config) {
// Lets our integrations know we are running in a Pixeleye environment
setEnv("PIXELEYE_RUNNING", "true");

const api = API({
endpoint: options.endpoint!,
token: options.token,
Expand Down
5 changes: 5 additions & 0 deletions integrations/storybook/src/browser/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export type SBWindow = typeof window & {
__STORYBOOK_CLIENT_API__: API;
__STORYBOOK_PREVIEW__: {
channel: Channel;
storyStoreValue?: {
cacheAllCSFFiles: () => Promise<void>;
cachedCSFFiles?: Record<string, unknown>;
extract: () => RawStory[];
};
};
};

Expand Down
30 changes: 21 additions & 9 deletions integrations/storybook/src/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,35 @@ export async function captureStories({
"/iframe.html?selectedKind=story-crawler-kind&selectedStory=story-crawler-story",
{
timeout: 120_000,
waitUntil: "domcontentloaded",
}
);

await page.waitForFunction(
() => (window as SBWindow).__STORYBOOK_CLIENT_API__,
{
timeout: 60_000,
}
);
await Promise.race([
page
.waitForFunction(() => (window as SBWindow).__STORYBOOK_CLIENT_API__, {
timeout: 60_000,
})
.catch(() => {}),
page
.waitForFunction(() => (window as SBWindow).__STORYBOOK_PREVIEW__, {
timeout: 60_000,
})
.catch(() => {}),
]);

const result = await page.evaluate(async () => {
const { __STORYBOOK_CLIENT_API__: api } = window as SBWindow;
const { __STORYBOOK_CLIENT_API__, __STORYBOOK_PREVIEW__ } =
window as SBWindow;

const store =
__STORYBOOK_CLIENT_API__?._storyStore ||
__STORYBOOK_PREVIEW__?.storyStoreValue!;

await api._storyStore?.cacheAllCSFFiles();
await store.cacheAllCSFFiles();

return {
stories: Object.values(api._storyStore?.extract() || {}).map(
stories: Object.values(store.extract() || {}).map(
({ id, story, kind, parameters: { pixeleye } }) => ({
id,
story,
Expand Down

0 comments on commit 41ae1ba

Please sign in to comment.