diff --git a/src/snapshots.js b/src/snapshots.js index 1fcbfc12..fd4fc1ef 100644 --- a/src/snapshots.js +++ b/src/snapshots.js @@ -2,7 +2,6 @@ import { logger, PercyConfig } from '@percy/cli-command'; import { yieldAll } from '@percy/cli-command/utils'; import qs from 'qs'; import { - checkStorybookVersion, fetchStorybookPreviewResource, evalStorybookEnvironmentInfo, evalStorybookStorySnapshots, @@ -162,8 +161,6 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags let lastCount; log.debug(`Requesting Storybook: ${baseUrl}`); - let storybookVersion = await checkStorybookVersion(); - log.debug(`Storybook Version: ${storybookVersion}`); // start a timeout to show a log if storybook takes a few seconds to respond let logTimeout = setTimeout(log.warn, 3000, 'Waiting on a response from Storybook...'); let previewResource = yield fetchStorybookPreviewResource(percy, previewUrl); @@ -177,7 +174,7 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags // gather storybook data in parallel let [environmentInfo, stories] = yield* yieldAll([ withPage(percy, aboutUrl, p => p.eval(evalStorybookEnvironmentInfo)), - withPage(percy, previewUrl, p => p.eval(evalStorybookStorySnapshots, storybookVersion)) + withPage(percy, previewUrl, p => p.eval(evalStorybookStorySnapshots)) ]); // map stories to snapshot options @@ -218,7 +215,7 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags } else { log.debug(`Loading story: ${options.name}`); // when not dry-running and javascript is not enabled, capture the story dom - yield page.eval(evalSetCurrentStory, { id, args, globals, queryParams }, storybookVersion); + yield page.eval(evalSetCurrentStory, { id, args, globals, queryParams }); /* istanbul ignore next: tested, but coverage is stripped */ let { dom, domSnapshot = dom } = yield page.snapshot(options); options.domSnapshot = domSnapshot; diff --git a/src/utils.js b/src/utils.js index c8b9089d..fabed9b2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -200,7 +200,7 @@ export function evalStorybookEnvironmentInfo({ waitForXPath }) { // Evaluate and return serialized Storybook stories to snapshot /* istanbul ignore next: no instrumenting injected code */ -export function evalStorybookStorySnapshots({ waitFor }, storybookVersion) { +export function evalStorybookStorySnapshots({ waitFor }) { let serialize = (what, value, invalid) => { if (what === 'include' || what === 'exclude') { return [].concat(value).filter(Boolean).map(v => v.toString()); @@ -226,23 +226,18 @@ export function evalStorybookStorySnapshots({ waitFor }, storybookVersion) { }; return waitFor(async () => { - if (storybookVersion === 8) { - await window.__STORYBOOK_PREVIEW__?.cacheAllCSFFiles?.(); - await window.__STORYBOOK_PREVIEW__?.ready?.(); - const storiesObj = await (window.__STORYBOOK_PREVIEW__?.extract?.()); - if (storiesObj) { - return Object.values(storiesObj); - } - throw new Error(); - } else { + await window.__STORYBOOK_PREVIEW__?.ready?.(); // uncache stories, if cached via storyStorev7: true - await (window.__STORYBOOK_PREVIEW__?.cacheAllCSFFiles?.() || - window.__STORYBOOK_STORY_STORE__?.cacheAllCSFFiles?.()); - // use newer storybook APIs before old APIs - await (window.__STORYBOOK_PREVIEW__?.extract?.() || - window.__STORYBOOK_STORY_STORE__?.extract?.()); - return window.__STORYBOOK_STORY_STORE__.raw(); + await (window.__STORYBOOK_PREVIEW__?.cacheAllCSFFiles?.() || + window.__STORYBOOK_STORY_STORE__?.cacheAllCSFFiles?.()); + + const storiesObj = await (window.__STORYBOOK_PREVIEW__?.extract?.()); + if (storiesObj && !Array.isArray(storiesObj)) { + return Object.values(storiesObj); } + + await window.__STORYBOOK_STORY_STORE__?.extract?.(); + return window.__STORYBOOK_STORY_STORE__.raw(); }, 5000).catch(() => Promise.reject(new Error( 'Storybook object not found on the window. ' + 'Open Storybook and check the console for errors.' @@ -264,15 +259,11 @@ export function evalStorybookStorySnapshots({ waitFor }, storybookVersion) { // Change the currently selected story within Storybook, decoding args and globals as necessary /* istanbul ignore next: no instrumenting injected code */ -export function evalSetCurrentStory({ waitFor }, story, storybookVersion) { +export function evalSetCurrentStory({ waitFor }, story) { return waitFor(() => { // get the correct channel depending on the storybook version - if (storybookVersion === 8) { - return window.__STORYBOOK_PREVIEW__?.channel; - } else { - return window.__STORYBOOK_PREVIEW__?.channel || + return window.__STORYBOOK_PREVIEW__?.channel || window.__STORYBOOK_STORY_STORE__?._channel; - } }, 5000).catch(() => Promise.reject(new Error( 'Storybook object not found on the window. ' + 'Open Storybook and check the console for errors.'