Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rishigupta1599 committed May 5, 2024
1 parent ab95909 commit 7fb8e0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/snapshots.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { logger, PercyConfig } from '@percy/cli-command';
import { yieldAll } from '@percy/cli-command/utils';
import qs from 'qs';
import { checkStorybookVersion } from './utils.js';

import {
checkStorybookVersion,
fetchStorybookPreviewResource,
evalStorybookEnvironmentInfo,
evalStorybookStorySnapshots,
Expand Down
19 changes: 9 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,19 @@ export function evalStorybookStorySnapshots({ waitFor }, storybookVersion) {
};

return waitFor(async () => {
if(storybookVersion == 8) {
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)
if (storiesObj) {
return Object.values(storiesObj);
}
throw new Error()
throw new Error();
} else {
// uncache stories, if cached via storyStorev7: true
await (window.__STORYBOOK_PREVIEW__?.cacheAllCSFFiles?.() ||
window.__STORYBOOK_STORY_STORE__?.cacheAllCSFFiles?.());
// use newer storybook APIs before old APIs
// use newer storybook APIs before old APIs
await (window.__STORYBOOK_PREVIEW__?.extract?.() ||
window.__STORYBOOK_STORY_STORE__?.extract?.());
return window.__STORYBOOK_STORY_STORE__.raw();
Expand Down Expand Up @@ -267,14 +267,13 @@ export function evalStorybookStorySnapshots({ waitFor }, storybookVersion) {
export function evalSetCurrentStory({ waitFor }, story, storybookVersion) {
return waitFor(() => {
// get the correct channel depending on the storybook version
if(storybookVersion == 8){
return window.__STORYBOOK_PREVIEW__?.channel
if (storybookVersion === 8) {
return window.__STORYBOOK_PREVIEW__?.channel;
} else {
return window.__STORYBOOK_PREVIEW__?.channel ||
window.__STORYBOOK_STORY_STORE__?._channel
window.__STORYBOOK_STORY_STORE__?._channel;
}

}, 5000).catch(() => Promise.reject(new Error(
}, 5000).catch(() => Promise.reject(new Error(
'Storybook object not found on the window. ' +
'Open Storybook and check the console for errors.'
))).then(channel => {
Expand Down
21 changes: 10 additions & 11 deletions test/storybook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('percy storybook', () => {
delete process.env.PERCY_CLIENT_ERROR_LOGS;
});

it('snapshots live urls', async () => {
fit('snapshots live urls', async () => {
await storybook(['http://localhost:9000']);

// if there are stderr logs ensure it is only an acceptable warning
Expand Down Expand Up @@ -133,16 +133,16 @@ describe('percy storybook', () => {
});

it('errors when unable to reach storybook', async () => {
const errorMessage = 'no coffee'
const errorMessage = 'no coffee';
server.reply('/iframe.html', () => new Promise(resolve => {
setTimeout(resolve, 3000, [418, 'text/plain', errorMessage]);
}));
await expectAsync(storybook(['http://localhost:8000']))
.toBeRejectedWithError(`418 I\'m a Teapot\n${errorMessage}`);
.toBeRejectedWithError(`418 I'm a Teapot\n${errorMessage}`);

expect(logger.stderr).toEqual([
'[percy] Waiting on a response from Storybook...',
`[percy] Error: 418 I\'m a Teapot\n${errorMessage}`
`[percy] Error: 418 I'm a Teapot\n${errorMessage}`
]);
});

Expand Down Expand Up @@ -227,7 +227,6 @@ describe('percy storybook', () => {
});

it('uses the preview dom when javascript is enabled', async () => {
let i = 0;
const FAKE_PREVIEW_V8 = `{ async extract() { return ${JSON.stringify([
{ id: '1', kind: 'foo', name: 'bar' },
{ id: '2', kind: 'foo', name: 'bar/baz', parameters: { percy: { enableJavaScript: true } } }
Expand All @@ -237,11 +236,11 @@ describe('percy storybook', () => {
' }';

let previewDOM = [`<script>__STORYBOOK_PREVIEW__ = ${FAKE_PREVIEW_V8}</script>`,
'<script>__STORYBOOK_STORY_STORE__ = { raw: () => ' + JSON.stringify([
{ id: '1', kind: 'foo', name: 'bar' },
{ id: '2', kind: 'foo', name: 'bar/baz', parameters: { percy: { enableJavaScript: true } } }
]) + ' }</script>',
'<p>This is the preview</p>'
'<script>__STORYBOOK_STORY_STORE__ = { raw: () => ' + JSON.stringify([
{ id: '1', kind: 'foo', name: 'bar' },
{ id: '2', kind: 'foo', name: 'bar/baz', parameters: { percy: { enableJavaScript: true } } }
]) + ' }</script>',
'<p>This is the preview</p>'
].join('');
let storyDOM = [
'<!DOCTYPE html><html><head></head><body>',
Expand Down

0 comments on commit 7fb8e0c

Please sign in to comment.