Skip to content

Commit

Permalink
Merge pull request #10404 from storybookjs/fix/legacy-redirect
Browse files Browse the repository at this point in the history
FIX legacy redirect
  • Loading branch information
ndelangen authored Apr 13, 2020
2 parents 0b940bf + 51321e8 commit 86c568a
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 64 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}

This file was deleted.

3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babel_pkg_json/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}
9 changes: 0 additions & 9 deletions lib/cli/test/fixtures/react_babelrc/.storybook/config.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babelrc/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}
9 changes: 0 additions & 9 deletions lib/cli/test/fixtures/react_babelrc_js/.storybook/config.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babelrc_js/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
}
18 changes: 14 additions & 4 deletions lib/core/src/client/preview/start.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { document, window } from 'global';
import Events from '@storybook/core-events';

import start from './start';

Expand Down Expand Up @@ -34,6 +35,7 @@ it('returns apis', () => {
expect(result).toEqual(
expect.objectContaining({
configure: expect.any(Function),
channel: expect.any(Object),
clientApi: expect.any(Object),
configApi: expect.any(Object),
forceReRender: expect.any(Function),
Expand All @@ -49,7 +51,9 @@ it('reuses the current client api when the lib is reloaded', () => {

const valueOfClientApi = window.__STORYBOOK_CLIENT_API__;

const { clientApi: newClientApi } = start(render);
const { clientApi: newClientApi, channel } = start(render);

channel.emit(Events.SET_STORIES, {});

expect(clientApi).toEqual(newClientApi);
expect(clientApi).toEqual(valueOfClientApi);
Expand All @@ -59,25 +63,29 @@ it('calls render when you add a story', () => {
jest.useFakeTimers();
const render = jest.fn();

const { clientApi, configApi } = start(render);
const { clientApi, configApi, channel } = start(render);

configApi.configure(() => {
clientApi.storiesOf('kind', {} as NodeModule).add('story', () => {});
}, {} as NodeModule);

channel.emit(Events.SET_STORIES, {});

expect(render).toHaveBeenCalledWith(expect.objectContaining({ kind: 'kind', name: 'story' }));
});

it('emits an exception and shows error when your story throws', () => {
jest.useFakeTimers();
const render = jest.fn();

const { clientApi, configApi } = start(render);
const { clientApi, configApi, channel } = start(render);

configApi.configure(() => {
clientApi.storiesOf('kind', {} as NodeModule).add('story1', () => {});
}, {} as NodeModule);

channel.emit(Events.SET_STORIES, {});

expect(render).not.toHaveBeenCalled();
expect(document.body.classList.add).toHaveBeenCalledWith('sb-show-nopreview');
});
Expand All @@ -92,12 +100,14 @@ it('emits an error and shows error when your framework calls showError', () => {
showError(error);
});

const { clientApi, configApi } = start(render);
const { clientApi, configApi, channel } = start(render);

configApi.configure(() => {
clientApi.storiesOf('kind', {} as NodeModule).add('story', () => {});
}, {} as NodeModule);

channel.emit(Events.SET_STORIES, {});

expect(render).toHaveBeenCalled();
expect(document.body.classList.add).toHaveBeenCalledWith('sb-show-errordisplay');
});
26 changes: 18 additions & 8 deletions lib/core/src/client/preview/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ export default function start(

// Only try and do URL/event based stuff in a browser context (i.e. not in storyshots)
if (isBrowser) {
// Initialize the story store with the selection in the URL
const { storyId, viewMode } = initializePath(storyStore);
const afterStoriesSet = () => {
// Initialize the story store with the selection in the URL
const { storyId, viewMode } = initializePath(storyStore);

if (storyId !== '*') {
storyStore.setSelection({ storyId, viewMode });
if (storyId !== '*') {
storyStore.setSelection({ storyId, viewMode });

// Keep the URL updated based on the current story
channel.on(Events.CURRENT_STORY_WAS_SET, setPath);
}
// Keep the URL updated based on the current story
channel.on(Events.CURRENT_STORY_WAS_SET, setPath);
}
};

channel.once(Events.SET_STORIES, afterStoriesSet);

// Handle keyboard shortcuts
window.onkeydown = (event: KeyboardEvent) => {
Expand All @@ -94,5 +98,11 @@ export default function start(
}

const configure = loadCsf({ clientApi, storyStore, configApi });
return { configure, clientApi, configApi, forceReRender: () => storyRenderer.forceReRender() };
return {
configure,
clientApi,
configApi,
channel,
forceReRender: () => storyRenderer.forceReRender(),
};
}

0 comments on commit 86c568a

Please sign in to comment.