UNPKG

@testplane/storybook

Version:

Testplane plugin that enables runtime screenshot storybook tests autogeneration

58 lines 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = exports.getAbsoluteFilePath = void 0; const extend_stories_1 = require("./extend-stories"); const test_decorators_1 = require("./test-decorators"); const open_story_1 = require("./open-story"); const inheritable_values_1 = require("./inheritable-values"); function getAbsoluteFilePath() { return __filename; } exports.getAbsoluteFilePath = getAbsoluteFilePath; // Those stories must be from a single story file function run(stories, opts) { const withStoryFileDataStories = (0, extend_stories_1.extendStoriesFromStoryFile)(stories); withStoryFileDataStories.forEach(story => createTestplaneTests(story, opts)); } exports.run = run; function createTestplaneTests(story, { autoScreenshots, autoscreenshotSelector, autoScreenshotStorybookGlobals }) { (0, test_decorators_1.nestedDescribe)(story, () => { var _a; const rawAutoScreenshotGlobalSets = (0, inheritable_values_1.extractInheritedValue)(story.autoScreenshotStorybookGlobals, autoScreenshotStorybookGlobals); const screenshotGlobalSetNames = Object.keys(rawAutoScreenshotGlobalSets).filter(name => Boolean(rawAutoScreenshotGlobalSets[name])); const autoScreenshotGlobalSets = screenshotGlobalSetNames.length ? screenshotGlobalSetNames.map(name => ({ name, globals: rawAutoScreenshotGlobalSets[name] })) : [{ name: "", globals: {} }]; if ((_a = story.autoScreenshots) !== null && _a !== void 0 ? _a : autoScreenshots) { for (const { name, globals } of autoScreenshotGlobalSets) { (0, test_decorators_1.extendedIt)(story, `Autoscreenshot${name ? ` ${name}` : ""}`, async function (ctx) { ctx.expect = globalThis.expect; const result = await openStoryStep(ctx.browser, story, globals); const selector = story.autoscreenshotSelector || autoscreenshotSelector || result.rootSelector; await autoScreenshotStep(ctx.browser, selector); }); } } if (story.extraTests) { for (const testName in story.extraTests) { (0, test_decorators_1.extendedIt)(story, testName, async function (ctx) { ctx.expect = globalThis.expect; await openStoryStep(ctx.browser, story); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await story.extraTests[testName].call(ctx, ctx); await clearSessionStep(ctx.browser); }); } } }); } async function openStoryStep(browser, story, storybookGlobals = {}) { return browser.runStep("@testplane/storybook: open story", () => (0, open_story_1.openStory)(browser, story, storybookGlobals)); } async function autoScreenshotStep(browser, rootSelector) { await browser.runStep(`@testplane/storybook: autoscreenshot "${rootSelector}"`, () => browser.assertView("plain", rootSelector)); } async function clearSessionStep(browser) { await browser.runStep("@testplane/storybook: clear session", () => browser.clearSession()); } //# sourceMappingURL=index.js.map