Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Ensure we show an error when configure() throws #17435

Merged
merged 1 commit into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/api/src/modules/stories.ts
Expand Up @@ -10,6 +10,7 @@ import {
SET_STORIES,
STORY_SPECIFIED,
STORY_INDEX_INVALIDATED,
CONFIG_ERROR,
} from '@storybook/core-events';
import deprecate from 'util-deprecate';
import { logger } from '@storybook/client-logger';
Expand Down Expand Up @@ -512,6 +513,13 @@ export const init: ModuleFn = ({
}
);

fullAPI.on(CONFIG_ERROR, function handleConfigError(err) {
store.setState({
storiesConfigured: true,
storiesFailed: err,
});
});

if (FEATURES?.storyStoreV7) {
provider.serverChannel?.on(STORY_INDEX_INVALIDATED, () => fullAPI.fetchStoryList());
await fullAPI.fetchStoryList();
Expand Down
20 changes: 20 additions & 0 deletions lib/api/src/tests/stories.test.js
Expand Up @@ -6,6 +6,7 @@ import {
STORY_SPECIFIED,
STORY_PREPARED,
STORY_INDEX_INVALIDATED,
CONFIG_ERROR,
} from '@storybook/core-events';
import { EventEmitter } from 'events';
import global from 'global';
Expand Down Expand Up @@ -1136,6 +1137,25 @@ describe('stories API', () => {
});
});

describe('CONFIG_ERROR', () => {
it('shows error to user', async () => {
const navigate = jest.fn();
const store = createMockStore();
const fullAPI = Object.assign(new EventEmitter(), {});

const { api, init } = initStories({ store, navigate, provider, fullAPI });
Object.assign(fullAPI, api);

await init();

fullAPI.emit(CONFIG_ERROR, { message: 'Failed to run configure' });

const { storiesConfigured, storiesFailed } = store.getState();
expect(storiesConfigured).toBe(true);
expect(storiesFailed.message).toMatch(/Failed to run configure/);
});
});

describe('v2 SET_STORIES event', () => {
it('normalizes parameters and calls setStories for local stories', () => {
const fullAPI = Object.assign(new EventEmitter(), {
Expand Down