Skip to content

Commit

Permalink
Merge pull request #26514 from storybookjs/kasper/fix-single-loaders-…
Browse files Browse the repository at this point in the history
…decorators

Bug: Make sure loaders/decorators can be used as array
  • Loading branch information
kasperpeulen authored Mar 18, 2024
2 parents c0fdb3e + 58120f6 commit b016a4f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
28 changes: 28 additions & 0 deletions code/lib/preview-api/src/modules/store/csf/composeConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ describe('composeConfigs', () => {
});
});

it('allows single array to be written without array', () => {
expect(
composeConfigs([
{
argsEnhancers: ['1', '2'],
argTypesEnhancers: ['1', '2'],
loaders: '1',
},
{
argsEnhancers: '3',
argTypesEnhancers: '3',
loaders: ['2', '3'],
},
])
).toEqual({
parameters: {},
decorators: [],
args: {},
argsEnhancers: ['1', '2', '3'],
argTypes: {},
argTypesEnhancers: ['1', '2', '3'],
globals: {},
globalTypes: {},
loaders: ['1', '2', '3'],
runStep: expect.any(Function),
});
});

it('combines decorators in reverse file order', () => {
expect(
composeConfigs([
Expand Down
9 changes: 5 additions & 4 deletions code/lib/preview-api/src/modules/store/csf/composeConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { global } from '@storybook/global';

import { combineParameters } from '../parameters';
import { composeStepRunners } from './stepRunners';
import { normalizeArrays } from './normalizeArrays';

export function getField<TFieldType = any>(
moduleExportList: ModuleExports[],
Expand All @@ -16,10 +17,10 @@ export function getArrayField<TFieldType = any>(
field: string,
options: { reverseFileOrder?: boolean } = {}
): TFieldType[] {
return getField(moduleExportList, field).reduce(
(a: any, b: any) => (options.reverseFileOrder ? [...b, ...a] : [...a, ...b]),
[]
);
return getField(moduleExportList, field).reduce((prev: any, cur: any) => {
const normalized = normalizeArrays(cur);
return options.reverseFileOrder ? [...normalized, ...prev] : [...prev, ...normalized];
}, []);
}

export function getObjectField<TFieldType = Record<string, any>>(
Expand Down

0 comments on commit b016a4f

Please sign in to comment.