Skip to content

Commit 34e737e

Browse files
fix: acknowledge safari & webpack quirks
1 parent 4a0f84e commit 34e737e

File tree

2 files changed

+12
-49
lines changed

2 files changed

+12
-49
lines changed

src/storybook/story-test-runner/open-story/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export async function openStory(
2323
const storybookIframeUrl = await getStorybookIframeUrl(browser);
2424

2525
await browser.runStep("open storybook url", () => browser.url(storybookIframeUrl));
26-
await browser.runStep("inject script", () => testplaneOpenStory.inject(browser));
2726
}
2827

2928
await extendBrowserMeta(browser, story);

src/storybook/story-test-runner/open-story/testplane-open-story.ts

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export interface StoryLoadResult {
44
rootSelector: string;
55
playFunctionError?: string;
66
loadError?: string;
7-
notInjected?: true;
87
}
98

109
interface HTMLElement {
@@ -13,12 +12,6 @@ interface HTMLElement {
1312

1413
export type StorybookWindow = Window &
1514
typeof globalThis & {
16-
__HERMIONE_OPEN_STORY__: (
17-
storyId: string,
18-
storybookGlobals: Record<string, unknown>,
19-
remountOnly: boolean,
20-
done: (result: string) => void,
21-
) => void;
2215
__TESTPLANE_STORYBOOK_INITIAL_GLOBALS__?: Record<string, unknown>;
2316
__STORYBOOK_PREVIEW__?: { storeInitializationPromise?: Promise<void> };
2417
__STORYBOOK_ADDONS_CHANNEL__: EventEmitter & {
@@ -36,38 +29,6 @@ export type StorybookWindow = Window &
3629
>;
3730
};
3831

39-
export async function inject(browser: WebdriverIO.Browser): Promise<void> {
40-
await browser.execute(`window.__HERMIONE_OPEN_STORY__ = ${openStoryScript.toString()}`);
41-
}
42-
43-
export async function execute(
44-
browser: WebdriverIO.Browser,
45-
storyId: string,
46-
storybookGlobals: Record<string, unknown>,
47-
shouldRemount: boolean,
48-
): Promise<StoryLoadResult> {
49-
const getResult = (): Promise<StoryLoadResult> =>
50-
browser.executeAsync(executeOpenStoryScript, storyId, storybookGlobals, shouldRemount).then(JSON.parse);
51-
52-
const result: StoryLoadResult = await getResult();
53-
54-
if (!result.notInjected) {
55-
return result;
56-
}
57-
58-
await inject(browser);
59-
60-
const retriedResult = await getResult();
61-
62-
if (retriedResult.notInjected) {
63-
throw new Error("Can't inject client script");
64-
}
65-
66-
return retriedResult;
67-
}
68-
69-
export default { inject, execute };
70-
7132
function openStoryScript(
7233
storyId: string,
7334
storybookGlobals: Record<string, unknown>,
@@ -201,15 +162,18 @@ function openStoryScript(
201162
});
202163
}
203164

204-
function executeOpenStoryScript(
165+
export async function execute(
166+
browser: WebdriverIO.Browser,
205167
storyId: string,
206168
storybookGlobals: Record<string, unknown>,
207-
remountOnly: boolean,
208-
done: (result: string) => void,
209-
): void {
210-
if ((window as StorybookWindow).__HERMIONE_OPEN_STORY__) {
211-
(window as StorybookWindow).__HERMIONE_OPEN_STORY__(storyId, storybookGlobals, remountOnly, done);
212-
} else {
213-
done(JSON.stringify({ notInjected: true }));
214-
}
169+
shouldRemount: boolean,
170+
): Promise<StoryLoadResult> {
171+
const getResult = ({ disableRemount = false } = {}): Promise<StoryLoadResult> =>
172+
browser
173+
.executeAsync(openStoryScript, storyId, storybookGlobals, shouldRemount && !disableRemount)
174+
.then(JSON.parse);
175+
176+
return getResult().catch(() => getResult({ disableRemount: true }));
215177
}
178+
179+
export default { execute };

0 commit comments

Comments
 (0)