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

Support webpack4 modules format #3576

Merged
merged 1 commit into from
May 17, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/src/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class ClientApi {
// wrap the first decorator and so on.
const decorators = [...localDecorators, ...this._globalDecorators];

const fileName = m ? m.filename : null;
const fileName = m ? m.id : null;

// Add the fully decorated getStory function.
this._storyStore.addStory(kind, storyName, this._decorateStory(getStory, decorators), {
Expand Down
19 changes: 18 additions & 1 deletion lib/core/src/client/preview/client_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('preview.client_api', () => {
describe('reads filename from module', () => {
const api = new ClientAPI();
const story = jest.fn();
api.storiesOf('kind', { filename: 'foo.js' }).add('story', story);
api.storiesOf('kind', { id: 'foo.js' }).add('story', story);
const storybook = api.getStorybook();
expect(storybook).toEqual([
{ kind: 'kind', fileName: 'foo.js', stories: [{ name: 'story', render: expect.anything() }] },
Expand All @@ -224,6 +224,23 @@ describe('preview.client_api', () => {
expect(story).toHaveBeenCalled();
});

describe('reads filename from nodejs module', () => {
const api = new ClientAPI();
const story = jest.fn();
api.storiesOf('kind', module).add('story', story);
const storybook = api.getStorybook();
expect(storybook).toEqual([
{
kind: 'kind',
fileName: module.filename,
stories: [{ name: 'story', render: expect.anything() }],
},
]);

storybook[0].stories[0].render();
expect(story).toHaveBeenCalled();
});

describe('hot module loading', () => {
class MockModule {
hot = {
Expand Down