mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-17 05:02:23 +08:00
Merge pull request #21389 from storybookjs/shilman/fix-default-export-storysort
Core: Fix default export storySort handling
This commit is contained in:
commit
66c5c5e0db
@ -159,14 +159,16 @@ describe('getStorySortParameter', () => {
|
||||
export const parameters = [];
|
||||
`)
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unexpected 'parameters'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
"Unexpected 'parameters'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
}
|
||||
}"
|
||||
`);
|
||||
export default {
|
||||
parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
},
|
||||
},
|
||||
};"
|
||||
`);
|
||||
});
|
||||
|
||||
it('parameters var', () => {
|
||||
@ -201,14 +203,16 @@ describe('getStorySortParameter', () => {
|
||||
};
|
||||
`)
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unexpected 'options'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
"Unexpected 'options'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
}
|
||||
}"
|
||||
`);
|
||||
export default {
|
||||
parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
},
|
||||
},
|
||||
};"
|
||||
`);
|
||||
});
|
||||
|
||||
it('storySort var', () => {
|
||||
@ -226,14 +230,16 @@ describe('getStorySortParameter', () => {
|
||||
};
|
||||
`)
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unexpected 'storySort'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
"Unexpected 'storySort'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
}
|
||||
}"
|
||||
`);
|
||||
export default {
|
||||
parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
},
|
||||
},
|
||||
};"
|
||||
`);
|
||||
});
|
||||
|
||||
it('order var', () => {
|
||||
@ -251,14 +257,16 @@ describe('getStorySortParameter', () => {
|
||||
};
|
||||
`)
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unexpected 'order'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
"Unexpected 'order'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
}
|
||||
}"
|
||||
`);
|
||||
export default {
|
||||
parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
},
|
||||
},
|
||||
};"
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -289,6 +297,24 @@ describe('getStorySortParameter', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('no storysort', () => {
|
||||
expect(
|
||||
getStorySortParameter(dedent`
|
||||
const config = {
|
||||
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
`)
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('inline typescript', () => {
|
||||
expect(
|
||||
getStorySortParameter(dedent`
|
||||
@ -389,7 +415,7 @@ describe('getStorySortParameter', () => {
|
||||
});
|
||||
});
|
||||
describe('unsupported', () => {
|
||||
it('bad default epxort', () => {
|
||||
it('bad default export', () => {
|
||||
expect(
|
||||
getStorySortParameter(dedent`
|
||||
export default 'foo';
|
||||
|
@ -47,11 +47,13 @@ const unsupported = (unexpectedVar: string, isError: boolean) => {
|
||||
const message = dedent`
|
||||
Unexpected '${unexpectedVar}'. Parameter 'options.storySort' should be defined inline e.g.:
|
||||
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
}
|
||||
}
|
||||
export default {
|
||||
parameters = {
|
||||
options: {
|
||||
storySort: <array | object | function>
|
||||
},
|
||||
},
|
||||
};
|
||||
`;
|
||||
if (isError) {
|
||||
throw new Error(message);
|
||||
@ -86,8 +88,9 @@ const parseDefault = (defaultExpr: t.Expression): t.Expression | undefined => {
|
||||
if (params) {
|
||||
return parseParameters(params);
|
||||
}
|
||||
} else {
|
||||
unsupported('default', true);
|
||||
}
|
||||
unsupported('default', true);
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user