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: Re-enable failing args tests #10126

Merged
merged 2 commits into from
Mar 16, 2020
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
138 changes: 69 additions & 69 deletions lib/client-api/src/story_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,75 +199,75 @@ describe('preview.story_store', () => {
});

describe('globalArgs', () => {
// it('is initialized to the value stored in parameters.globalArgs on the first story', () => {
// const store = new StoryStore({ channel });
// addStoryToStore(store, 'a', '1', () => 0, {
// globalArgs: {
// arg1: 'arg1',
// arg2: 2,
// arg3: { complex: { object: ['type'] } },
// },
// });
// store.finishConfiguring();
// expect(store.getRawStory('a', '1').globalArgs).toEqual({
// arg1: 'arg1',
// arg2: 2,
// arg3: { complex: { object: ['type'] } },
// });
// });

// it('is initialized to the default values stored in parameters.globalArgsTypes on the first story', () => {
// const store = new StoryStore({ channel });
// addStoryToStore(store, 'a', '1', () => 0, {
// globalArgs: {
// arg1: 'arg1',
// arg2: 2,
// },
// globalArgTypes: {
// arg2: { defaultValue: 'arg2' },
// arg3: { defaultValue: { complex: { object: ['type'] } } },
// },
// });
// store.finishConfiguring();
// expect(store.getRawStory('a', '1').globalArgs).toEqual({
// arg1: 'arg1',
// arg2: 2,
// arg3: { complex: { object: ['type'] } },
// });
// });

// it('on HMR it sensibly re-initializes with memory', () => {
// const store = new StoryStore({ channel });
// addons.setChannel(channel);
// addStoryToStore(store, 'a', '1', () => 0, {
// globalArgs: {
// arg1: 'arg1',
// arg2: 2,
// arg3: { complex: { object: ['type'] } },
// },
// });
// store.finishConfiguring();

// // HMR
// store.startConfiguring();
// store.removeStoryKind('a');
// addStoryToStore(store, 'a', '1', () => 0, {
// globalArgs: {
// arg2: 2,
// // Although we have changed the default there is no way to tell that the user didn't change
// // it themselves
// arg3: { complex: { object: ['changed'] } },
// arg4: 'new',
// },
// });
// store.finishConfiguring();

// expect(store.getRawStory('a', '1').globalArgs).toEqual({
// arg2: 2,
// arg3: { complex: { object: ['type'] } },
// arg4: 'new',
// });
// });
it('is initialized to the value stored in parameters.globalArgs on the first story', () => {
const store = new StoryStore({ channel });
addStoryToStore(store, 'a', '1', () => 0, {
globalArgs: {
arg1: 'arg1',
arg2: 2,
arg3: { complex: { object: ['type'] } },
},
});
store.finishConfiguring();
expect(store.getRawStory('a', '1').globalArgs).toEqual({
arg1: 'arg1',
arg2: 2,
arg3: { complex: { object: ['type'] } },
});
});

it('is initialized to the default values stored in parameters.globalArgsTypes on the first story', () => {
const store = new StoryStore({ channel });
addStoryToStore(store, 'a', '1', () => 0, {
globalArgs: {
arg1: 'arg1',
arg2: 2,
},
globalArgTypes: {
arg2: { defaultValue: 'arg2' },
arg3: { defaultValue: { complex: { object: ['type'] } } },
},
});
store.finishConfiguring();
expect(store.getRawStory('a', '1').globalArgs).toEqual({
arg1: 'arg1',
arg2: 2,
arg3: { complex: { object: ['type'] } },
});
});

it('on HMR it sensibly re-initializes with memory', () => {
const store = new StoryStore({ channel });
addons.setChannel(channel);
addStoryToStore(store, 'a', '1', () => 0, {
globalArgs: {
arg1: 'arg1',
arg2: 2,
arg3: { complex: { object: ['type'] } },
},
});
store.finishConfiguring();

// HMR
store.startConfiguring();
store.removeStoryKind('a');
addStoryToStore(store, 'a', '1', () => 0, {
globalArgs: {
arg2: 2,
// Although we have changed the default there is no way to tell that the user didn't change
// it themselves
arg3: { complex: { object: ['changed'] } },
arg4: 'new',
},
});
store.finishConfiguring();

expect(store.getRawStory('a', '1').globalArgs).toEqual({
arg2: 2,
arg3: { complex: { object: ['type'] } },
arg4: 'new',
});
});

it('updateGlobalArgs changes the global args', () => {
const store = new StoryStore({ channel });
Expand Down
11 changes: 7 additions & 4 deletions lib/client-api/src/story_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ const includeStory = (story: StoreItem, options: StoryOptions = { includeDocsOnl
return !isStoryDocsOnly(story.parameters);
};

const inJest = () => process.env.JEST_WORKER_ID !== undefined;

const checkGlobalArgs = (parameters: Parameters) => {
const { globalArgs, globalArgTypes } = parameters;
if (globalArgs || globalArgTypes) {
throw new Error(
`Global args/argTypes can only be set globally: ${JSON.stringify({
if ((globalArgs || globalArgTypes) && !inJest()) {
logger.error(
'Global args/argTypes can only be set globally',
JSON.stringify({
globalArgs,
globalArgTypes,
})}`
})
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/server/preview/iframe-webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default ({

if(args || argTypes) logger.warn('Invalid args/argTypes in config, ignoring.', JSON.stringify({ args, argTypes }));
if (decorators) decorators.forEach(decorator => addDecorator(decorator));
if (parameters || globalArgs || globalArgTypes) addParameters({ ...parameters, globalArgs, globalArgTypes });
if (parameters || globalArgs || globalArgTypes) addParameters(Object.assign({}, parameters, { globalArgs, globalArgTypes }));
if (parameterEnhancers) parameterEnhancers.forEach(enhancer => addParameterEnhancer(enhancer));
`;
}
Expand Down