UNPKG

@testplane/storybook

Version:

Testplane plugin that enables runtime screenshot storybook tests autogeneration

53 lines 2.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.openStory = void 0; const play_function_error_1 = require("../play-function-error"); const testplane_open_story_1 = __importDefault(require("./testplane-open-story")); async function openStory(browser, story, storybookGlobals) { const browserConfig = await browser.getConfig(); const currentBrowserUrl = await browser.getUrl(); const iframeUrlObj = new URL(browserConfig.baseUrl); const currentUrlObj = new URL(currentBrowserUrl); const isOnStorybookPage = currentUrlObj.host === iframeUrlObj.host && currentUrlObj.pathname.includes("iframe.html"); const shouldRemount = isOnStorybookPage && currentUrlObj.searchParams.get("id") === story.id; if (!isOnStorybookPage) { const storybookIframeUrl = await getStorybookIframeUrl(browser); await browser.runStep("open storybook url", () => browser.url(storybookIframeUrl)); } await extendBrowserMeta(browser, story); return browser.runStep("wait story load", async () => { const storyLoadResult = await testplane_open_story_1.default.execute(browser, story.id, storybookGlobals, shouldRemount); if (storyLoadResult.loadError) { throw new Error(storyLoadResult.loadError); } if (storyLoadResult.playFunctionError) { throw new play_function_error_1.PlayFunctionError(storyLoadResult.playFunctionError); } if (!story.autoscreenshotSelector && !storyLoadResult.rootSelector) { throw new Error("Story root selector is not found"); } return storyLoadResult; }); } exports.openStory = openStory; async function getStorybookIframeUrl(browser) { const browserConfig = await browser.getConfig(); const iframeUrlObj = new URL(browserConfig.baseUrl); iframeUrlObj.searchParams.set("instrument", String(true)); iframeUrlObj.searchParams.set("viewMode", "story"); return iframeUrlObj.toString(); } async function extendBrowserMeta(browser, story) { const storybookIframeUrl = await getStorybookIframeUrl(browser); const urlObj = new URL(storybookIframeUrl); urlObj.searchParams.set("id", story.id); urlObj.searchParams.set("path", `/${story.type}/${story.id}`); browser.executionContext["@testplane/storybook-assertView-opts"] = story.assertViewOpts; await browser.setMeta("url", urlObj.toString().replace("iframe.html", "index.html")); await browser.setMeta("storyFile", story.importPath); } //# sourceMappingURL=index.js.map